2023-01-31 14:23:34 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
|
|
|
use openvk\Web\Models\Entities\Club;
|
|
|
|
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
|
|
|
use openvk\Web\Models\Entities\Video as VideoEntity;
|
|
|
|
use openvk\Web\Models\Repositories\Videos as VideosRepo;
|
|
|
|
use openvk\Web\Models\Entities\Comment;
|
|
|
|
use openvk\Web\Models\Repositories\Comments as CommentsRepo;
|
|
|
|
|
|
|
|
final class Video extends VKAPIRequestHandler
|
|
|
|
{
|
2023-11-14 22:44:39 +03:00
|
|
|
function get(int $owner_id, string $videos = "", int $offset = 0, int $count = 30, int $extended = 0): object
|
2023-01-31 14:23:34 +03:00
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
2023-11-14 22:44:39 +03:00
|
|
|
if(!empty($videos)) {
|
2023-04-29 16:05:37 +03:00
|
|
|
$vids = explode(',', $videos);
|
|
|
|
|
|
|
|
foreach($vids as $vid)
|
|
|
|
{
|
|
|
|
$id = explode("_", $vid);
|
|
|
|
|
|
|
|
$items = [];
|
|
|
|
|
|
|
|
$video = (new VideosRepo)->getByOwnerAndVID(intval($id[0]), intval($id[1]));
|
|
|
|
if($video) {
|
2023-11-15 11:41:18 +03:00
|
|
|
$items[] = $video->getApiStructure($this->getUser());
|
2023-04-29 16:05:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"count" => count($items),
|
|
|
|
"items" => $items
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
if ($owner_id > 0)
|
2023-12-02 20:21:16 +03:00
|
|
|
$user = (new UsersRepo)->get($owner_id);
|
2023-04-29 16:05:37 +03:00
|
|
|
else
|
2023-11-15 11:41:18 +03:00
|
|
|
$this->fail(1, "Not implemented");
|
|
|
|
|
2023-12-02 20:21:16 +03:00
|
|
|
if(!$user || $user->isDeleted())
|
|
|
|
$this->fail(14, "Invalid user");
|
|
|
|
|
|
|
|
if(!$user->getPrivacyPermission('videos.read', $this->getUser()))
|
|
|
|
$this->fail(21, "This user chose to hide his videos.");
|
|
|
|
|
2023-04-29 16:05:37 +03:00
|
|
|
$videos = (new VideosRepo)->getByUser($user, $offset + 1, $count);
|
|
|
|
$videosCount = (new VideosRepo)->getUserVideosCount($user);
|
|
|
|
|
2023-01-31 14:23:34 +03:00
|
|
|
$items = [];
|
2023-04-29 16:05:37 +03:00
|
|
|
foreach ($videos as $video) {
|
2023-11-15 11:41:18 +03:00
|
|
|
$items[] = $video->getApiStructure($this->getUser());
|
2023-01-31 14:23:34 +03:00
|
|
|
}
|
2023-04-29 16:05:37 +03:00
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"count" => $videosCount,
|
|
|
|
"items" => $items
|
|
|
|
];
|
2023-01-31 14:23:34 +03:00
|
|
|
}
|
|
|
|
}
|
2024-10-25 16:28:35 +03:00
|
|
|
|
|
|
|
function search(string $q = '', int $sort = 0, int $offset = 0, int $count = 10, bool $extended = false, string $fields = ''): object
|
|
|
|
{
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
$params = [];
|
|
|
|
$db_sort = ['type' => 'id', 'invert' => false];
|
|
|
|
$videos = (new VideosRepo)->find($q, $params, $db_sort);
|
|
|
|
$items = iterator_to_array($videos->offsetLimit($offset, $count));
|
|
|
|
$count = $videos->size();
|
|
|
|
|
|
|
|
$return_items = [];
|
|
|
|
$profiles = [];
|
|
|
|
$groups = [];
|
|
|
|
foreach($items as $item)
|
|
|
|
$return_item = $item->getApiStructure($this->getUser());
|
|
|
|
$return_item = $return_item->video;
|
|
|
|
$return_items[] = $return_item;
|
|
|
|
|
|
|
|
if($return_item['owner_id']) {
|
|
|
|
if($return_item['owner_id'] > 0)
|
|
|
|
$profiles[] = $return_item['owner_id'];
|
|
|
|
else
|
|
|
|
$groups[] = abs($return_item['owner_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($extended) {
|
|
|
|
$profiles = array_unique($profiles);
|
|
|
|
$groups = array_unique($groups);
|
|
|
|
|
|
|
|
$profilesFormatted = [];
|
|
|
|
$groupsFormatted = [];
|
|
|
|
|
|
|
|
foreach($profiles as $prof) {
|
|
|
|
$profile = (new UsersRepo)->get($prof);
|
|
|
|
$profilesFormatted[] = $profile->toVkApiStruct($this->getUser(), $fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($groups as $gr) {
|
|
|
|
$group = (new ClubsRepo)->get($gr);
|
|
|
|
$groupsFormatted[] = $group->toVkApiStruct($this->getUser(), $fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"count" => $count,
|
|
|
|
"items" => $return_items,
|
|
|
|
"profiles" => $profilesFormatted,
|
|
|
|
"groups" => $groupsFormatted,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
"count" => $count,
|
|
|
|
"items" => $return_items,
|
|
|
|
];
|
|
|
|
}
|
2023-01-31 14:23:34 +03:00
|
|
|
}
|