Download: allow limiting by user uploaded as well

This commit is contained in:
Aaron van Geffen 2024-01-15 11:40:33 +01:00
parent ec2d702a0d
commit 4b289a5e83
2 changed files with 15 additions and 6 deletions

View File

@ -21,22 +21,30 @@ class Download
$tag = (int)$_GET['tag']; $tag = (int)$_GET['tag'];
$album = Tag::fromId($tag); $album = Tag::fromId($tag);
if (isset($_GET['by']) && ($user = Member::fromSlug($_GET['by'])) !== false)
$id_user_uploaded = $user->getUserId();
else
$id_user_uploaded = null;
if (isset($_SESSION['current_export'])) if (isset($_SESSION['current_export']))
throw new UserFacingException('You can only export one album at the same time. Please wait until the other download finishes, or try again later.'); throw new UserFacingException('You can only export one album at the same time. Please wait until the other download finishes, or try again later.');
// So far so good? // So far so good?
$this->exportAlbum($album); $this->exportAlbum($album, $id_user_uploaded);
exit; exit;
} }
private function exportAlbum(Tag $album) private function exportAlbum(Tag $album, $id_user_uploaded)
{ {
$files = []; $files = [];
$album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag)); $album_ids = array_merge([$album->id_tag], $this->getChildAlbumIds($album->id_tag));
foreach ($album_ids as $album_id) foreach ($album_ids as $album_id)
{ {
$iterator = AssetIterator::getByOptions(['id_tag' => $album_id]); $iterator = AssetIterator::getByOptions([
'id_tag' => $album_id,
'id_user_uploaded' => $id_user_uploaded,
]);
while ($asset = $iterator->next()) while ($asset = $iterator->next())
$files[] = join(DIRECTORY_SEPARATOR, [$asset->getSubdir(), $asset->getFilename()]); $files[] = join(DIRECTORY_SEPARATOR, [$asset->getSubdir(), $asset->getFilename()]);
} }

View File

@ -79,7 +79,7 @@ class ViewPhotoAlbum extends HTMLController
} }
// Add an interface to query and modify the album/tag // Add an interface to query and modify the album/tag
$buttons = $this->getAlbumButtons($tag); $buttons = $this->getAlbumButtons($tag, $active_filter);
$button_strip = new AlbumButtonBox($buttons, $filters, $active_filter); $button_strip = new AlbumButtonBox($buttons, $filters, $active_filter);
$this->page->adopt($button_strip); $this->page->adopt($button_strip);
@ -174,15 +174,16 @@ class ViewPhotoAlbum extends HTMLController
return $albums; return $albums;
} }
private function getAlbumButtons(Tag $tag) private function getAlbumButtons(Tag $tag, $active_filter)
{ {
$buttons = []; $buttons = [];
$user = Registry::get('user'); $user = Registry::get('user');
if ($user->isLoggedIn()) if ($user->isLoggedIn())
{ {
$suffix = !empty($active_filter) ? '&by=' . $active_filter : '';
$buttons[] = [ $buttons[] = [
'url' => BASEURL . '/download/?tag=' . $tag->id_tag, 'url' => BASEURL . '/download/?tag=' . $tag->id_tag . $suffix,
'caption' => 'Download album', 'caption' => 'Download album',
]; ];
} }