mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +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 Nette\Database\Table\ActiveRow;
|
||||||
use openvk\Web\Models\RowModel;
|
use openvk\Web\Models\RowModel;
|
||||||
use Chandler\Database\DatabaseConnection;
|
use Chandler\Database\DatabaseConnection;
|
||||||
use openvk\Web\Models\Repositories\Users;
|
use openvk\Web\Models\Repositories\{Users, SupportAliases};
|
||||||
use Chandler\Database\DatabaseConnection as DB;
|
use Chandler\Database\DatabaseConnection as DB;
|
||||||
use Nette\InvalidStateException as ISE;
|
use Nette\InvalidStateException as ISE;
|
||||||
use Nette\Database\Table\Selection;
|
use Nette\Database\Table\Selection;
|
||||||
|
@ -12,7 +12,12 @@ use Nette\Database\Table\Selection;
|
||||||
class TicketComment extends RowModel
|
class TicketComment extends RowModel
|
||||||
{
|
{
|
||||||
protected $tableName = "tickets_comments";
|
protected $tableName = "tickets_comments";
|
||||||
|
|
||||||
|
private function getSupportAlias(): ?SupportAlias
|
||||||
|
{
|
||||||
|
return (new SupportAliases)->get($this->getUser()->getId());
|
||||||
|
}
|
||||||
|
|
||||||
function getId(): int
|
function getId(): int
|
||||||
{
|
{
|
||||||
return $this->getRecord()->id;
|
return $this->getRecord()->id;
|
||||||
|
@ -26,7 +31,34 @@ class TicketComment extends RowModel
|
||||||
function getUser(): User
|
function getUser(): User
|
||||||
{
|
{
|
||||||
return (new Users)->get($this->getRecord()->user_id);
|
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
|
function getAgentNumber(): ?string
|
||||||
{
|
{
|
||||||
|
@ -46,6 +78,9 @@ class TicketComment extends RowModel
|
||||||
if(is_null($agent = $this->getAgentNumber()))
|
if(is_null($agent = $this->getAgentNumber()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if(!is_null($this->getSupportAlias()))
|
||||||
|
return 0;
|
||||||
|
|
||||||
$agent = (int) $agent;
|
$agent = (int) $agent;
|
||||||
$rotation = $agent > 500 ? ( ($agent * 360) / 999 ) : $agent; # cap at 360deg
|
$rotation = $agent > 500 ? ( ($agent * 360) / 999 ) : $agent; # cap at 360deg
|
||||||
$values = [0, 45, 160, 220, 310, 345]; # good looking colors
|
$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()}
|
<br></b>Автор: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a> | {$ticket->getUser()->getRegistrationIP()} | Статус: {$ticket->getStatus()}
|
||||||
</div>
|
</div>
|
||||||
<div class="text" style="padding-top: 10px;border-bottom: #ECECEC solid 1px;">
|
<div class="text" style="padding-top: 10px;border-bottom: #ECECEC solid 1px;">
|
||||||
{$ticket->getContext()}
|
{$ticket->getContext()|noescape}
|
||||||
<br></br>
|
<br></br>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding-top: 5px;">
|
<div style="padding-top: 5px;">
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
{else}
|
{else}
|
||||||
<td width="54" valign="top">
|
<td width="54" valign="top">
|
||||||
<img
|
<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);" />
|
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
<div class="post-author">
|
<div class="post-author">
|
||||||
<a href="javascript:false">
|
<a href="javascript:false">
|
||||||
<b>
|
<b>
|
||||||
{=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()}
|
{$comment->getAuthorName()}
|
||||||
</b>
|
</b>
|
||||||
</a>
|
</a>
|
||||||
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
|
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
{else}
|
{else}
|
||||||
<td width="54" valign="top">
|
<td width="54" valign="top">
|
||||||
<img
|
<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);" />
|
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -63,9 +63,12 @@
|
||||||
</div>
|
</div>
|
||||||
{elseif ($comment->getUType() === 1)}
|
{elseif ($comment->getUType() === 1)}
|
||||||
<div class="post-author">
|
<div class="post-author">
|
||||||
<a href="#"><b>
|
<a href="javascript:false">
|
||||||
{=OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["supportName"]} №{$comment->getAgentNumber()}
|
<b>
|
||||||
</b></a> написал<br>
|
{$comment->getAuthorName()}
|
||||||
|
</b>
|
||||||
|
</a>
|
||||||
|
написал<br>
|
||||||
<a href="#" class="date">{$comment->getTime()}</a>
|
<a href="#" class="date">{$comment->getTime()}</a>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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