diff --git a/Web/Models/Entities/SupportAlias.php b/Web/Models/Entities/SupportAlias.php new file mode 100644 index 00000000..9ad618a6 --- /dev/null +++ b/Web/Models/Entities/SupportAlias.php @@ -0,0 +1,39 @@ +get($this->getRecord()->agent); + } + + function getName(): string + { + return $this->getRecord()->name; + } + + function getIcon(): ?string + { + return $this->getRecord()->icon; + } + + function shouldAppendNumber(): bool + { + return (bool) $this->getRecord()->numerate; + } + + function setAgent(User $agent): void + { + $this->stateChanges("agent", $agent->getId()); + } + + function setNumeration(bool $numerate): void + { + $this->stateChanges("numerate", $numerate); + } +} diff --git a/Web/Models/Entities/TicketComment.php b/Web/Models/Entities/TicketComment.php index 25568bc7..9cbc4716 100644 --- a/Web/Models/Entities/TicketComment.php +++ b/Web/Models/Entities/TicketComment.php @@ -4,7 +4,7 @@ use openvk\Web\Util\DateTime; use Nette\Database\Table\ActiveRow; use openvk\Web\Models\RowModel; use Chandler\Database\DatabaseConnection; -use openvk\Web\Models\Repositories\Users; +use openvk\Web\Models\Repositories\{Users, SupportAliases}; use Chandler\Database\DatabaseConnection as DB; use Nette\InvalidStateException as ISE; use Nette\Database\Table\Selection; @@ -12,7 +12,12 @@ use Nette\Database\Table\Selection; class TicketComment extends RowModel { protected $tableName = "tickets_comments"; - + + private function getSupportAlias(): ?SupportAlias + { + return (new SupportAliases)->get($this->getUser()->getId()); + } + function getId(): int { return $this->getRecord()->id; @@ -26,7 +31,34 @@ class TicketComment extends RowModel function getUser(): User { return (new Users)->get($this->getRecord()->user_id); - } + } + + function getAuthorName(): string + { + if($this->getUType() === 0) + return $this->getUser()->getCanonicalName(); + + $alias = $this->getSupportAlias(); + if(!$alias) + return OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"] . " №" . $this->getAgentNumber(); + + $name = $alias->getName(); + if($alias->shouldAppendNumber()) + $name .= " №" . $this->getAgentNumber(); + + return $name; + } + + function getAvatar(): string + { + if($this->getUType() === 0) + return $this->getUser()->getAvatarUrl(); + + $default = "/assets/packages/static/openvk/img/support.jpeg"; + $alias = $this->getSupportAlias(); + + return is_null($alias) ? $default : ($alias->getIcon() ?? $default); + } function getAgentNumber(): ?string { @@ -46,6 +78,9 @@ class TicketComment extends RowModel if(is_null($agent = $this->getAgentNumber())) return NULL; + if(!is_null($this->getSupportAlias())) + return 0; + $agent = (int) $agent; $rotation = $agent > 500 ? ( ($agent * 360) / 999 ) : $agent; # cap at 360deg $values = [0, 45, 160, 220, 310, 345]; # good looking colors diff --git a/Web/Models/Repositories/SupportAliases.php b/Web/Models/Repositories/SupportAliases.php new file mode 100644 index 00000000..cb1a2521 --- /dev/null +++ b/Web/Models/Repositories/SupportAliases.php @@ -0,0 +1,13 @@ +toEntity($this->table->where("agent", $agent)->fetch()); + } +} diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index 68194810..8b3f9313 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -15,7 +15,7 @@
Автор: {$ticket->getUser()->getFullName()} | {$ticket->getUser()->getRegistrationIP()} | Статус: {$ticket->getStatus()}
- {$ticket->getContext()} + {$ticket->getContext()|noescape}

@@ -50,7 +50,7 @@ {else} {/if} @@ -66,7 +66,7 @@
- {=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()} + {$comment->getAuthorName()} {if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)} diff --git a/Web/Presenters/templates/Support/View.xml b/Web/Presenters/templates/Support/View.xml index cd24a775..46c372b1 100644 --- a/Web/Presenters/templates/Support/View.xml +++ b/Web/Presenters/templates/Support/View.xml @@ -49,7 +49,7 @@ {else} {/if} @@ -63,9 +63,12 @@
{elseif ($comment->getUType() === 1)}
- - {=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()} - написал
+ + + {$comment->getAuthorName()} + + + написал
{$comment->getTime()}
{/if} diff --git a/Web/static/img/support.jpeg b/Web/static/img/support.jpeg new file mode 100644 index 00000000..ccf42a12 Binary files /dev/null and b/Web/static/img/support.jpeg differ diff --git a/install/sqls/00002-support-aliases.sql b/install/sqls/00002-support-aliases.sql new file mode 100644 index 00000000..b586a1dd --- /dev/null +++ b/install/sqls/00002-support-aliases.sql @@ -0,0 +1 @@ +CREATE TABLE `support_names` ( `agent` BIGINT UNSIGNED NOT NULL , `name` VARCHAR(512) NOT NULL , `icon` VARCHAR(1024) NULL DEFAULT NULL , `numerate` BOOLEAN NOT NULL DEFAULT FALSE , PRIMARY KEY (`agent`)) ENGINE = InnoDB; \ No newline at end of file