diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/movies.php | 9 | ||||
-rw-r--r-- | modules/gallery/controllers/photos.php | 9 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 34 |
3 files changed, 28 insertions, 24 deletions
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 01a9fc8b..6200e8b4 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -25,13 +25,14 @@ class Movies_Controller extends Items_Controller { public function _show($movie) { access::required("view", $movie); - $position = $movie->parent()->get_position($movie); + $where = array("type != " => "album"); + $position = $movie->parent()->get_position($movie, $where); if ($position > 1) { list ($previous_item, $ignore, $next_item) = - $movie->parent()->children(3, $position - 2); + $movie->parent()->children(3, $position - 2, $where); } else { $previous_item = null; - list ($next_item) = $movie->parent()->viewable()->children(1, $position); + list ($next_item) = $movie->parent()->viewable()->children(1, $position, $where); } $template = new Theme_View("page.html", "movie"); @@ -41,7 +42,7 @@ class Movies_Controller extends Items_Controller { $template->set_global("parents", $movie->parents()); $template->set_global("next_item", $next_item); $template->set_global("previous_item", $previous_item); - $template->set_global("sibling_count", $movie->parent()->viewable()->children_count()); + $template->set_global("sibling_count", $movie->parent()->viewable()->children_count($where)); $template->set_global("position", $position); $template->content = new View("movie.html"); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 54cd63c6..b9adfd90 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -25,13 +25,14 @@ class Photos_Controller extends Items_Controller { public function _show($photo) { access::required("view", $photo); - $position = $photo->parent()->get_position($photo); + $where = array("type != " => "album"); + $position = $photo->parent()->get_position($photo, $where); if ($position > 1) { list ($previous_item, $ignore, $next_item) = - $photo->parent()->children(3, $position - 2); + $photo->parent()->children(3, $position - 2, $where); } else { $previous_item = null; - list ($next_item) = $photo->parent()->viewable()->children(1, $position); + list ($next_item) = $photo->parent()->viewable()->children(1, $position, $where); } $template = new Theme_View("page.html", "photo"); @@ -41,7 +42,7 @@ class Photos_Controller extends Items_Controller { $template->set_global("parents", $photo->parents()); $template->set_global("next_item", $next_item); $template->set_global("previous_item", $previous_item); - $template->set_global("sibling_count", $photo->parent()->viewable()->children_count()); + $template->set_global("sibling_count", $photo->parent()->viewable()->children_count($where)); $template->set_global("position", $position); $template->content = new View("photo.html"); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index fc0f0193..9735ed62 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -422,7 +422,7 @@ class Item_Model extends ORM_MPTT { * 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) { + public function get_position($child, $where=array()) { if ($this->sort_order == "DESC") { $comp = ">"; } else { @@ -435,18 +435,20 @@ class Item_Model extends ORM_MPTT { $count = $db->from("items") ->where("parent_id", $this->id) ->where($this->sort_column, NULL) + ->where($where) ->count_records(); if (empty($count)) { // There are no NULLs in the sort column, so we can just use it directly. - $position = $db->query(" - SELECT COUNT(*) AS position FROM {items} - WHERE `parent_id` = {$this->id} - AND `{$this->sort_column}` $comp (SELECT `{$this->sort_column}` - FROM {items} WHERE `id` = $child->id)") - ->current()->position; - - // We stopped short of our target value in the sort (notice that we're using a < comparator + $sort_column = $this->sort_column; + + $position = $db->from("items") + ->where("parent_id", $this->id) + ->where("$sort_column < ", $child->$sort_column) + ->where($where) + ->count_records(); + + // We stopped short of our target value in the sort (notice that we're using a < comparator // above) because it's possible that we have duplicate values in the sort column. An // equality check would just arbitrarily pick one of those multiple possible equivalent // columns, which would mean that if you choose a sort order that has duplicates, it'd pick @@ -454,13 +456,12 @@ class Item_Model extends ORM_MPTT { // // Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to // our base value. - $result = $db->query(" - SELECT id FROM {items} - WHERE `parent_id` = {$this->id} - AND `{$this->sort_column}` = (SELECT `{$this->sort_column}` - FROM {items} WHERE `id` = $child->id) - ORDER BY `id` ASC"); - foreach ($result as $row) { + foreach ($db->from("items") + ->where("parent_id", $this->id) + ->where($sort_column, $child->$sort_column) + ->where($where) + ->orderby(array("id" => "ASC")) + ->get() as $row) { $position++; if ($row->id == $child->id) { break; @@ -484,6 +485,7 @@ class Item_Model extends ORM_MPTT { foreach ($db->select("id") ->from("items") ->where("parent_id", $this->id) + ->where($where) ->orderby($orderby) ->get() as $row) { $position++; |