EditAsset: allow changing an asset's parent album

This commit is contained in:
2023-11-12 17:26:03 +01:00
parent 44c6bf5914
commit 0c861bf976
3 changed files with 106 additions and 6 deletions

View File

@@ -31,6 +31,25 @@ class EditAsset extends HTMLController
exit;
}
// Get a list of available photo albums
$allAlbums = [];
foreach (PhotoAlbum::getHierarchy('tag', 'up') as $album)
$allAlbums[$album['id_tag']] = $album['tag'];
// Figure out the current album id
$currentAlbumId = 0;
$currentAlbumSlug = '';
$currentTags = $asset->getTags();
foreach ($currentTags as $tag)
{
if ($tag->kind === 'Album')
{
$currentAlbumId = $tag->id_tag;
$currentAlbumSlug = $tag->slug;
break;
}
}
if (!empty($_POST))
{
if (isset($_GET['updatethumb']))
@@ -48,6 +67,26 @@ class EditAsset extends HTMLController
$asset->setKeyData(htmlspecialchars($_POST['title']), $slug, $date_captured, intval($_POST['priority']));
}
// Changing parent album?
if ($_POST['id_album'] != $currentAlbumId)
{
$targetAlbum = Tag::fromId($_POST['id_album']);
// First move the asset, then sort out the album tag
if (($retCode = $asset->moveToSubDir($targetAlbum->slug)) === true)
{
if (!isset($_POST['tag']))
$_POST['tag'] = [];
// Unset tag for current parent album
if (isset($_POST['tag'][$currentAlbumId]))
unset($_POST['tag'][$currentAlbumId]);
// Set tag for new parent album
$_POST['tag'][$_POST['id_album']] = true;
}
}
// Handle tags
$new_tags = [];
if (isset($_POST['tag']) && is_array($_POST['tag']))
@@ -98,10 +137,13 @@ class EditAsset extends HTMLController
header('Location: ' . BASEURL . '/editasset/?id=' . $asset->getId());
}
// Get list of thumbnails
$thumbs = $this->getThumbs($asset);
$page = new EditAssetForm([
'asset' => $asset,
'thumbs' => $this->getThumbs($asset),
'allAlbums' => $allAlbums,
'currentAlbumId' => $currentAlbumId,
]);
$page = new EditAssetForm($asset, $thumbs);
parent::__construct('Edit asset \'' . $asset->getTitle() . '\' (' . $asset->getFilename() . ') - ' . SITE_TITLE);
$this->page->adopt($page);
}