summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/albums.php12
-rw-r--r--core/models/item.php13
-rw-r--r--themes/default/views/header.html.php2
3 files changed, 26 insertions, 1 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php
index 668e868a..7f78303e 100644
--- a/core/controllers/albums.php
+++ b/core/controllers/albums.php
@@ -26,6 +26,18 @@ class Albums_Controller extends Items_Controller {
access::required("view", $album);
$page_size = module::get_var("core", "page_size", 9);
+ $show = $this->input->get("show");
+
+ if ($show) {
+ $index = $album->get_position($show);
+ $page = ceil($index / $page_size);
+ if ($page == 1) {
+ url::redirect("albums/$album->id");
+ } else {
+ url::redirect("albums/$album->id?page=$page");
+ }
+ }
+
$page = $this->input->get("page", "1");
$children_count = $album->viewable()->children_count();
$offset = ($page-1) * $page_size;
diff --git a/core/models/item.php b/core/models/item.php
index ffdaa7e9..6f56e726 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -234,4 +234,17 @@ class Item_Model extends ORM_MPTT {
return model_cache::get("item", $this->album_cover_item_id);
}
+
+ /**
+ * Find the position of the given child id in this album. The resulting value is 1-indexed, so
+ * the first child in the album is at position 1.
+ */
+ public function get_position($child_id) {
+ // Right now we only sort by id ascending, so bake that assumption in here.
+ // @todo fix this when we introduce sort orders.
+ return ORM::factory("item")
+ ->where("parent_id", $this->id)
+ ->where("id <=", $child_id)
+ ->count_all();
+ }
}
diff --git a/themes/default/views/header.html.php b/themes/default/views/header.html.php
index c94527e9..262f6540 100644
--- a/themes/default/views/header.html.php
+++ b/themes/default/views/header.html.php
@@ -12,7 +12,7 @@
<? if ($page_type != "tag"): ?>
<ul id="gBreadcrumbs">
<? foreach ($parents as $parent): ?>
- <li><a href="<?= url::site("albums/{$parent->id}") ?>"><?= $parent->title ?></a></li>
+ <li><a href="<?= url::site("albums/{$parent->id}?show=$item->id") ?>"><?= $parent->title ?></a></li>
<? endforeach ?>
<li class="active"><?= $item->title ?></li>
</ul>