PhotoPage: make prev/next photo logic more direct
This commit is contained in:
parent
507357ba59
commit
bc08e867f0
@ -40,17 +40,8 @@ class ViewPhoto extends HTMLController
|
|||||||
|
|
||||||
// What tag are we browsing?
|
// What tag are we browsing?
|
||||||
$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
|
$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
|
||||||
$id_tag = isset($tag) ? $tag->id_tag : null;
|
if (isset($tag))
|
||||||
|
$page->setTag($tag);
|
||||||
// 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->adopt($page);
|
||||||
$this->page->setCanonicalUrl($photo->getPageUrl());
|
$this->page->setCanonicalUrl($photo->getPageUrl());
|
||||||
|
@ -697,11 +697,11 @@ class Asset
|
|||||||
$params);
|
$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlForPreviousInSet($id_tag = null)
|
public function getUrlForPreviousInSet(?Tag $tag)
|
||||||
{
|
{
|
||||||
$row = Registry::get('db')->queryAssoc('
|
$row = Registry::get('db')->queryAssoc('
|
||||||
SELECT a.*
|
SELECT a.*
|
||||||
' . (isset($id_tag) ? '
|
' . (isset($tag) ? '
|
||||||
FROM assets_tags AS t
|
FROM assets_tags AS t
|
||||||
INNER JOIN assets AS a ON a.id_asset = t.id_asset
|
INNER JOIN assets AS a ON a.id_asset = t.id_asset
|
||||||
WHERE t.id_tag = {int:id_tag} AND
|
WHERE t.id_tag = {int:id_tag} AND
|
||||||
@ -715,24 +715,24 @@ class Asset
|
|||||||
LIMIT 1',
|
LIMIT 1',
|
||||||
[
|
[
|
||||||
'id_asset' => $this->id_asset,
|
'id_asset' => $this->id_asset,
|
||||||
'id_tag' => $id_tag,
|
'id_tag' => $tag->id_tag,
|
||||||
'date_captured' => $this->date_captured,
|
'date_captured' => $this->date_captured,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($row)
|
if ($row)
|
||||||
{
|
{
|
||||||
$obj = self::byRow($row, 'object');
|
$obj = self::byRow($row, 'object');
|
||||||
return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
|
return $obj->getPageUrl() . ($tag ? '?in=' . $tag->id_tag : '');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlForNextInSet($id_tag = null)
|
public function getUrlForNextInSet(?Tag $tag)
|
||||||
{
|
{
|
||||||
$row = Registry::get('db')->queryAssoc('
|
$row = Registry::get('db')->queryAssoc('
|
||||||
SELECT a.*
|
SELECT a.*
|
||||||
' . (isset($id_tag) ? '
|
' . (isset($tag) ? '
|
||||||
FROM assets_tags AS t
|
FROM assets_tags AS t
|
||||||
INNER JOIN assets AS a ON a.id_asset = t.id_asset
|
INNER JOIN assets AS a ON a.id_asset = t.id_asset
|
||||||
WHERE t.id_tag = {int:id_tag} AND
|
WHERE t.id_tag = {int:id_tag} AND
|
||||||
@ -746,14 +746,14 @@ class Asset
|
|||||||
LIMIT 1',
|
LIMIT 1',
|
||||||
[
|
[
|
||||||
'id_asset' => $this->id_asset,
|
'id_asset' => $this->id_asset,
|
||||||
'id_tag' => $id_tag,
|
'id_tag' => $tag->id_tag,
|
||||||
'date_captured' => $this->date_captured,
|
'date_captured' => $this->date_captured,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($row)
|
if ($row)
|
||||||
{
|
{
|
||||||
$obj = self::byRow($row, 'object');
|
$obj = self::byRow($row, 'object');
|
||||||
return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
|
return $obj->getPageUrl() . ($tag ? '?in=' . $tag->id_tag : '');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -10,24 +10,13 @@ class PhotoPage extends Template
|
|||||||
{
|
{
|
||||||
protected $photo;
|
protected $photo;
|
||||||
private $exif;
|
private $exif;
|
||||||
private $previous_photo_url = '';
|
private $tag;
|
||||||
private $next_photo_url = '';
|
|
||||||
|
|
||||||
public function __construct(Image $photo)
|
public function __construct(Image $photo)
|
||||||
{
|
{
|
||||||
$this->photo = $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()
|
public function html_main()
|
||||||
{
|
{
|
||||||
$this->photoNav();
|
$this->photoNav();
|
||||||
@ -86,18 +75,23 @@ class PhotoPage extends Template
|
|||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTag(Tag $tag)
|
||||||
|
{
|
||||||
|
$this->tag = $tag;
|
||||||
|
}
|
||||||
|
|
||||||
private function photoNav()
|
private function photoNav()
|
||||||
{
|
{
|
||||||
if ($this->previous_photo_url)
|
if ($previousUrl = $this->photo->getUrlForPreviousInSet($this->tag))
|
||||||
echo '
|
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
|
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 ($this->next_photo_url)
|
if ($nextUrl = $this->photo->getUrlForNextInSet($this->tag))
|
||||||
echo '
|
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
|
else
|
||||||
echo '
|
echo '
|
||||||
<span id="next_photo"><i class="bi bi-arrow-right"></i></span>';
|
<span id="next_photo"><i class="bi bi-arrow-right"></i></span>';
|
||||||
|
Loading…
Reference in New Issue
Block a user