2020-06-07 19:04:43 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Entities;
|
|
|
|
use openvk\Web\Models\Repositories\Photos;
|
|
|
|
|
2021-01-27 20:41:21 +03:00
|
|
|
class Album extends MediaCollection
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
|
|
|
const SPECIAL_AVATARS = 16;
|
|
|
|
const SPECIAL_WALL = 32;
|
|
|
|
|
2021-01-27 20:41:21 +03:00
|
|
|
protected $tableName = "albums";
|
|
|
|
protected $relTableName = "album_relations";
|
|
|
|
protected $entityTableName = "photos";
|
|
|
|
protected $entityClassName = 'openvk\Web\Models\Entities\Photo';
|
2020-06-07 19:04:43 +03:00
|
|
|
|
2021-01-27 20:41:21 +03:00
|
|
|
protected $specialNames = [
|
|
|
|
16 => "_avatar_album",
|
|
|
|
32 => "_wall_album",
|
|
|
|
64 => "_saved_photos_album",
|
|
|
|
];
|
2020-06-07 19:04:43 +03:00
|
|
|
|
2021-01-27 20:41:21 +03:00
|
|
|
function getCoverURL(): ?string
|
2020-06-07 19:04:43 +03:00
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
$coverPhoto = $this->getCoverPhoto();
|
|
|
|
if(!$coverPhoto)
|
|
|
|
return "/assets/packages/static/openvk/img/camera_200.png";
|
|
|
|
|
|
|
|
return $coverPhoto->getURL();
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCoverPhoto(): ?Photo
|
|
|
|
{
|
|
|
|
$cover = $this->getRecord()->cover_photo;
|
|
|
|
if(!$cover) {
|
|
|
|
$photos = iterator_to_array($this->getPhotos(1, 1));
|
|
|
|
$photo = $photos[0] ?? NULL;
|
|
|
|
if(!$photo || $photo->isDeleted())
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return $photo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new Photos)->get($cover);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPhotos(int $page = 1, ?int $perPage = NULL): \Traversable
|
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
return $this->fetch($page, $perPage);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPhotosCount(): int
|
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
return $this->size();
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function addPhoto(Photo $photo): void
|
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
$this->add($photo);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function removePhoto(Photo $photo): void
|
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
$this->remove($photo);
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function hasPhoto(Photo $photo): bool
|
|
|
|
{
|
2021-01-27 20:41:21 +03:00
|
|
|
return $this->has($photo);
|
2020-06-07 19:04:43 +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
|
|
|
|
2023-12-02 20:21:16 +03:00
|
|
|
function canBeViewedBy(?User $user = NULL): bool
|
|
|
|
{
|
|
|
|
if($this->isDeleted()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$owner = $this->getOwner();
|
|
|
|
|
|
|
|
if(get_class($owner) == "openvk\\Web\\Models\\Entities\\User") {
|
|
|
|
return $owner->canBeViewedBy($user) && $owner->getPrivacyPermission('photos.read', $user);
|
|
|
|
} else {
|
|
|
|
return $owner->canBeViewedBy($user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 toVkApiStruct(?User $user = NULL, bool $need_covers = false, bool $photo_sizes = false): object
|
|
|
|
{
|
|
|
|
$res = (object) [];
|
|
|
|
|
|
|
|
$res->id = $this->getPrettyId();
|
|
|
|
$res->thumb_id = !is_null($this->getCoverPhoto()) ? $this->getCoverPhoto()->getPrettyId() : 0;
|
|
|
|
$res->owner_id = $this->getOwner()->getId();
|
|
|
|
$res->title = $this->getName();
|
|
|
|
$res->description = $this->getDescription();
|
|
|
|
$res->created = $this->getCreationTime()->timestamp();
|
|
|
|
$res->updated = $this->getEditTime() ? $this->getEditTime()->timestamp() : NULL;
|
|
|
|
$res->size = $this->size();
|
|
|
|
$res->privacy_comment = 1;
|
|
|
|
$res->upload_by_admins_only = 1;
|
|
|
|
$res->comments_disabled = 0;
|
|
|
|
$res->can_upload = $this->canBeModifiedBy($user); # thisUser недоступен в entities
|
|
|
|
if($need_covers) {
|
|
|
|
$res->thumb_src = $this->getCoverURL();
|
|
|
|
|
|
|
|
if($photo_sizes) {
|
|
|
|
$res->sizes = !is_null($this->getCoverPhoto()) ? $this->getCoverPhoto()->getVkApiSizes() : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|