ViewPhotoAlbum: tweak album buttons to be more useful

This commit is contained in:
Aaron van Geffen 2023-03-11 20:34:58 +01:00
parent d9fd2ae20d
commit 167a50cb92

View File

@ -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))