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\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2020-06-07 19:04:43 +03:00
|
|
|
use openvk\Web\Models\Entities\TicketComment;
|
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
|
|
|
|
class TicketComments
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
use \Nette\SmartObject;
|
2020-06-07 19:04:43 +03:00
|
|
|
private $context;
|
|
|
|
private $comments;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function __construct()
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
|
|
$this->comments = $this->context->table("tickets_comments");
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getCommentsById(int $ticket_id): \Traversable
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
foreach ($this->comments->where(['ticket_id' => $ticket_id, 'deleted' => 0]) as $comment) {
|
|
|
|
yield new TicketComment($comment);
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
2021-12-15 01:56:23 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function get(int $id): ?TicketComment
|
2021-12-15 01:56:23 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
$comment = $this->comments->get($id);
|
|
|
|
;
|
|
|
|
if (!is_null($comment)) {
|
2021-12-15 01:56:23 +03:00
|
|
|
return new TicketComment($comment);
|
2025-01-31 18:20:13 +03:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2021-12-15 01:56:23 +03:00
|
|
|
}
|
2022-11-08 00:36:07 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function getCountByAgent(int $agent_id, int $mark = null): int
|
2022-11-08 00:36:07 +03:00
|
|
|
{
|
|
|
|
$filter = ['user_id' => $agent_id, 'user_type' => 1];
|
|
|
|
$mark && $filter['mark'] = $mark;
|
|
|
|
return sizeof($this->comments->where($filter));
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|