Support: Allow users to rate support answers (#342)

* New feature: users can rate support answers

Now users can rate support answers. They will see links "This is good answer" and "This is bad answer", like it was in original VK.
This commit is contained in:
n1rwana 2021-12-15 01:56:23 +03:00 committed by GitHub
parent 6d14f03573
commit a082d84d54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 129 additions and 5 deletions

View file

@ -108,5 +108,26 @@ class TicketComment extends RowModel
return false; # Кооостыыыль!!!
}
function getMark(): ?int
{
return $this->getRecord()->mark;
}
function isLikedByUser(): ?bool
{
$mark = $this->getMark();
switch ($mark) {
case 0:
return false;
break;
case 1:
return true;
break;
default:
return NULL;
break;
}
}
use Traits\TRichText;
}

View file

@ -49,5 +49,14 @@ class TicketComments
// return $this->toTicket($this->tickets->get($id));
// }
function get(int $id): ?TicketComment
{
$comment = $this->comments->get($id);;
if (!is_null($comment))
return new TicketComment($comment);
else
return NULL;
}
use \Nette\SmartObject;
}

View file

@ -225,4 +225,23 @@ final class SupportPresenter extends OpenVKPresenter
$this->template->heading = $heading;
$this->template->content = $parser->parse($content);
}
function renderRateAnswer(int $id, int $mark): void
{
$this->willExecuteWriteAction();
$this->assertUserLoggedIn();
$comment = $this->comments->get($id);
if($this->user->id !== $this->tickets->get($comment->getTicketId())->getUser()->getId())
exit(header("HTTP/1.1 403 Forbidden"));
if($mark === 1 || $mark === 2)
header("HTTP/1.1 200 OK");
else
exit(header("HTTP/1.1 400 Bad Request"));
$comment->setMark($mark);
$comment->save();
}
}

View file

@ -109,6 +109,18 @@
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
{if $comment->getUType() === 1}
<div class="post-menu">
<strong>
{if $comment->isLikedByUser()}
{_support_good_answer_agent}
{else}
{_support_bad_answer_agent}
{/if}
</strong>
</div>
{/if}
</div>
</td>
</tr>

View file

@ -6,6 +6,27 @@
{/block}
{block content}
<script>
function markAnswer(id, mark) {
let url = "/support/comment/" + id + "/rate/" + mark;
$.ajax(url, {
error: errorHandler,
success: success(id, mark)
});
}
function success(id, mark) {
if(mark == 1) {
document.getElementById("markText-" + id).innerHTML = {_support_good_answer_user};
} else {
document.getElementById("markText-" + id).innerHTML = {_support_bad_answer_user};
}
}
function errorHandler(id, mark) {
document.getElementById("markText-" + id).innerHTML = {_error};
}
</script>
{if $ticket->isDeleted() == 0 }
<div class="post-author">
<a href="#" style="font-size:13px;">
@ -90,10 +111,29 @@
{$comment->getText()|noescape}
{/if}
</div>
{if $comment->getUType() === 0}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
{if $comment->getUType() === 1}
<div class="post-menu">
<strong id="markText-{$comment->getId()}">
{if $comment->isLikedByUser()}
{_support_good_answer_user}
{else}
{_support_bad_answer_user}
{/if}
</strong>
{if $comment->isLikedByUser() === null}
<a onClick="markAnswer({$comment->getId()}, 1)">{_support_rate_good_answer}</a>
|
<a onClick="markAnswer({$comment->getId()}, 2)">{_support_rate_bad_answer}</a>
{/if}
{/if}
</div>
{/if}
</div>
</td>

View file

@ -17,6 +17,8 @@ routes:
handler: "Support->AnswerTicket"
- url: "/support/view/{num}"
handler: "Support->view"
- url: "/support/comment/{num}/rate/{num}"
handler: "Support->rateAnswer"
- url: "/al_comments.pl/create/support/{num}"
handler: "Support->makeComment"
- url: "/al_comments.pl/create/support/reply/{num}"

View file

@ -0,0 +1 @@
ALTER TABLE `tickets_comments` ADD `mark` BOOLEAN NULL DEFAULT NULL;

View file

@ -565,6 +565,16 @@
"support_new_title" = "Enter the topic of your ticket";
"support_new_content" = "Describe the issue or suggestion";
"support_rate_good_answer" = "This is good answer";
"support_rate_bad_answer" = "This is bad answer";
"support_good_answer_user" = "You left a positive feedback.";
"support_bad_answer_user" = "You left a negative feedback.";
"support_good_answer_agent" = "User left a positive feedback.";
"support_bad_answer_agent" = "User left a negative feedback.";
"support_rated_good" = "You left a positive feedback about the answer.";
"support_rated_bad" = "You left a negative feedback about the answer.";
"wrong_parameters" = "Invalid request parameters.";
"comment" = "Comment";
"sender" = "Sender";

View file

@ -590,6 +590,16 @@
"support_new_title" = "Введите тему вашего обращения";
"support_new_content" = "Опишите проблему или предложение";
"support_rate_good_answer" = "Это хороший ответ";
"support_rate_bad_answer" = "Это плохой ответ";
"support_good_answer_user" = "Вы оставили положительный отзыв.";
"support_bad_answer_user" = "Вы оставили негативный отзыв.";
"support_good_answer_agent" = "Пользователь оставил положительный отзыв";
"support_bad_answer_agent" = "Пользователь оставил негативный отзыв";
"support_rated_good" = "Вы оставили положительный отзыв об ответе.";
"support_rated_bad" = "Вы оставили негативный отзыв об ответе.";
"wrong_parameters" = "Неверные параметры запроса.";
"comment" = "Комментарий";
"sender" = "Отправитель";