2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
namespace openvk\Web\Models\Entities;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
use openvk\Web\Util\DateTime;
|
|
|
|
use openvk\Web\Models\RowModel;
|
2021-12-16 21:25:42 +03:00
|
|
|
use openvk\Web\Models\Repositories\{Users, SupportAliases, Tickets};
|
2020-06-07 19:04:43 +03:00
|
|
|
|
|
|
|
class TicketComment extends RowModel
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
use Traits\TRichText;
|
2020-06-07 19:04:43 +03:00
|
|
|
protected $tableName = "tickets_comments";
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2021-11-17 22:39:22 +03:00
|
|
|
private $overrideContentColumn = "text";
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
private function getSupportAlias(): ?SupportAlias
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return (new SupportAliases())->get($this->getUser()->getId());
|
2021-10-14 13:35:17 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getId(): int
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->getRecord()->id;
|
|
|
|
}
|
2021-10-09 13:55:25 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getUType(): int
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return $this->getRecord()->user_type;
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getUser(): User
|
|
|
|
{
|
|
|
|
return (new Users())->get($this->getRecord()->user_id);
|
2021-10-14 13:35:17 +03:00
|
|
|
}
|
2021-12-16 21:25:42 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getTicket(): Ticket
|
2021-12-16 21:25:42 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return (new Tickets())->get($this->getRecord()->ticket_id);
|
2021-12-16 21:25:42 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getAuthorName(): string
|
2021-10-14 13:35:17 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($this->getUType() === 0) {
|
2021-10-14 13:35:17 +03:00
|
|
|
return $this->getUser()->getCanonicalName();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
$alias = $this->getSupportAlias();
|
2025-01-31 18:20:13 +03:00
|
|
|
if (!$alias) {
|
2022-11-08 00:36:07 +03:00
|
|
|
return tr("helpdesk_agent") . " #" . $this->getAgentNumber();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
$name = $alias->getName();
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($alias->shouldAppendNumber()) {
|
2021-10-14 13:35:17 +03:00
|
|
|
$name .= " №" . $this->getAgentNumber();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
return $name;
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getAvatar(): string
|
2021-10-14 13:35:17 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($this->getUType() === 0) {
|
2021-10-14 13:35:17 +03:00
|
|
|
return $this->getUser()->getAvatarUrl();
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
$default = "/assets/packages/static/openvk/img/support.jpeg";
|
|
|
|
$alias = $this->getSupportAlias();
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2021-10-14 13:35:17 +03:00
|
|
|
return is_null($alias) ? $default : ($alias->getIcon() ?? $default);
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getAgentNumber(): ?string
|
2020-07-16 23:09:48 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($this->getUType() === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-07-16 23:09:48 +03:00
|
|
|
$salt = "kiraMiki";
|
|
|
|
$hash = $this->getUser()->getId() . CHANDLER_ROOT_CONF["security"]["secret"] . $salt;
|
|
|
|
$hash = hexdec(substr(hash("adler32", $hash), 0, 3));
|
|
|
|
$hash = ceil(($hash * 999) / 4096); # proportionalize to 0-999
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-07-16 23:09:48 +03:00
|
|
|
return str_pad((string) $hash, 3, "0", STR_PAD_LEFT);
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getColorRotation(): ?int
|
2020-07-16 23:09:48 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if (is_null($agent = $this->getAgentNumber())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($this->getSupportAlias())) {
|
2021-10-14 13:35:17 +03:00
|
|
|
return 0;
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
2020-07-16 23:09:48 +03:00
|
|
|
$agent = (int) $agent;
|
2025-01-31 18:20:13 +03:00
|
|
|
$rotation = $agent > 500 ? (($agent * 360) / 999) : $agent; # cap at 360deg
|
2020-07-16 23:09:48 +03:00
|
|
|
$values = [0, 45, 160, 220, 310, 345]; # good looking colors
|
2025-01-31 18:20:13 +03:00
|
|
|
usort($values, function ($x, $y) use ($rotation) {
|
2020-07-16 23:09:48 +03:00
|
|
|
# find closest
|
|
|
|
return abs($x - $rotation) - abs($y - $rotation);
|
|
|
|
});
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-07-16 23:09:48 +03:00
|
|
|
return array_shift($values);
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getContext(): string
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
2021-10-09 13:46:41 +03:00
|
|
|
$text = $this->getRecord()->text;
|
|
|
|
$text = $this->formatLinks($text);
|
|
|
|
$text = $this->removeZalgo($text);
|
|
|
|
$text = nl2br($text);
|
|
|
|
return $text;
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getTime(): DateTime
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
return new DateTime($this->getRecord()->created);
|
|
|
|
}
|
2021-10-09 13:46:41 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function isAd(): bool
|
|
|
|
{
|
|
|
|
return false; # Кооостыыыль!!!
|
|
|
|
}
|
2021-10-09 13:55:25 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getMark(): ?int
|
2021-12-15 01:56:23 +03:00
|
|
|
{
|
|
|
|
return $this->getRecord()->mark;
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function isLikedByUser(): ?bool
|
2021-12-15 01:56:23 +03:00
|
|
|
{
|
|
|
|
$mark = $this->getMark();
|
2025-01-31 18:20:13 +03:00
|
|
|
if (is_null($mark)) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2021-12-16 21:25:42 +03:00
|
|
|
return $mark === 1;
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2021-12-15 01:56:23 +03:00
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function isDeleted(): bool
|
2022-01-28 16:34:13 +03:00
|
|
|
{
|
|
|
|
return (bool) $this->getRecord()->deleted;
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|