2020-06-07 19:04:43 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Repositories;
|
|
|
|
use openvk\Web\Models\Entities\Album;
|
2022-03-25 14:05:44 +03:00
|
|
|
use openvk\Web\Models\Entities\Photo;
|
2020-06-07 19:04:43 +03:00
|
|
|
use openvk\Web\Models\Entities\Club;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use Nette\Database\Table\ActiveRow;
|
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
|
|
|
|
class Albums
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $albums;
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
|
|
$this->albums = $this->context->table("albums");
|
|
|
|
}
|
|
|
|
|
|
|
|
private function toAlbum(?ActiveRow $ar): ?Album
|
|
|
|
{
|
|
|
|
return is_null($ar) ? NULL : new Album($ar);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSpecialConditions(int $id, int $type): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
"name" => "[/!\\ DO NOT EDIT: INTERNAL NAME ASSIGNMENT IS ACTIVE]",
|
|
|
|
"owner" => $id,
|
|
|
|
"special_type" => $type,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(int $id): ?Album
|
|
|
|
{
|
|
|
|
return $this->toAlbum($this->albums->get($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserAlbums(User $user, int $page = 1, ?int $perPage = NULL): \Traversable
|
|
|
|
{
|
|
|
|
$perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
|
2020-06-29 22:53:19 +03:00
|
|
|
$albums = $this->albums->where("owner", $user->getId())->where("deleted", false);
|
2020-06-07 19:04:43 +03:00
|
|
|
foreach($albums->page($page, $perPage) as $album)
|
|
|
|
yield new Album($album);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserAlbumsCount(User $user): int
|
|
|
|
{
|
2020-06-29 22:53:19 +03:00
|
|
|
$albums = $this->albums->where("owner", $user->getId())->where("deleted", false);
|
2020-06-07 19:04:43 +03:00
|
|
|
return sizeof($albums);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClubAlbums(Club $club, int $page = 1, ?int $perPage = NULL): \Traversable
|
|
|
|
{
|
|
|
|
$perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE;
|
2020-06-29 22:53:19 +03:00
|
|
|
$albums = $this->albums->where("owner", $club->getId() * -1)->where("special_type", 0)->where("deleted", false);
|
|
|
|
foreach($albums->page($page, $perPage) as $album)
|
2020-06-07 19:04:43 +03:00
|
|
|
yield new Album($album);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClubAlbumsCount(Club $club): int
|
|
|
|
{
|
2020-06-29 22:53:19 +03:00
|
|
|
$albums = $this->albums->where("owner", $club->getId() * -1)->where("special_type", 0)->where("deleted", false);
|
|
|
|
return sizeof($albums);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAvatarAlbumById(int $id, int $regTime): Album
|
|
|
|
{
|
|
|
|
$data = $this->getSpecialConditions($id, 16);
|
|
|
|
$album = $this->albums->where([
|
|
|
|
"owner" => $id,
|
|
|
|
"special_type" => 16,
|
|
|
|
])->fetch();
|
|
|
|
if(!$album) {
|
|
|
|
$album = new Album;
|
|
|
|
$album->setName("[!!! internal album]");
|
|
|
|
$album->setOwner($id);
|
|
|
|
$album->setSpecial_Type(16);
|
|
|
|
$album->setCreated($regTime);
|
|
|
|
$album->save();
|
|
|
|
|
|
|
|
return $album;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Album($album);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getUserAvatarAlbum(User $user): Album
|
|
|
|
{
|
|
|
|
return $this->getAvatarAlbumById($user->getId(), $user->getRegistrationTime()->timestamp());
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClubAvatarAlbum(Club $club): Album
|
|
|
|
{
|
2020-06-29 22:53:19 +03:00
|
|
|
return $this->getAvatarAlbumById($club->getId() * -1, time());
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getUserWallAlbum(User $user): Album
|
|
|
|
{
|
|
|
|
$data = $this->getSpecialConditions($user->getId(), 32);
|
|
|
|
$album = $this->albums->where([
|
|
|
|
"owner" => $user->getId(),
|
|
|
|
"special_type" => 32,
|
|
|
|
])->fetch();
|
|
|
|
if(!$album) {
|
|
|
|
$album = new Album;
|
|
|
|
$album->setName("[!!! internal album]");
|
|
|
|
$album->setOwner($user->getId());
|
|
|
|
$album->setSpecial_Type(32);
|
|
|
|
$album->setCreated($user->getRegistrationTime()->timestamp());
|
|
|
|
$album->save();
|
|
|
|
|
|
|
|
return $album;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Album($album);
|
|
|
|
}
|
2022-03-25 14:05:44 +03:00
|
|
|
|
|
|
|
function getAlbumByPhotoId(Photo $photo): ?Album
|
|
|
|
{
|
2022-03-25 16:36:38 +03:00
|
|
|
$dbalbum = $this->context->table("album_relations")->where(["media" => $photo->getId()])->fetch();
|
2022-03-25 14:05:44 +03:00
|
|
|
|
2022-03-25 14:44:10 +03:00
|
|
|
return $dbalbum->collection ? $this->get($dbalbum->collection) : null;
|
2022-03-25 14:05:44 +03:00
|
|
|
}
|
VKAPI: методы для подарков, заметок, статусов, обсуждений и немного для фоток и групп (#876)
* API methods for gifts, notes, statuses
* Some fixes
Строки локализации у gifts.send теперь не костыльные и можно прикрепить до 10 аттачей к посту
* Small imp
Пофиксил пагинацию у заметков и подарок
Перенёс структуру заметок
Добавил аттачи к комментариям
Добавил проверку на удалённость аттача
Ну и пофиксил сортировку заметок
* 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())
* fixsex
2023-06-13 21:03:43 +03:00
|
|
|
|
|
|
|
function getAlbumByOwnerAndId(int $owner, int $id)
|
|
|
|
{
|
|
|
|
$album = $this->albums->where([
|
|
|
|
"owner" => $owner,
|
|
|
|
"id" => $id
|
|
|
|
])->fetch();
|
2023-11-05 15:19:06 +03:00
|
|
|
|
|
|
|
return $album ? new Album($album) : NULL;
|
VKAPI: методы для подарков, заметок, статусов, обсуждений и немного для фоток и групп (#876)
* API methods for gifts, notes, statuses
* Some fixes
Строки локализации у gifts.send теперь не костыльные и можно прикрепить до 10 аттачей к посту
* Small imp
Пофиксил пагинацию у заметков и подарок
Перенёс структуру заметок
Добавил аттачи к комментариям
Добавил проверку на удалённость аттача
Ну и пофиксил сортировку заметок
* 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())
* fixsex
2023-06-13 21:03:43 +03:00
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|