diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index 5e99697..815f6d2 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -57,8 +57,30 @@ class ViewPhotoAlbum extends HTMLController $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. - 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)) { $index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin()); @@ -75,7 +97,7 @@ class ViewPhotoAlbum extends HTMLController 'items_per_page' => self::PER_PAGE, 'start' => (isset($_GET['page']) ? $_GET['page'] - 1 : 0) * self::PER_PAGE, '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', ]); $this->page->adopt(new PageIndexWidget($index)); @@ -85,11 +107,12 @@ class ViewPhotoAlbum extends HTMLController $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. list($this->iterator, $total_count) = AssetIterator::getByOptions([ 'id_tag' => $id_tag, + 'id_user_uploaded' => $id_user_uploaded, 'order' => 'date_captured', 'direction' => $sort_linear ? 'asc' : 'desc', 'limit' => self::PER_PAGE, diff --git a/models/AssetIterator.php b/models/AssetIterator.php index 94132aa..2eabbf3 100644 --- a/models/AssetIterator.php +++ b/models/AssetIterator.php @@ -118,6 +118,11 @@ class AssetIterator extends Asset else $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'])) { $params['id_tag'] = $options['id_tag'];