summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-06-04 22:11:08 -0700
committerBharat Mediratta <bharat@menalto.com>2009-06-04 22:11:08 -0700
commit4f0a3fefa035ec351bc881093f49f9bc81941f3d (patch)
treea0a9631d33550b35db767809008ca84e238004f0
parent54927248b0b7b7e71b905c3be129305ba98e0456 (diff)
Fix a bug in Item_Model::get_position() where we incorrectly using the
grandparent id. Oops. This caused navigation from photo back up to album to be broken. Also update Photos_Controller to use the active sort order.. it was still hardcoded to use the id. It's more efficient now, yay. Fixes ticket #340.
-rw-r--r--modules/gallery/controllers/photos.php30
-rw-r--r--modules/gallery/models/item.php2
2 files changed, 11 insertions, 21 deletions
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 2de51bc7..f5be5d59 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -25,32 +25,22 @@ class Photos_Controller extends Items_Controller {
public function _show($photo) {
access::required("view", $photo);
- // We sort by id ascending so for now, find sibling info by doing id based queries.
- $next_item = ORM::factory("item")
- ->viewable()
- ->where("parent_id", $photo->parent_id)
- ->where("id >", $photo->id)
- ->orderby("id", "ASC")
- ->find();
- $previous_item = ORM::factory("item")
- ->viewable()
- ->where("parent_id", $photo->parent_id)
- ->where("id <", $photo->id)
- ->orderby("id", "DESC")
- ->find();
- $position = ORM::factory("item")
- ->viewable()
- ->where("parent_id", $photo->parent_id)
- ->where("id <=", $photo->id)
- ->count_all();
+ $position = $photo->parent()->get_position($photo->id);
+ if ($position > 1) {
+ list ($previous_item, $ignore, $next_item) =
+ $photo->parent()->children(3, $position - 2);
+ } else {
+ $previous_item = null;
+ list ($next_item) = $photo->parent()->children(1, $position);
+ }
$template = new Theme_View("page.html", "photo");
$template->set_global("item", $photo);
$template->set_global("children", array());
$template->set_global("children_count", $photo->children_count());
$template->set_global("parents", $photo->parents());
- $template->set_global("next_item", $next_item->loaded ? $next_item : null);
- $template->set_global("previous_item", $previous_item->loaded ? $previous_item : null);
+ $template->set_global("next_item", $next_item);
+ $template->set_global("previous_item", $previous_item);
$template->set_global("sibling_count", $photo->parent()->children_count());
$template->set_global("position", $position);
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 10bad0b2..7dce9e51 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -380,7 +380,7 @@ class Item_Model extends ORM_MPTT {
public function get_position($child_id) {
$result = Database::instance()->query("
SELECT COUNT(*) AS position FROM {items}
- WHERE parent_id = {$this->parent_id}
+ WHERE parent_id = {$this->id}
AND {$this->sort_column} <= (SELECT {$this->sort_column}
FROM {items} WHERE id = $child_id)
ORDER BY {$this->sort_column} {$this->sort_order}");