From d227a14a1091b5f4128f2f1b7c0b27b407590ff6 Mon Sep 17 00:00:00 2001 From: lalka2018 <99399973+lalka2016@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:05:57 +0300 Subject: [PATCH] Add audio queue --- Web/Presenters/AudioPresenter.php | 84 +++++ Web/Presenters/templates/Audio/List.xml | 7 +- Web/Presenters/templates/Audio/Playlist.xml | 8 +- Web/Presenters/templates/Audio/bigplayer.xml | 11 +- Web/Presenters/templates/Audio/player.xml | 12 +- Web/Presenters/templates/Audio/tabs.xml | 2 +- Web/routes.yml | 2 + Web/static/css/audios.css | 37 +++ Web/static/css/main.css | 4 +- Web/static/js/al_music.js | 316 ++++++++++++++++++- 10 files changed, 458 insertions(+), 25 deletions(-) diff --git a/Web/Presenters/AudioPresenter.php b/Web/Presenters/AudioPresenter.php index 3776a52e..75d74fc7 100644 --- a/Web/Presenters/AudioPresenter.php +++ b/Web/Presenters/AudioPresenter.php @@ -298,7 +298,9 @@ final class AudioPresenter extends OpenVKPresenter $this->notFound(); $this->template->playlist = $playlist; + $this->template->page = (int)($this->queryParam("p") ?? 0); $this->template->audios = iterator_to_array($playlist->getAudios()); + $this->template->isBookmarked = $playlist->isBookmarkedBy($this->user->identity); $this->template->isMy = $playlist->getOwner()->getId() === $this->user->id; $this->template->canEdit = ($this->template->isMy || ($playlist->getOwner() instanceof Club && $playlist->getOwner()->canBeModifiedBy($this->user->identity))); $this->template->edit = $this->queryParam("act") === "edit"; @@ -453,4 +455,86 @@ final class AudioPresenter extends OpenVKPresenter { $this->renderList($owner, "playlists"); } + + function renderApiGetContext() + { + $this->assertUserLoggedIn(); + + if ($_SERVER["REQUEST_METHOD"] !== "POST") { + header("HTTP/1.1 405 Method Not Allowed"); + exit(""); + } + + $ctx_type = $this->postParam("context"); + $ctx_id = (int)($this->postParam("context_entity")); + $page = (int)($this->postParam("page") ?? 1); + $perPage = 10; + + switch($ctx_type) { + default: + case "entity_audios": + if($ctx_id > 0) { + $entity = (new Users)->get($ctx_id); + + if(!$entity || !$entity->getPrivacyPermission("audios.read", $this->user->identity)) + $this->flashFail("err", "Error", "Can't get queue", 80, true); + + $audios = $this->audios->getByUser($entity, $page, $perPage); + $audiosCount = $this->audios->getUserCollectionSize($entity); + } else { + $entity = (new Clubs)->get(abs($ctx_id)); + + if(!$entity || $entity->isBanned()) + $this->flashFail("err", "Error", "Can't get queue", 80, true); + + $audios = $this->audios->getByClub($entity, $page, $perPage); + $audiosCount = $this->audios->getClubCollectionSize($entity); + } + break; + case "new_audios": + $audios = $this->audios->getNew(); + $audiosCount = $audios->size(); + break; + case "popular_audios": + $audios = $this->audios->getPopular(); + $audiosCount = $audios->size(); + break; + case "playlist_context": + $playlist = $this->audios->getPlaylist($ctx_id); + + if (!$playlist || $playlist->isDeleted()) + $this->flashFail("err", "Error", "Can't get queue", 80, true); + + $audios = $playlist->getAudios($page, 10); + $audiosCount = $playlist->size(); + break; + } + + $pagesCount = ceil($audiosCount / $perPage); + + $audiosArr = []; + + foreach($audios as $audio) { + $audiosArr[] = [ + "id" => $audio->getId(), + "name" => $audio->getTitle(), + "performer" => $audio->getPerformer(), + "keys" => $audio->getKeys(), + "url" => $audio->getUrl(), + "length" => $audio->getLength(), + "available" => $audio->isAvailable(), + "withdrawn" => $audio->isWithdrawn(), + ]; + } + + $resultArr = [ + "page" => $page, + "perPage" => $perPage, + "pagesCount" => $pagesCount, + "count" => $audiosCount, + "items" => $audiosArr, + ]; + + $this->returnJson($resultArr); + } } \ No newline at end of file diff --git a/Web/Presenters/templates/Audio/List.xml b/Web/Presenters/templates/Audio/List.xml index 129791a7..189cd4a0 100644 --- a/Web/Presenters/templates/Audio/List.xml +++ b/Web/Presenters/templates/Audio/List.xml @@ -35,6 +35,11 @@ {* ref: https://archive.li/P32em *} {include "bigplayer.xml"} + + + + +
@@ -47,7 +52,7 @@
-
+
{include "../components/paginator.xml", conf => (object) [ "page" => $page, "count" => $audiosCount, diff --git a/Web/Presenters/templates/Audio/Playlist.xml b/Web/Presenters/templates/Audio/Playlist.xml index 10f1f579..1b8516ba 100644 --- a/Web/Presenters/templates/Audio/Playlist.xml +++ b/Web/Presenters/templates/Audio/Playlist.xml @@ -12,12 +12,16 @@ {include "bigplayer.xml"} {php $count = $playlist->size()} + +
- diff --git a/Web/Presenters/templates/Audio/bigplayer.xml b/Web/Presenters/templates/Audio/bigplayer.xml index 28d85e69..5b31cf8b 100644 --- a/Web/Presenters/templates/Audio/bigplayer.xml +++ b/Web/Presenters/templates/Audio/bigplayer.xml @@ -1,4 +1,5 @@
+