Allow users to filter albums by contributors #48
@ -46,6 +46,19 @@ class ViewPhoto extends HTMLController
|
|||||||
if (isset($tag))
|
if (isset($tag))
|
||||||
$page->setTag($tag);
|
$page->setTag($tag);
|
||||||
|
|
||||||
|
// Keeping tabs on a filter?
|
||||||
|
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)
|
||||||
|
throw new UnexpectedValueException('Invalid filter for this album or tag.');
|
||||||
|
|
||||||
|
// Alright, let's run with it then
|
||||||
|
$filter = reset($contributors);
|
||||||
|
$page->setActiveFilter($filter['slug']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->page->adopt($page);
|
$this->page->adopt($page);
|
||||||
$this->page->setCanonicalUrl($this->photo->getPageUrl());
|
$this->page->setCanonicalUrl($this->photo->getPageUrl());
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,15 @@ class ViewPhotoAlbum extends HTMLController
|
|||||||
{
|
{
|
||||||
$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
|
$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
|
||||||
$this->page->adopt($index);
|
$this->page->adopt($index);
|
||||||
if ($id_tag > 1)
|
|
||||||
$index->setUrlSuffix('?in=' . $id_tag);
|
$url_params = [];
|
||||||
|
if (isset($tag) && $tag->id_parent != 0)
|
||||||
|
$url_params['in'] = $tag->id_tag;
|
||||||
|
if (!empty($active_filter))
|
||||||
|
$url_params['by'] = $active_filter;
|
||||||
|
|
||||||
|
if (!empty($url_params))
|
||||||
|
$index->setUrlSuffix('?' . http_build_query($url_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a page index as needed, while we're at it.
|
// Make a page index as needed, while we're at it.
|
||||||
|
@ -697,7 +697,7 @@ class Asset
|
|||||||
$params);
|
$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getUrlForAdjacentInSet($prevNext, ?Tag $tag)
|
protected function getUrlForAdjacentInSet($prevNext, ?Tag $tag, $activeFilter)
|
||||||
{
|
{
|
||||||
$next = $prevNext === 'next';
|
$next = $prevNext === 'next';
|
||||||
$previous = !$next;
|
$previous = !$next;
|
||||||
@ -722,6 +722,14 @@ class Asset
|
|||||||
$params['order_dir'] = $previous ? 'ASC' : 'DESC';
|
$params['order_dir'] = $previous ? 'ASC' : 'DESC';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Take active filter into account as well
|
||||||
|
if (!empty($activeFilter))
|
||||||
|
{
|
||||||
|
$user = Member::fromSlug($activeFilter);
|
||||||
|
$where[] = 'id_user_uploaded = {int:id_user_uploaded}';
|
||||||
|
$params['id_user_uploaded'] = $user->getUserId();
|
||||||
|
}
|
||||||
|
|
||||||
// Use complete ordering when sorting the set
|
// Use complete ordering when sorting the set
|
||||||
$where[] = '(a.date_captured, a.id_asset) {raw:where_op} ' .
|
$where[] = '(a.date_captured, a.id_asset) {raw:where_op} ' .
|
||||||
'({datetime:date_captured}, {int:id_asset})';
|
'({datetime:date_captured}, {int:id_asset})';
|
||||||
@ -740,22 +748,29 @@ class Asset
|
|||||||
LIMIT 1',
|
LIMIT 1',
|
||||||
$params);
|
$params);
|
||||||
|
|
||||||
if ($row)
|
if (!$row)
|
||||||
{
|
|
||||||
$obj = self::byRow($row, 'object');
|
|
||||||
return $obj->getPageUrl() . ($tag ? '?in=' . $tag->id_tag : '');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
$obj = self::byRow($row, 'object');
|
||||||
|
|
||||||
|
$urlParams = [];
|
||||||
|
if (isset($tag))
|
||||||
|
$urlParams['in'] = $tag->id_tag;
|
||||||
|
if (!empty($activeFilter))
|
||||||
|
$urlParams['by'] = $activeFilter;
|
||||||
|
|
||||||
|
$queryString = !empty($urlParams) ? '?' . http_build_query($urlParams) : '';
|
||||||
|
|
||||||
|
return $obj->getPageUrl() . $queryString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlForPreviousInSet(?Tag $tag)
|
public function getUrlForPreviousInSet(?Tag $tag, $activeFilter)
|
||||||
{
|
{
|
||||||
return $this->getUrlForAdjacentInSet('previous', $tag);
|
return $this->getUrlForAdjacentInSet('previous', $tag, $activeFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlForNextInSet(?Tag $tag)
|
public function getUrlForNextInSet(?Tag $tag, $activeFilter)
|
||||||
{
|
{
|
||||||
return $this->getUrlForAdjacentInSet('next', $tag);
|
return $this->getUrlForAdjacentInSet('next', $tag, $activeFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
class PhotoPage extends Template
|
class PhotoPage extends Template
|
||||||
{
|
{
|
||||||
|
private $activeFilter;
|
||||||
private $photo;
|
private $photo;
|
||||||
private $metaData;
|
private $metaData;
|
||||||
private $tag;
|
private $tag;
|
||||||
@ -78,6 +79,11 @@ class PhotoPage extends Template
|
|||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setActiveFilter($filter)
|
||||||
|
{
|
||||||
|
$this->activeFilter = $filter;
|
||||||
|
}
|
||||||
|
|
||||||
public function setTag(Tag $tag)
|
public function setTag(Tag $tag)
|
||||||
{
|
{
|
||||||
$this->tag = $tag;
|
$this->tag = $tag;
|
||||||
@ -85,14 +91,14 @@ class PhotoPage extends Template
|
|||||||
|
|
||||||
private function photoNav()
|
private function photoNav()
|
||||||
{
|
{
|
||||||
if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag))
|
if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag, $this->activeFilter))
|
||||||
echo '
|
echo '
|
||||||
<a href="', $previousUrl, '#photo_frame" id="previous_photo"><i class="bi bi-arrow-left"></i></a>';
|
<a href="', $previousUrl, '#photo_frame" id="previous_photo"><i class="bi bi-arrow-left"></i></a>';
|
||||||
else
|
else
|
||||||
echo '
|
echo '
|
||||||
<span id="previous_photo"><i class="bi bi-arrow-left"></i></span>';
|
<span id="previous_photo"><i class="bi bi-arrow-left"></i></span>';
|
||||||
|
|
||||||
if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag))
|
if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag, $this->activeFilter))
|
||||||
echo '
|
echo '
|
||||||
<a href="', $nextUrl, '#photo_frame" id="next_photo"><i class="bi bi-arrow-right"></i></a>';
|
<a href="', $nextUrl, '#photo_frame" id="next_photo"><i class="bi bi-arrow-right"></i></a>';
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user