openvk/Web/Models/Repositories/TicketComments.php
Alexander Minkin 6ec54a379d
feat: add linting of code (#1220)
* feat(lint): add php-cs-fixer for linting

Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0.

This is not the reformatting commit.

* style: format code according to PER-CS 2.0 with php-cs-fixer

* ci(actions): add lint action

Resolves #1132.
2025-01-31 18:20:13 +03:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use openvk\Web\Models\Entities\TicketComment;
use Chandler\Database\DatabaseConnection;
class TicketComments
{
use \Nette\SmartObject;
private $context;
private $comments;
public function __construct()
{
$this->context = DatabaseConnection::i()->getContext();
$this->comments = $this->context->table("tickets_comments");
}
public function getCommentsById(int $ticket_id): \Traversable
{
foreach ($this->comments->where(['ticket_id' => $ticket_id, 'deleted' => 0]) as $comment) {
yield new TicketComment($comment);
}
}
public function get(int $id): ?TicketComment
{
$comment = $this->comments->get($id);
;
if (!is_null($comment)) {
return new TicketComment($comment);
} else {
return null;
}
}
public function getCountByAgent(int $agent_id, int $mark = null): int
{
$filter = ['user_id' => $agent_id, 'user_type' => 1];
$mark && $filter['mark'] = $mark;
return sizeof($this->comments->where($filter));
}
}