diff --git a/controllers/ViewPhoto.php b/controllers/ViewPhoto.php
index e6a8c390..52cb2f80 100644
--- a/controllers/ViewPhoto.php
+++ b/controllers/ViewPhoto.php
@@ -40,17 +40,8 @@ class ViewPhoto extends HTMLController
// What tag are we browsing?
$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
- $id_tag = isset($tag) ? $tag->id_tag : null;
-
- // Find previous photo in set.
- $previous_url = $photo->getUrlForPreviousInSet($id_tag);
- if ($previous_url)
- $page->setPreviousPhotoUrl($previous_url);
-
- // ... and the next photo, too.
- $next_url = $photo->getUrlForNextInSet($id_tag);
- if ($next_url)
- $page->setNextPhotoUrl($next_url);
+ if (isset($tag))
+ $page->setTag($tag);
$this->page->adopt($page);
$this->page->setCanonicalUrl($photo->getPageUrl());
diff --git a/models/Asset.php b/models/Asset.php
index 5779761d..93e77bc4 100644
--- a/models/Asset.php
+++ b/models/Asset.php
@@ -697,11 +697,11 @@ class Asset
$params);
}
- public function getUrlForPreviousInSet($id_tag = null)
+ public function getUrlForPreviousInSet(?Tag $tag)
{
$row = Registry::get('db')->queryAssoc('
SELECT a.*
- ' . (isset($id_tag) ? '
+ ' . (isset($tag) ? '
FROM assets_tags AS t
INNER JOIN assets AS a ON a.id_asset = t.id_asset
WHERE t.id_tag = {int:id_tag} AND
@@ -715,24 +715,24 @@ class Asset
LIMIT 1',
[
'id_asset' => $this->id_asset,
- 'id_tag' => $id_tag,
+ 'id_tag' => $tag->id_tag,
'date_captured' => $this->date_captured,
]);
if ($row)
{
$obj = self::byRow($row, 'object');
- return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
+ return $obj->getPageUrl() . ($tag ? '?in=' . $tag->id_tag : '');
}
else
return false;
}
- public function getUrlForNextInSet($id_tag = null)
+ public function getUrlForNextInSet(?Tag $tag)
{
$row = Registry::get('db')->queryAssoc('
SELECT a.*
- ' . (isset($id_tag) ? '
+ ' . (isset($tag) ? '
FROM assets_tags AS t
INNER JOIN assets AS a ON a.id_asset = t.id_asset
WHERE t.id_tag = {int:id_tag} AND
@@ -746,14 +746,14 @@ class Asset
LIMIT 1',
[
'id_asset' => $this->id_asset,
- 'id_tag' => $id_tag,
+ 'id_tag' => $tag->id_tag,
'date_captured' => $this->date_captured,
]);
if ($row)
{
$obj = self::byRow($row, 'object');
- return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
+ return $obj->getPageUrl() . ($tag ? '?in=' . $tag->id_tag : '');
}
else
return false;
diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php
index 9554106d..1b61f2df 100644
--- a/templates/PhotoPage.php
+++ b/templates/PhotoPage.php
@@ -10,24 +10,13 @@ class PhotoPage extends Template
{
protected $photo;
private $exif;
- private $previous_photo_url = '';
- private $next_photo_url = '';
+ private $tag;
public function __construct(Image $photo)
{
$this->photo = $photo;
}
- public function setPreviousPhotoUrl($url)
- {
- $this->previous_photo_url = $url;
- }
-
- public function setNextPhotoUrl($url)
- {
- $this->next_photo_url = $url;
- }
-
public function html_main()
{
$this->photoNav();
@@ -86,18 +75,23 @@ class PhotoPage extends Template
';
}
+ public function setTag(Tag $tag)
+ {
+ $this->tag = $tag;
+ }
+
private function photoNav()
{
- if ($this->previous_photo_url)
+ if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag))
echo '
- ';
+ ';
else
echo '
';
- if ($this->next_photo_url)
+ if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag))
echo '
- ';
+ ';
else
echo '
';