Rework meta data display on photo page #45

Merged
minnozz merged 5 commits from photo-page into master 2024-01-13 17:23:06 +01:00
3 changed files with 20 additions and 35 deletions
Showing only changes of commit bc08e867f0 - Show all commits

View File

@ -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());

View File

@ -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;

View File

@ -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
</a>';
}
public function setTag(Tag $tag)
{
$this->tag = $tag;
}
private function photoNav()
{
if ($this->previous_photo_url)
if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag))
echo '
<a href="', $this->previous_photo_url, '#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
echo '
<span id="previous_photo"><i class="bi bi-arrow-left"></i></span>';
if ($this->next_photo_url)
if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag))
echo '
<a href="', $this->next_photo_url, '#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
echo '
<span id="next_photo"><i class="bi bi-arrow-right"></i></span>';