summaryrefslogtreecommitdiff
path: root/core/libraries/ORM_MPTT.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-07 06:46:38 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-07 06:46:38 +0000
commit936decb437cbb19799dcae255af1d4425a850ae3 (patch)
tree6edc9bd258d255f89b0d98d389feae449fcc147e /core/libraries/ORM_MPTT.php
parent6a1ef44c8842d007dd59574cc76ba767519d124f (diff)
Add children_count() to ORM_MPTT
Diffstat (limited to 'core/libraries/ORM_MPTT.php')
-rw-r--r--core/libraries/ORM_MPTT.php30
1 files changed, 28 insertions, 2 deletions
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index 83190d4a..f79ea910 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -36,6 +36,7 @@ class ORM_MPTT_Core extends ORM {
private $parent = null;
private $parents = null;
private $children = null;
+ private $children_count = null;
function __construct($id=null) {
parent::__construct($id);
@@ -102,22 +103,47 @@ class ORM_MPTT_Core extends ORM {
/**
* 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() {
+ function children($limit=NULL, $offset=0) {
if (!isset($this->children)) {
$this->children =
$this->where("parent_id", $this->id)
->orderby("id", "ASC")
- ->find_all();
+ ->find_all($limit, $offset);
}
return $this->children;
}
+ /**
+ * 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_count() {
+ if (!isset($this->children_count)) {
+ $this->children_count =
+ $this->where("parent_id", $this->id)
+ ->orderby("id", "ASC")
+ ->count_all();
+ }
+ return $this->children_count;
+ }
+
+ /**
+ * @see ORM::reload
+ */
function reload() {
$this->parent = null;
$this->parents = null;
$this->children = null;
+ $this->children_count = null;
return parent::reload();
}