openvk/Web/Models/Repositories/Conversations.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

53 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace openvk\Web\Models\Repositories;
use openvk\Web\Models\Entities\{Messages as M, User};
use Chandler\Database\DatabaseConnection as DB;
use Nette\Database\Table\ActiveRow;
class Conversations
{
private $context;
private $convos;
public function __construct()
{
$this->context = DB::i()->getContext();
$this->convos = $this->context->table("conversations");
}
private function toConversation(?ActiveRow $ar): ?M\AbstractConversation
{
if (is_null($ar)) {
return null;
} elseif ($ar->is_pm) {
return new M\PrivateConversation($ar);
} else {
return new M\Conversation($ar);
}
}
public function get(int $id): ?M\AbstractConversation
{
return $this->toConversation($this->convos->get($id));
}
public function getConversationsByUser(User $user, int $page = 1, ?int $perPage = null): \Traversable
{
$rels = $this->context->table("conversation_members")->where([
"deleted" => false,
"user" => $user->getId(),
])->page($page, $perPage ?? OPENVK_DEFAULT_PER_PAGE);
foreach ($rels as $rel) {
yield $this->get($rel->conversation);
}
}
public function getPrivateConversation(User $user, int $peer): M\PrivateConversation
{
;
}
}