From 7c2ed027ff8385ba1618fcde7bcff95803708843 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:48:07 +0200 Subject: [PATCH] Item: new method count_descendants --- object/Item.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/object/Item.php b/object/Item.php index 8825678941..a9115ee08e 100644 --- a/object/Item.php +++ b/object/Item.php @@ -65,7 +65,7 @@ class Item extends BaseObject { $osparkle = ''; $lastcollapsed = false; $firstcollapsed = false; - $total_children += count_descendants($item); + $total_children = $this->count_descendants(); $show_comment_box = ((($this->is_page_writeable()) && ($this->is_writeable())) ? true : false); $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) @@ -523,5 +523,19 @@ class Item extends BaseObject { private function is_writeable() { return $this->writeable; } + + /** + * Count the total of our descendants + */ + private function count_descendants() { + $children = $this->get_children(); + $total = count($children); + if($total > 0) { + foreach($children as $child) { + $total += $child->count_descendants(); + } + } + return $total; + } } ?> -- 2.39.5