mirror of
https://github.com/openvk/openvk
synced 2025-02-02 21:15:42 +03:00
Alexander Minkin
6ec54a379d
* 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.
72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Repositories;
|
|
|
|
use openvk\Web\Models\Entities\{Photo, User};
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
class Photos
|
|
{
|
|
private $context;
|
|
private $photos;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
$this->photos = $this->context->table("photos");
|
|
}
|
|
|
|
public function get(int $id): ?Photo
|
|
{
|
|
$photo = $this->photos->get($id);
|
|
if (!$photo) {
|
|
return null;
|
|
}
|
|
|
|
return new Photo($photo);
|
|
}
|
|
|
|
public function getByOwnerAndVID(int $owner, int $vId): ?Photo
|
|
{
|
|
$photo = $this->photos->where([
|
|
"owner" => $owner,
|
|
"virtual_id" => $vId,
|
|
"system" => 0,
|
|
"private" => 0,
|
|
])->fetch();
|
|
if (!$photo) {
|
|
return null;
|
|
}
|
|
|
|
return new Photo($photo);
|
|
}
|
|
|
|
public function getEveryUserPhoto(User $user, int $offset = 0, int $limit = 10): \Traversable
|
|
{
|
|
$perPage ??= OPENVK_DEFAULT_PER_PAGE;
|
|
$photos = $this->photos->where([
|
|
"owner" => $user->getId(),
|
|
"deleted" => 0,
|
|
"system" => 0,
|
|
"private" => 0,
|
|
])->order("id DESC");
|
|
|
|
foreach ($photos->limit($limit, $offset) as $photo) {
|
|
yield new Photo($photo);
|
|
}
|
|
}
|
|
|
|
public function getUserPhotosCount(User $user)
|
|
{
|
|
$photos = $this->photos->where([
|
|
"owner" => $user->getId(),
|
|
"deleted" => 0,
|
|
"system" => 0,
|
|
"private" => 0,
|
|
]);
|
|
|
|
return sizeof($photos);
|
|
}
|
|
}
|