diff options
-rw-r--r-- | core/controllers/albums.php | 3 | ||||
-rw-r--r-- | core/libraries/ORM_MPTT.php | 11 | ||||
-rw-r--r-- | core/models/item.php | 25 |
3 files changed, 34 insertions, 5 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index 2a55ecac..270b2184 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -53,8 +53,7 @@ class Albums_Controller extends Items_Controller { $template = new Theme_View("page.html", "album"); $template->set_global("page_size", $page_size); $template->set_global("item", $album); - $template->set_global("children", $album->viewable()->children($page_size, $offset, - array($album->sort_column => $album->sort_order))); + $template->set_global("children", $album->viewable()->children($page_size, $offset)); $template->set_global("children_count", $children_count); $template->set_global("parents", $album->parents()); $template->content = new View("album.html"); diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php index 6b493e88..f59aa084 100644 --- a/core/libraries/ORM_MPTT.php +++ b/core/libraries/ORM_MPTT.php @@ -140,6 +140,7 @@ class ORM_MPTT_Core extends ORM { * @chainable * @param integer SQL limit * @param integer SQL offset + * @param array orderby * @return array ORM */ function children($limit=null, $offset=0, $orderby=null) { @@ -170,17 +171,21 @@ class ORM_MPTT_Core extends ORM { * @param integer SQL limit * @param integer SQL offset * @param string type to return + * @param array orderby * @return object ORM_Iterator */ - function descendants($limit=null, $offset=0, $type=null) { + function descendants($limit=null, $offset=0, $type=null, $orderby=null) { $this->where("left >", $this->left) ->where("right <=", $this->right); if ($type) { $this->where("type", $type); } - // @todo: make the order column data driven - $this->orderby("id", "ASC"); + if (empty($orderby)) { + $this->orderby("id", "ASC"); + } else { + $this->orderby($orderby); + } return $this->find_all($limit, $offset); } diff --git a/core/models/item.php b/core/models/item.php index 9f9134fa..bab83aca 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -353,4 +353,29 @@ class Item_Model extends ORM_MPTT { url::abs_file("lib/flowplayer-3.0.5.swf") . "'); </script>"; } + + /** + * Return all of the children of this node, ordered by id. + * + * @chainable + * @param integer SQL limit + * @param integer SQL offset + * @return array ORM + */ + function children($limit=null, $offset=0) { + return parent::children($limit, $offset, array($this->sort_column => $this->sort_order)); + } + + /** + * Return all of the children of the specified type, ordered by id. + * + * @param integer SQL limit + * @param integer SQL offset + * @param string type to return + * @return object ORM_Iterator + */ + function descendants($limit=null, $offset=0, $type=null) { + return parent::descendants($limit, $offset, $type, + array($this->sort_column => $this->sort_order)); + } } |