From a082d84d54d990693af1772a385c6073586f0769 Mon Sep 17 00:00:00 2001 From: n1rwana <93197434+n1rwana@users.noreply.github.com> Date: Wed, 15 Dec 2021 01:56:23 +0300 Subject: [PATCH] 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. --- Web/Models/Entities/TicketComment.php | 21 ++++++++ Web/Models/Repositories/TicketComments.php | 9 ++++ Web/Presenters/SupportPresenter.php | 21 +++++++- .../templates/Support/AnswerTicket.xml | 12 +++++ Web/Presenters/templates/Support/View.xml | 48 +++++++++++++++++-- Web/routes.yml | 2 + .../00014-helpdesk-answers-evaluvating.sql | 1 + locales/en.strings | 10 ++++ locales/ru.strings | 10 ++++ 9 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 install/sqls/00014-helpdesk-answers-evaluvating.sql diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index 472177d1..1acf4c50 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -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; } diff --git a/Web/Models/Repositories/TicketComments.php b/Web/Models/Repositories/TicketComments.php index d5d1f07e..94360aec 100644 --- a/Web/Models/Repositories/TicketComments.php +++ b/Web/Models/Repositories/TicketComments.php @@ -48,6 +48,15 @@ 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; } diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index fd30328e..6ecd9150 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -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(); + } +} \ No newline at end of file diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index fb1f456c..025474c9 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -109,6 +109,18 @@ {_delete} {/if} + + {if $comment->getUType() === 1} +
+ {/if} diff --git a/Web/Presenters/templates/Support/View.xml b/Web/Presenters/templates/Support/View.xml index 4966f830..b4510509 100644 --- a/Web/Presenters/templates/Support/View.xml +++ b/Web/Presenters/templates/Support/View.xml @@ -6,6 +6,27 @@ {/block} {block content} + {if $ticket->isDeleted() == 0 } + {if $comment->getUType() === 0} - + + {/if} + + {if $comment->getUType() === 1} + {/if} @@ -101,4 +141,4 @@ {/if} -{/block} +{/block} \ No newline at end of file diff --git a/Web/routes.yml b/Web/routes.yml index 9fc3c7f6..8f31b4b8 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -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}" diff --git a/install/sqls/00014-helpdesk-answers-evaluvating.sql b/install/sqls/00014-helpdesk-answers-evaluvating.sql new file mode 100644 index 00000000..a957cf88 --- /dev/null +++ b/install/sqls/00014-helpdesk-answers-evaluvating.sql @@ -0,0 +1 @@ +ALTER TABLE `tickets_comments` ADD `mark` BOOLEAN NULL DEFAULT NULL; \ No newline at end of file diff --git a/locales/en.strings b/locales/en.strings index 403d8a81..7d38461c 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -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"; diff --git a/locales/ru.strings b/locales/ru.strings index 880a095b..57315548 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -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" = "Отправитель";