cvs: pear /Tree Common.php

From: Date: Mon, 30 Sep 2002 14:51:08 +0000
Subject: cvs: pear /Tree Common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-6775@lists.php.net to get a copy of this message
cain Mon Sep 30 10:51:08 2002 EDT Modified files: /pear/Tree Common.php Log: - added getChildrens :-) Index: pear/Tree/Common.php diff -u pear/Tree/Common.php:1.11 pear/Tree/Common.php:1.12 --- pear/Tree/Common.php:1.11 Fri Aug 23 13:18:57 2002 +++ pear/Tree/Common.php Mon Sep 30 10:51:07 2002 @@ -16,7 +16,7 @@ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.11 2002/08/23 17:18:57 cain Exp $ +// $Id: Common.php,v 1.12 2002/09/30 14:51:07 cain Exp $ require_once('Tree/OptionsDB.php'); @@ -85,6 +85,72 @@ } /** + * gets all the children and grand children + * i know there is no such word as 'childrens' but it makes sense here :-) + * + * @version 2002/09/30 + * @access public + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param integer $id ID of the element that the children shall be retreived for + * @return mixed an array of all the children of the element with id=$id, + * or false if there are no children + */ + function getChildrens( $id ) + { + $retChildrens = false; + if( $childrens = $this->hasChildren( $id ) ) + { + $retChildrens = $this->_getChildrens( $id ); + } + return $retChildrens; + } + + /** + * this method gets all the children recursively + * + * @see getChildrens() + * @version 2002/09/30 + * @access public + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param integer $id ID of the element that the children shall be retreived for + * @return mixed an array of all the ids of the children of the element with id=$id, + * or false if there are no children + */ + function &_getChildrens( $id ) + { + $retChildrens = array(); + if( $children = $this->getChildren( $id ) ) + { + foreach( $children as $key=>$aChild ) + { + $retChildrens[] = &$children[$key]; + //$retChildrens = array_merge($retChildrens,$this->_getChildrens( $aChild['id'] )); + } + } + return $retChildrens; + } + + /** + * gets all the children-ids and grand children-ids + * + * @version 2002/09/30 + * @access public + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param integer $id ID of the element that the children shall be retreived for + * @return mixed an array of all the ids of the children of the element with id=$id, + * or false if there are no children + */ + function getChildrensIds( $id ) + { + if( $childrens = $this->getChildrens($id) ) + { + $childrensIds = array(); + foreach( $childrens as $aNode ) + $childrensIds[] = $aNode['id']; + } + return $childrensIds; + } + /** * get the id of the parent for the given element * * @version 2002/01/18 @@ -385,4 +451,4 @@ } } -?> \ No newline at end of file +?>

« previous php.pear.cvs (#6775) next »