Allow users to filter albums by contributors #48
@ -57,8 +57,30 @@ class ViewPhotoAlbum extends HTMLController
|
|||||||
$this->page->adopt($index);
|
$this->page->adopt($index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Who contributed to this album?
|
||||||
|
$contributors = $tag->getContributorList();
|
||||||
|
|
||||||
|
// Enumerate possible filters
|
||||||
|
$filters = ['' => [null, 'Show all photos']];
|
||||||
|
foreach ($contributors as $contributor)
|
||||||
|
{
|
||||||
|
$filters[$contributor['slug']] = [$contributor['id_user'], sprintf('%s %s (%s photos)',
|
||||||
|
$contributor['first_name'], $contributor['surname'], $contributor['num_assets'])];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit to a particular uploader?
|
||||||
|
$active_filter = $id_user_uploaded = null;
|
||||||
|
if (!empty($_GET['by']))
|
||||||
|
{
|
||||||
|
if (!isset($filters[$_GET['by']]))
|
||||||
|
throw new UnexpectedValueException('Invalid filter for this album or tag.');
|
||||||
|
|
||||||
|
$active_filter = $_GET['by'];
|
||||||
|
$id_user_uploaded = $filters[$active_filter][0];
|
||||||
|
}
|
||||||
|
|
||||||
// Load a photo mosaic for the current tag.
|
// Load a photo mosaic for the current tag.
|
||||||
list($mosaic, $total_count) = $this->getPhotoMosaic($id_tag, $page, !isset($is_person));
|
list($mosaic, $total_count) = $this->getPhotoMosaic($id_tag, $id_user_uploaded, $page, !isset($is_person));
|
||||||
if (isset($mosaic))
|
if (isset($mosaic))
|
||||||
{
|
{
|
||||||
$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
|
$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
|
||||||
@ -75,7 +97,7 @@ class ViewPhotoAlbum extends HTMLController
|
|||||||
'items_per_page' => self::PER_PAGE,
|
'items_per_page' => self::PER_PAGE,
|
||||||
'start' => (isset($_GET['page']) ? $_GET['page'] - 1 : 0) * self::PER_PAGE,
|
'start' => (isset($_GET['page']) ? $_GET['page'] - 1 : 0) * self::PER_PAGE,
|
||||||
'base_url' => $tag->getUrl(),
|
'base_url' => $tag->getUrl(),
|
||||||
'page_slug' => 'page/%PAGE%/',
|
'page_slug' => 'page/%PAGE%/' . (isset($active_filter) ? '?by=' . $active_filter : ''),
|
||||||
'index_class' => 'pagination-lg justify-content-around justify-content-lg-center',
|
'index_class' => 'pagination-lg justify-content-around justify-content-lg-center',
|
||||||
]);
|
]);
|
||||||
$this->page->adopt(new PageIndexWidget($index));
|
$this->page->adopt(new PageIndexWidget($index));
|
||||||
@ -85,11 +107,12 @@ class ViewPhotoAlbum extends HTMLController
|
|||||||
$this->page->setCanonicalUrl($tag->getUrl() . ($page > 1 ? 'page/' . $page . '/' : ''));
|
$this->page->setCanonicalUrl($tag->getUrl() . ($page > 1 ? 'page/' . $page . '/' : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPhotoMosaic($id_tag, $page, $sort_linear)
|
public function getPhotoMosaic($id_tag, $id_user_uploaded, $page, $sort_linear)
|
||||||
{
|
{
|
||||||
// Create an iterator.
|
// Create an iterator.
|
||||||
list($this->iterator, $total_count) = AssetIterator::getByOptions([
|
list($this->iterator, $total_count) = AssetIterator::getByOptions([
|
||||||
'id_tag' => $id_tag,
|
'id_tag' => $id_tag,
|
||||||
|
'id_user_uploaded' => $id_user_uploaded,
|
||||||
'order' => 'date_captured',
|
'order' => 'date_captured',
|
||||||
'direction' => $sort_linear ? 'asc' : 'desc',
|
'direction' => $sort_linear ? 'asc' : 'desc',
|
||||||
'limit' => self::PER_PAGE,
|
'limit' => self::PER_PAGE,
|
||||||
|
@ -118,6 +118,11 @@ class AssetIterator extends Asset
|
|||||||
else
|
else
|
||||||
$where[] = 'a.mimetype = {string:mime_type}';
|
$where[] = 'a.mimetype = {string:mime_type}';
|
||||||
}
|
}
|
||||||
|
if (isset($options['id_user_uploaded']))
|
||||||
|
{
|
||||||
|
$params['id_user_uploaded'] = $options['id_user_uploaded'];
|
||||||
|
$where[] = 'id_user_uploaded = {int:id_user_uploaded}';
|
||||||
|
}
|
||||||
if (isset($options['id_tag']))
|
if (isset($options['id_tag']))
|
||||||
{
|
{
|
||||||
$params['id_tag'] = $options['id_tag'];
|
$params['id_tag'] = $options['id_tag'];
|
||||||
|
Loading…
Reference in New Issue
Block a user