diff --git a/controllers/ViewPhoto.php b/controllers/ViewPhoto.php index eafaf31a..4f7dfb01 100644 --- a/controllers/ViewPhoto.php +++ b/controllers/ViewPhoto.php @@ -22,6 +22,20 @@ class ViewPhoto extends HTMLController if ($exif) $page->setExif($exif); + // 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); + $this->page->adopt($page); $this->page->setCanonicalUrl($photo->getPageUrl()); diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index 3cc48769..4f26d074 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -79,7 +79,12 @@ class ViewPhotoAlbum extends HTMLController // Load a photo mosaic for the current tag. list($mosaic, $total_count) = $this->getPhotoMosaic($id_tag, $page); if (isset($mosaic)) - $this->page->adopt(new PhotosIndex($mosaic, Registry::get('user')->isAdmin())); + { + $index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin()); + $this->page->adopt($index); + if ($id_tag > 1) + $index->setUrlSuffix('?in=' . $id_tag); + } // Make a page index as needed, while we're at it. if ($total_count > self::PER_PAGE) diff --git a/models/Asset.php b/models/Asset.php index d03f12a8..7b46c259 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -500,4 +500,70 @@ class Asset WHERE id_asset = {int:id_asset}', $params); } + + public function getUrlForPreviousInSet($id_tag = null) + { + $row = Registry::get('db')->queryAssoc(' + SELECT a.* + ' . (isset($id_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 + a.date_captured <= {datetime:date_captured} AND + a.id_asset != {int:id_asset} + ORDER BY a.date_captured DESC' + : ' + FROM assets AS a + WHERE date_captured >= {datetime:date_captured} AND + a.id_asset != {int:id_asset} + ORDER BY date_captured ASC') + . ' + LIMIT 1', + [ + 'id_asset' => $this->id_asset, + 'id_tag' => $id_tag, + 'date_captured' => $this->date_captured, + ]); + + if ($row) + { + $obj = self::byRow($row, 'object'); + return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : ''); + } + else + return false; + } + + public function getUrlForNextInSet($id_tag = null) + { + $row = Registry::get('db')->queryAssoc(' + SELECT a.* + ' . (isset($id_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 + a.date_captured >= {datetime:date_captured} AND + a.id_asset != {int:id_asset} + ORDER BY a.date_captured ASC' + : ' + FROM assets AS a + WHERE date_captured <= {datetime:date_captured} AND + a.id_asset != {int:id_asset} + ORDER BY date_captured DESC') + . ' + LIMIT 1', + [ + 'id_asset' => $this->id_asset, + 'id_tag' => $id_tag, + 'date_captured' => $this->date_captured, + ]); + + if ($row) + { + $obj = self::byRow($row, 'object'); + return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : ''); + } + else + return false; + } } diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php index 2499bcb5..470839f6 100644 --- a/templates/PhotoPage.php +++ b/templates/PhotoPage.php @@ -10,12 +10,24 @@ class PhotoPage extends SubTemplate { private $photo; private $exif; + private $previous_photo_url = ''; + private $next_photo_url = ''; 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; + } + protected function html_content() { $this->photoNav(); @@ -57,16 +69,16 @@ class PhotoPage extends SubTemplate private function photoNav() { - if (false) // $previous_post = $this->post->getPreviousPostUrl()) + if ($this->previous_photo_url) echo ' - Previous photo'; + Previous photo'; else echo ' Previous photo'; - if (false) //$this->post->getNextPostUrl()) + if ($this->next_photo_url) echo ' - Next photo'; + Next photo'; else echo ' Next photo'; diff --git a/templates/PhotosIndex.php b/templates/PhotosIndex.php index 044ef394..0a94fc1d 100644 --- a/templates/PhotosIndex.php +++ b/templates/PhotosIndex.php @@ -13,6 +13,7 @@ class PhotosIndex extends SubTemplate protected $show_labels; protected $row_limit = 1000; protected $previous_header = ''; + protected $url_suffix; const PANORAMA_WIDTH = 1280; const PANORAMA_HEIGHT = null; @@ -95,7 +96,7 @@ class PhotosIndex extends SubTemplate Edit'; echo ' - + '; if ($this->show_labels) @@ -262,4 +263,9 @@ class PhotosIndex extends SubTemplate echo ' '; } + + public function setUrlSuffix($suffix) + { + $this->url_suffix = $suffix; + } }