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
2 changed files with 24 additions and 15 deletions
Showing only changes of commit 9c00248a7f - Show all commits

View File

@ -47,15 +47,19 @@ class ViewPhotoAlbum extends HTMLController
$contributors = $tag->getContributorList(); $contributors = $tag->getContributorList();
// Enumerate possible filters // Enumerate possible filters
$filters = ['' => ['id_user' => null, 'caption' => 'Show all photos', 'link' => $tag->getUrl()]]; $filters = [];
foreach ($contributors as $contributor) if (!empty($contributors))
{ {
$filters[$contributor['slug']] = [ $filters[''] = ['id_user' => null, 'caption' => 'Show all photos', 'link' => $tag->getUrl()];
Aaron marked this conversation as resolved Outdated

Key label missing

Key `label` missing
Outdated
Review

I initially didn't add it as it'd never be used. You're right, though, and it's better to just have it there for consistency.

I initially didn't add it as it'd never be used. You're right, though, and it's better to just have it there for consistency.
'id_user' => $contributor['id_user'], foreach ($contributors as $contributor)
'caption' => sprintf('By %s (%s photos)', {
$contributor['first_name'], $contributor['num_assets']), $filters[$contributor['slug']] = [
'link' => $tag->getUrl() . '/?by=' . $contributor['slug'], 'id_user' => $contributor['id_user'],
]; 'caption' => sprintf('By %s (%s photos)',
$contributor['first_name'], $contributor['num_assets']),
'link' => $tag->getUrl() . '/?by=' . $contributor['slug'],
];
}
} }
// Limit to a particular uploader? // Limit to a particular uploader?

View File

@ -28,26 +28,31 @@ class AlbumButtonBox extends Template
echo ' echo '
<a class="btn btn-light" href="', $button['url'], '">', $button['caption'], '</a>'; <a class="btn btn-light" href="', $button['url'], '">', $button['caption'], '</a>';
echo ' if (!empty($this->filters))
{
echo '
<div class="dropdown"> <div class="dropdown">
<button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> <button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-filter"></i> <i class="bi bi-filter"></i>
</button> </button>
<ul class="dropdown-menu">'; <ul class="dropdown-menu">';
foreach ($this->filters as $key => $filter) foreach ($this->filters as $key => $filter)
{ {
$is_active = $key === $this->active_filter; $is_active = $key === $this->active_filter;
echo ' echo '
<li><a class="dropdown-item', $is_active ? ' active' : '', <li><a class="dropdown-item', $is_active ? ' active' : '',
'" href="', $filter['link'], '">', '" href="', $filter['link'], '">',
$filter['caption'], $filter['caption'],
'</a></li>'; '</a></li>';
}
echo '
</ul>
</div>';
} }
echo ' echo '
</ul>
</div>
</div>'; </div>';
} }
} }