openvk/Web/Models/Repositories/Photos.php
lalka2016 a1ec1ca241 VKAPI: Some methods for topics and photos
Добавлены методы для обсуждений (addTopic, closeTopic(), createComment(), deleteComment(), deleteTopic(), editTopic(), fixTopic(), getComments(), getTopics(), openTopic(), unfixTopic())
и для фотографий (createAlbum(), editAlbum(), getAlbums(), getAlbumsCount(), getById(), get(), deleteAlbum(), edit(), delete(), deleteComment(), createComment(), getAll(), getComments())
2023-05-27 22:15:16 +03:00

46 lines
1.1 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;
function __construct()
{
$this->context = DatabaseConnection::i()->getContext();
$this->photos = $this->context->table("photos");
}
function get(int $id): ?Photo
{
$photo = $this->photos->get($id);
if(!$photo) return NULL;
return new Photo($photo);
}
function getByOwnerAndVID(int $owner, int $vId): ?Photo
{
$photo = $this->photos->where([
"owner" => $owner,
"virtual_id" => $vId,
])->fetch();
if(!$photo) return NULL;
return new Photo($photo);
}
function getEveryUserPhoto(User $user): \Traversable
{
$photos = $this->photos->where([
"owner" => $user->getId()
]);
foreach($photos as $photo) {
yield new Photo($photo);
}
}
}