Allow users to filter albums by contributors #48

Merged
Roflin merged 18 commits from refactor/viewalbum into master 2024-01-20 20:11:18 +01:00
3 changed files with 9 additions and 6 deletions
Showing only changes of commit ec2d702a0d - Show all commits

View File

@ -50,13 +50,12 @@ class ViewPhoto extends HTMLController
if (isset($_GET['by']))
{
// Let's first verify that the filter is valid
$contributors = array_filter($tag->getContributorList(), fn($el) => $el['slug'] === $_GET['by']);
if (count($contributors) !== 1)
$user = Member::fromSlug($_GET['by']);
if (!$user)
throw new UnexpectedValueException('Invalid filter for this album or tag.');
// Alright, let's run with it then
$filter = reset($contributors);
$page->setActiveFilter($filter['slug']);
$page->setActiveFilter($user->getSlug());
}
$this->page->adopt($page);

View File

@ -723,9 +723,8 @@ class Asset
}
// Take active filter into account as well
if (!empty($activeFilter))
if (!empty($activeFilter) && ($user = Member::fromSlug($activeFilter)) !== false)
{
$user = Member::fromSlug($activeFilter);
$where[] = 'id_user_uploaded = {int:id_user_uploaded}';
$params['id_user_uploaded'] = $user->getUserId();
}

View File

@ -75,6 +75,11 @@ abstract class User
return $this->ip_address;
}
public function getSlug()
{
return $this->slug;
}
/**
* Returns whether user is logged in.
*/