mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
Refactor Messages::getCorrespondence
This commit is contained in:
parent
f235338d69
commit
9dc25aa938
1 changed files with 12 additions and 3 deletions
|
@ -17,12 +17,21 @@ class Messages
|
|||
$this->messages = $this->context->table("messages");
|
||||
}
|
||||
|
||||
function getCorrespondencies(RowModel $correspondent, int $page = 1, ?int $perPage = NULL): \Traversable
|
||||
function get(int $id): ?Message
|
||||
{
|
||||
$msg = $this->messages->get($id);
|
||||
if(!$msg)
|
||||
return NULL;
|
||||
|
||||
return new Message($msg);
|
||||
}
|
||||
|
||||
function getCorrespondencies(RowModel $correspondent, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
|
||||
{
|
||||
$id = $correspondent->getId();
|
||||
$class = get_class($correspondent);
|
||||
$limit = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
|
||||
$offset = ($page - 1) * $limit;
|
||||
$offset = $offset ?? ($page - 1) * $limit;
|
||||
$query = file_get_contents(__DIR__ . "/../sql/get-correspondencies.tsql");
|
||||
DatabaseConnection::i()->getConnection()->query(file_get_contents(__DIR__ . "/../sql/mysql-msg-fix.tsql"));
|
||||
$coresps = DatabaseConnection::i()->getConnection()->query($query, $id, $class, $id, $class, $limit, $offset);
|
||||
|
@ -35,4 +44,4 @@ class Messages
|
|||
yield new Correspondence($correspondent, $anotherCorrespondent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue