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-12 21:06:31 +03:00
parent b90df2b49a
commit fead54dfb6
8 changed files with 86 additions and 0 deletions

View file

@ -108,5 +108,10 @@ class TicketComment extends RowModel
return false; # Кооостыыыль!!!
}
function getMark(): int
{
return $this->getRecord()->mark;
}
use Traits\TRichText;
}

View file

@ -48,6 +48,16 @@ class TicketComments
// {
// return $this->toTicket($this->tickets->get($id));
// }
// We can get comment by it's ID using this function
function get(int $id): TicketComment
{
$comm = $this->comments->where(['id' => $id])->fetch();
if (!is_null($comm))
return new TicketComment($comm);
else
return null;
}
use \Nette\SmartObject;
}

View file

@ -225,4 +225,36 @@ final class SupportPresenter extends OpenVKPresenter
$this->template->heading = $heading;
$this->template->content = $parser->parse($content);
}
function renderRateAnswerGood(int $id): void
{
$this->willExecuteWriteAction();
$this->assertUserLoggedIn();
$comment = $this->comments->get($id);
if ($this->user->id === $this->tickets->get($comment->getTicketId()->getUser()->getId())) {
$comment->setMark(1);
$comment->save();
$this->flashFail("succ", "Успешно", "Вы оставили положительный отзыв об ответе");
} else {
$this->flashFail("err", "Ошибка", "Ошибка доступа");
}
}
function renderRateAnswerBad(int $id): void
{
$this->willExecuteWriteAction();
$this->assertUserLoggedIn();
$comment = $this->comments->get($id);
if ($this->user->id === $this->tickets->get($comment->getTicketId()->getUser()->getId())) {
$comment->setMark(2);
$comment->save();
$this->flashFail("succ", "Успешно", "Вы оставили положительный отзыв об ответе");
} else {
$this->flashFail("err", "Ошибка", "Ошибка доступа");
}
}
}

View file

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

View file

@ -95,6 +95,22 @@
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
{if $comment->getUType() === 1 && $comment->getMark() === 0}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/rateGood">{_support_rate_good_answer}}</a>
|
<a href="/support/comment/{$comment->getId()}/rateBad">{_support_rate_bad_answer}}</a>
</div>
{elseif $comment->getMark() === 1}
<div class="post-menu">
<strong>{_support_good_answer_user}</strong>
</div>
{elseif $comment->getMark() === 2}
<div class="post-menu">
<strong>{_support_bad_answer_user}</strong>
</div>
{/if}
</div>
</td>
</tr>

View file

@ -17,6 +17,10 @@ routes:
handler: "Support->AnswerTicket"
- url: "/support/view/{num}"
handler: "Support->view"
- url: "/support/comment/{num}/rateGood"
handler: "Support->RateAnswerGood"
- url: "/support/comment/{num}/rateBad"
handler: "Support->RateAnswerBad"
- 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` TINYINT NOT NULL DEFAULT '0';

View file

@ -577,6 +577,13 @@
"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" = "Пользователь оставил негативный отзыв";
"comment" = "Комментарий";
"sender" = "Отправитель";