diff --git a/Web/Models/Entities/SupportAgent.php b/Web/Models/Entities/SupportAgent.php new file mode 100644 index 00000000..2f7fc21b --- /dev/null +++ b/Web/Models/Entities/SupportAgent.php @@ -0,0 +1,39 @@ +getRecord()->agent; + } + + function getName(): ?string + { + return $this->getRecord()->name; + } + + function getCanonicalName(): string + { + return $this->getName(); + } + + function getAvatarURL(): ?string + { + return $this->getRecord()->icon; + } + + function isShowNumber(): int + { + return $this->getRecord()->numerate; + } + + function getRealName(): string + { + return (new Users)->get($this->getAgentId())->getCanonicalName(); + } +} \ No newline at end of file diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index a9fb684a..2f1a5e8f 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -42,7 +42,7 @@ class TicketComment extends RowModel $alias = $this->getSupportAlias(); if(!$alias) - return OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"] . " №" . $this->getAgentNumber(); + return tr("helpdesk_agent") . " #" . $this->getAgentNumber(); $name = $alias->getName(); if($alias->shouldAppendNumber()) diff --git a/Web/Models/Repositories/SupportAgents.php b/Web/Models/Repositories/SupportAgents.php new file mode 100644 index 00000000..7b3a1e7e --- /dev/null +++ b/Web/Models/Repositories/SupportAgents.php @@ -0,0 +1,32 @@ +context = DatabaseConnection::i()->getContext(); + $this->agents = $this->context->table("support_names"); + } + + private function toAgent(?ActiveRow $ar) + { + return is_null($ar) ? NULL : new SupportAgent($ar); + } + + function get(int $id): ?SupportAgent + { + return $this->toAgent($this->agents->where("agent", $id)->fetch()); + } + + function isExists(int $id): bool + { + return !is_null($this->get($id)); + } +} \ No newline at end of file diff --git a/Web/Models/Repositories/TicketComments.php b/Web/Models/Repositories/TicketComments.php index 9277218f..ee05bb55 100644 --- a/Web/Models/Repositories/TicketComments.php +++ b/Web/Models/Repositories/TicketComments.php @@ -27,6 +27,13 @@ class TicketComments else return NULL; } + + function getCountByAgent(int $agent_id, int $mark = NULL): int + { + $filter = ['user_id' => $agent_id, 'user_type' => 1]; + $mark && $filter['mark'] = $mark; + return sizeof($this->comments->where($filter)); + } use \Nette\SmartObject; } diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index 8f4fd7d3..c4d729ea 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -1,7 +1,7 @@ save(); $this->returnJson([ "success" => true ]); } + + function renderAgent(int $id): void + { + $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0); + + $support_names = new SupportAgents; + + if(!$support_names->isExists($id)) + $this->template->mode = "edit"; + + $this->template->agent_id = $id; + $this->template->mode = in_array($this->queryParam("act"), ["info", "edit"]) ? $this->queryParam("act") : "info"; + $this->template->agent = $support_names->get($id) ?? NULL; + $this->template->counters = [ + "all" => (new TicketComments)->getCountByAgent($id), + "good" => (new TicketComments)->getCountByAgent($id, 1), + "bad" => (new TicketComments)->getCountByAgent($id, 2) + ]; + + if($id != $this->user->identity->getId()) + if ($support_names->isExists($id)) + $this->template->mode = "info"; + else + $this->redirect("/support/agent" . $this->user->identity->getId()); + } + + function renderEditAgent(int $id): void + { + $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0); + $this->assertNoCSRF(); + + $support_names = new SupportAgents; + $agent = $support_names->get($id); + + if($agent) + if($agent->getAgentId() != $this->user->identity->getId()) $this->flashFail("err", tr("error"), tr("forbidden")); + + if ($support_names->isExists($id)) { + $agent = $support_names->get($id); + $agent->setName($this->postParam("name") ?? tr("helpdesk_agent")); + $agent->setNumerate((int) $this->postParam("number") ?? NULL); + $agent->setIcon($this->postParam("avatar")); + $agent->save(); + $this->flashFail("succ", "Успех", "Профиль отредактирован."); + } else { + $agent = new SupportAgent; + $agent->setAgent($this->user->identity->getId()); + $agent->setName($this->postParam("name") ?? tr("helpdesk_agent")); + $agent->setNumerate((int) $this->postParam("number") ?? NULL); + $agent->setIcon($this->postParam("avatar")); + $agent->save(); + $this->flashFail("succ", "Успех", "Профиль создан. Теперь пользователи видят Ваши псевдоним и аватарку вместо стандартных аватарки и номера."); + } + } } diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index df163417..9b5b9de1 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -138,7 +138,7 @@ {var $menuLinksAvaiable = sizeof(OPENVK_ROOT_CONF['openvk']['preferences']['menu']['links']) > 0 && $thisUser->getLeftMenuItemStatus('links')} {_admin} - Helpdesk + {_helpdesk} {if $helpdeskTicketNotAnsweredCount > 0} ({$helpdeskTicketNotAnsweredCount}) {/if} diff --git a/Web/Presenters/templates/Support/Agent.xml b/Web/Presenters/templates/Support/Agent.xml new file mode 100644 index 00000000..987fb081 --- /dev/null +++ b/Web/Presenters/templates/Support/Agent.xml @@ -0,0 +1,92 @@ +{extends "../@layout.xml"} + +{block header} + {_helpdesk_agent_card} +{/block} + +{block content} +{var $isInfo = $mode === "info"} +{var $isEdit = $mode === "edit"} + +{if $agent != NULL} +
+ + +
+
+
+ +
+
+
+ {$counters["good"]} +
+
{_helpdesk_positive_answers}
+
+
+
+ {$counters["bad"]} +
+
{_helpdesk_negative_answers}
+
+
+
+ {$counters["all"]} +
+
{_helpdesk_all_answers}
+
+
+ {if $isEdit} +

{_edit}

+
+
+ + +

+ + {$agent->isShowNumber()} + +

+ + + +

+ +
+ {/if} +
+
+{else} +

Создать

+
+
+ + +

+ + +

+ + + + +
+{/if} +{/block} diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index f2fbfed7..7f577f9d 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -66,7 +66,7 @@ {elseif ($comment->getUType() === 1)}
- {$comment->getAuthorName()} + {$comment->getAuthorName()} {if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)} diff --git a/Web/Presenters/templates/Support/Index.xml b/Web/Presenters/templates/Support/Index.xml index 25c43100..9dc0cb31 100644 --- a/Web/Presenters/templates/Support/Index.xml +++ b/Web/Presenters/templates/Support/Index.xml @@ -22,7 +22,6 @@ {_support_new}
-
{if $isNew} diff --git a/Web/Presenters/templates/Support/List.xml b/Web/Presenters/templates/Support/List.xml index cd8c9981..b2cefbfa 100644 --- a/Web/Presenters/templates/Support/List.xml +++ b/Web/Presenters/templates/Support/List.xml @@ -18,6 +18,9 @@
{_support_closed}
+
+ Мой профиль +
{/block} {* BEGIN ELEMENTS DESCRIPTION *} diff --git a/Web/routes.yml b/Web/routes.yml index 55d73abb..d3dcbc83 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -31,6 +31,10 @@ routes: handler: "Comment->makeComment" - url: "/support/delete/{num}" handler: "Support->delete" + - url: "/support/agent{num}" + handler: "Support->agent" + - url: "/support/agent{num}/edit" + handler: "Support->editAgent" - url: "/language" handler: "About->language" - url: "/language/{text}.js" diff --git a/install/sqls/00032-agent-card.sql b/install/sqls/00032-agent-card.sql new file mode 100644 index 00000000..a8354c80 --- /dev/null +++ b/install/sqls/00032-agent-card.sql @@ -0,0 +1,15 @@ + +CREATE TABLE `support_names` ( + `id` bigint(20) UNSIGNED NOT NULL, + `agent` bigint(20) UNSIGNED NOT NULL, + `name` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL, + `icon` varchar(1024) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `numerate` tinyint(1) NOT NULL DEFAULT 0 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +ALTER TABLE `support_names` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `support_names` + MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT; +COMMIT; \ No newline at end of file diff --git a/locales/en.strings b/locales/en.strings index 132ffe8f..4ceaae0e 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -1186,8 +1186,18 @@ "url_is_banned_title" = "Link to a suspicious site"; "url_is_banned_proceed" = "Follow the link"; -/* Chandler */ +/* Helpdesk */ +"helpdesk" = "Support"; +"helpdesk_agent" = "Support Agent"; +"helpdesk_agent_card" = "Agent Card"; +"helpdesk_positive_answers" = "positive answers"; +"helpdesk_negative_answers" = "negative answers"; +"helpdesk_all_answers" = "all answers"; +"helpdesk_showing_name" = "Display name"; +"helpdesk_show_number" = "Show the number"; +"helpdesk_avatar_url" = "Link to the avatar"; +/* Chandler */ "c_user_removed_from_group" = "The user has been removed from the group"; "c_permission_removed_from_group" = "The permission has been removed from the group"; "c_group_removed" = "The group has been deleted."; diff --git a/locales/ru.strings b/locales/ru.strings index e62048ed..b8ef9152 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -1244,6 +1244,16 @@ "url_is_banned_title" = "Ссылка на подозрительный сайт"; "url_is_banned_proceed" = "Перейти по ссылке"; +/* Helpdesk */ +"helpdesk" = "Поддержка"; +"helpdesk_agent" = "Агент Поддержки"; +"helpdesk_agent_card" = "Карточка агента"; +"helpdesk_positive_answers" = "положительных ответов"; +"helpdesk_negative_answers" = "отрицательных ответов"; +"helpdesk_all_answers" = "всего ответов"; +"helpdesk_showing_name" = "Отображаемое имя"; +"helpdesk_show_number" = "Показывать номер"; +"helpdesk_avatar_url" = "Ссылка на аватарку"; /* Chandler */ "c_user_removed_from_group" = "Пользователь был удалён из группы";