From 167a50cb9281794d49df7bb4fb08ab3485279734 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 11 Mar 2023 20:34:58 +0100 Subject: [PATCH] ViewPhotoAlbum: tweak album buttons to be more useful --- controllers/ViewPhotoAlbum.php | 75 ++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index aa3d632..d45588b 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -60,27 +60,7 @@ class ViewPhotoAlbum extends HTMLController // Can we do fancy things here? // !!! TODO: permission system? - $buttons = []; - - if (Registry::get('user')->isLoggedIn()) - { - $buttons[] = [ - 'url' => BASEURL . '/download/?tag=' . $id_tag, - 'caption' => 'Download this album', - ]; - - $buttons[] = [ - 'url' => BASEURL . '/uploadmedia/?tag=' . $id_tag, - 'caption' => 'Upload new photos here', - ]; - } - if (Registry::get('user')->isAdmin()) - $buttons[] = [ - 'url' => BASEURL . '/addalbum/?tag=' . $id_tag, - 'caption' => 'Create new subalbum here', - ]; - - // Enough actions for a button box? + $buttons = $this->getAlbumButtons($id_tag, $tag ?? null); if (!empty($buttons)) $this->page->adopt(new AlbumButtonBox($buttons)); @@ -164,6 +144,59 @@ class ViewPhotoAlbum extends HTMLController return $albums; } + private function getAlbumButtons($id_tag, $tag) + { + $buttons = []; + $user = Registry::get('user'); + + if ($user->isLoggedIn()) + { + $buttons[] = [ + 'url' => BASEURL . '/download/?tag=' . $id_tag, + 'caption' => 'Download album', + ]; + } + + if (isset($tag)) + { + if ($tag->kind === 'Album') + { + $buttons[] = [ + 'url' => BASEURL . '/uploadmedia/?tag=' . $id_tag, + 'caption' => 'Upload photos here', + ]; + } + + if ($user->isAdmin()) + { + if ($tag->kind === 'Album') + { + $buttons[] = [ + 'url' => BASEURL . '/editalbum/?id=' . $id_tag, + 'caption' => 'Edit album', + ]; + } + elseif ($tag->kind === 'Person') + { + $buttons[] = [ + 'url' => BASEURL . '/edittag/?id=' . $id_tag, + 'caption' => 'Edit tag', + ]; + } + } + } + + if ($user->isAdmin() && (!isset($tag) || $tag->kind === 'Album')) + { + $buttons[] = [ + 'url' => BASEURL . '/addalbum/?tag=' . $id_tag, + 'caption' => 'Create subalbum', + ]; + } + + return $buttons; + } + public function __destruct() { if (isset($this->iterator))