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} +