openvk/Web/Models/Entities/VideoAlbum.php

50 lines
1.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2021-01-27 20:39:15 +03:00
namespace openvk\Web\Models\Entities;
2021-01-27 20:39:15 +03:00
use openvk\Web\Models\Repositories\Videos;
class VideoAlbum extends MediaCollection
{
public const SPECIAL_ADDED = 16;
public const SPECIAL_UPLOADED = 32;
2021-01-27 20:39:15 +03:00
protected $tableName = "video_playlists";
protected $relTableName = "vp_relations";
protected $entityTableName = "videos";
protected $entityClassName = 'openvk\Web\Models\Entities\Video';
2021-01-27 20:39:15 +03:00
protected $specialNames = [
16 => "_added_album",
32 => "_uploaded_album",
];
public function getCoverURL(): ?string
2021-01-27 20:39:15 +03:00
{
$cover = $this->getCoverVideo();
if (!$cover) {
2021-01-27 20:39:15 +03:00
return "/assets/packages/static/openvk/img/camera_200.png";
}
2021-01-27 20:39:15 +03:00
return $cover->getThumbnailURL();
}
public function getCoverVideo(): ?Photo
2021-01-27 20:39:15 +03:00
{
$cover = $this->getRecord()->cover_video;
if (!$cover) {
2021-01-27 20:39:15 +03:00
$vids = iterator_to_array($this->fetch(1, 1));
$vid = $vids[0] ?? null;
if (!$vid || $vid->isDeleted()) {
return null;
} else {
2021-01-27 20:39:15 +03:00
return $vid;
}
2021-01-27 20:39:15 +03:00
}
return (new Videos())->get($cover);
2021-01-27 20:39:15 +03:00
}
}