mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Support: WIP: Add support agent name customization
This commit is contained in:
parent
b39dd44143
commit
b47d0dcd48
7 changed files with 101 additions and 10 deletions
39
Web/Models/Entities/SupportAlias.php
Normal file
39
Web/Models/Entities/SupportAlias.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Entities;
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Models\Repositories\Users;
|
||||
|
||||
class SupportAlias extends RowModel
|
||||
{
|
||||
protected $tableName = "support_names";
|
||||
|
||||
function getUser(): User
|
||||
{
|
||||
return (new Users)->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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -13,6 +13,11 @@ 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;
|
||||
|
@ -28,6 +33,33 @@ class TicketComment extends RowModel
|
|||
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
|
||||
{
|
||||
if($this->getUType() === 0)
|
||||
|
@ -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
|
||||
|
|
13
Web/Models/Repositories/SupportAliases.php
Normal file
13
Web/Models/Repositories/SupportAliases.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Repositories;
|
||||
|
||||
class SupportAliases extends Repository
|
||||
{
|
||||
protected $tableName = "support_names";
|
||||
protected $modelName = "SupportAlias";
|
||||
|
||||
function get(int $agent)
|
||||
{
|
||||
return $this->toEntity($this->table->where("agent", $agent)->fetch());
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
<br></b>Автор: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a> | {$ticket->getUser()->getRegistrationIP()} | Статус: {$ticket->getStatus()}
|
||||
</div>
|
||||
<div class="text" style="padding-top: 10px;border-bottom: #ECECEC solid 1px;">
|
||||
{$ticket->getContext()}
|
||||
{$ticket->getContext()|noescape}
|
||||
<br></br>
|
||||
</div>
|
||||
<div style="padding-top: 5px;">
|
||||
|
@ -50,7 +50,7 @@
|
|||
{else}
|
||||
<td width="54" valign="top">
|
||||
<img
|
||||
src="https://avatars.mds.yandex.net/get-zen_doc/164147/pub_5b60816e2dc67000a862253e_5b6081d4e9151400a9f48625/scale_1200"
|
||||
src="{$comment->getAvatar()}"
|
||||
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
|
||||
</td>
|
||||
{/if}
|
||||
|
@ -66,7 +66,7 @@
|
|||
<div class="post-author">
|
||||
<a href="javascript:false">
|
||||
<b>
|
||||
{=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()}
|
||||
{$comment->getAuthorName()}
|
||||
</b>
|
||||
</a>
|
||||
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
{else}
|
||||
<td width="54" valign="top">
|
||||
<img
|
||||
src="https://avatars.mds.yandex.net/get-zen_doc/164147/pub_5b60816e2dc67000a862253e_5b6081d4e9151400a9f48625/scale_1200"
|
||||
src="{$comment->getAvatar()}"
|
||||
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
|
||||
</td>
|
||||
{/if}
|
||||
|
@ -63,9 +63,12 @@
|
|||
</div>
|
||||
{elseif ($comment->getUType() === 1)}
|
||||
<div class="post-author">
|
||||
<a href="#"><b>
|
||||
{=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()}
|
||||
</b></a> написал<br>
|
||||
<a href="javascript:false">
|
||||
<b>
|
||||
{$comment->getAuthorName()}
|
||||
</b>
|
||||
</a>
|
||||
написал<br>
|
||||
<a href="#" class="date">{$comment->getTime()}</a>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
BIN
Web/static/img/support.jpeg
Normal file
BIN
Web/static/img/support.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
1
install/sqls/00002-support-aliases.sql
Normal file
1
install/sqls/00002-support-aliases.sql
Normal file
|
@ -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;
|
Loading…
Reference in a new issue