| 16 |
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> | |
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> | |
| 17 |
// +----------------------------------------------------------------------+ |
// +----------------------------------------------------------------------+ |
| 18 |
// |
// |
|
// Id: Common.php,v 1.17 2003/01/28 19:18:37 cain Exp |
|
| 19 |
// $Id$ |
// $Id$ |
| 20 |
|
|
| 21 |
require_once('Tree/OptionsDB.php'); |
require_once('Tree/OptionsDB.php'); |
| 67 |
* @access public |
* @access public |
| 68 |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
| 69 |
* @param integer $id ID of the element that the children shall be retreived for |
* @param integer $id ID of the element that the children shall be retreived for |
| 70 |
|
* @param integer how many levels deep into the tree |
| 71 |
* @return mixed an array of all the ids of the children of the element with id=$id, |
* @return mixed an array of all the ids of the children of the element with id=$id, |
| 72 |
* or false if there are no children |
* or false if there are no children |
| 73 |
*/ |
*/ |
| 74 |
function getChildrenIds( $id ) |
function getChildrenIds($id,$levels=1) |
| 75 |
{ |
{ |
| 76 |
if( !($children = $this->getChildren( $id )) ) // returns false if no children exist |
if (!($children = $this->getChildren($id,$levels))) { // returns false if no children exist |
| 77 |
return array(); // return an empty array, if you want to know if there are children, use hasChildren |
return array(); // return an empty array, if you want to know if there are children, use hasChildren |
| 78 |
|
} |
| 79 |
|
|
| 80 |
if( $children && sizeof($children) ) |
if ($children && sizeof($children)) { |
| 81 |
{ |
foreach ($children as $aChild) { |
|
foreach( $children as $aChild ) |
|
| 82 |
$childrenIds[] = $aChild['id']; |
$childrenIds[] = $aChild['id']; |
| 83 |
|
} |
| 84 |
} |
} |
| 85 |
|
|
| 86 |
return $childrenIds; |
return $childrenIds; |
| 96 |
* @return mixed an array of all the children of the element with id=$id, |
* @return mixed an array of all the children of the element with id=$id, |
| 97 |
* or false if there are no children |
* or false if there are no children |
| 98 |
*/ |
*/ |
| 99 |
function getAllChildren( $id ) |
// FIXXXME remove this method and replace it by getChildren($id,0) |
| 100 |
|
function getAllChildren($id) |
| 101 |
{ |
{ |
| 102 |
$retChildren = false; |
$retChildren = false; |
| 103 |
if( $children = $this->hasChildren( $id ) ) |
if ($children = $this->hasChildren($id)) { |
|
{ |
|
| 104 |
$retChildren = $this->_getAllChildren( $id ); |
$retChildren = $this->_getAllChildren( $id ); |
| 105 |
} |
} |
| 106 |
return $retChildren; |
return $retChildren; |
| 117 |
* @return mixed an array of all the ids of the children of the element with id=$id, |
* @return mixed an array of all the ids of the children of the element with id=$id, |
| 118 |
* or false if there are no children |
* or false if there are no children |
| 119 |
*/ |
*/ |
| 120 |
function &_getAllChildren( $id ) |
function &_getAllChildren($id) |
| 121 |
{ |
{ |
| 122 |
$retChildren = array(); |
$retChildren = array(); |
| 123 |
if( $children = $this->getChildren( $id ) ) |
if ($children = $this->getChildren($id)) { |
| 124 |
{ |
foreach ($children as $key=>$aChild) { |
|
foreach( $children as $key=>$aChild ) |
|
|
{ |
|
| 125 |
$retChildren[] = &$children[$key]; |
$retChildren[] = &$children[$key]; |
| 126 |
$retChildren = array_merge($retChildren,$this->_getAllChildren( $aChild['id'] )); |
$retChildren = array_merge($retChildren,$this->_getAllChildren( $aChild['id'] )); |
| 127 |
} |
} |
| 290 |
* @access public |
* @access public |
| 291 |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
* @author Wolfram Kriesing <wolfram@kriesing.de> |
| 292 |
* @param mixed $id the id of the node to get the path for |
* @param mixed $id the id of the node to get the path for |
| 293 |
|
* @param integer If offset is positive, the sequence will |
| 294 |
|
* start at that offset in the array . If |
| 295 |
|
* offset is negative, the sequence will start that far from the end of the array . |
| 296 |
|
* @param integer If length is given and is positive, then |
| 297 |
|
* the sequence will have that many elements in it. If |
| 298 |
|
* length is given and is negative then the |
| 299 |
|
* sequence will stop that many elements from the end of the |
| 300 |
|
* array. If it is omitted, then the sequence will have everything |
| 301 |
|
* from offset up until the end of the array. |
| 302 |
* @return array this array contains all elements from the root to the element given by the id |
* @return array this array contains all elements from the root to the element given by the id |
| 303 |
* |
* |
| 304 |
*/ |
*/ |
| 305 |
function getPathAsString( $id , $seperator='/' ) |
function getPathAsString( $id , $seperator='/' , $offset=0 , $length=0 ) |
| 306 |
{ |
{ |
| 307 |
$path = $this->getPath($id); |
$path = $this->getPath($id); |
| 308 |
foreach( $path as $aNode ) |
foreach ($path as $aNode) { |
| 309 |
$pathArray[] = $aNode['name']; |
$pathArray[] = $aNode['name']; |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
if ($offset) { |
| 313 |
|
if ($length) { |
| 314 |
|
$pathArray = array_slice($pathArray,$offset,$length); |
| 315 |
|
} else { |
| 316 |
|
$pathArray = array_slice($pathArray,$offset); |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| 320 |
$pathString = ''; |
$pathString = ''; |
| 321 |
if( sizeof($pathArray) ) |
if( sizeof($pathArray) ) |
| 381 |
return $this->_throwError( 'not implemented, at least not overwritten the abstract declaration' , __LINE__ ); |
return $this->_throwError( 'not implemented, at least not overwritten the abstract declaration' , __LINE__ ); |
| 382 |
} // end of function |
} // end of function |
| 383 |
|
|
| 384 |
|
/** |
| 385 |
|
* return the maximum depth of the tree |
| 386 |
|
* |
| 387 |
|
* @version 2003/02/25 |
| 388 |
|
* @access public |
| 389 |
|
* @author Wolfram Kriesing <wolfram@kriesing.de> |
| 390 |
|
* @return int the depth of the tree |
| 391 |
|
*/ |
| 392 |
|
function getDepth() |
| 393 |
|
{ |
| 394 |
|
return $this->_treeDepth; |
| 395 |
|
} // end of function |
| 396 |
|
|
| 397 |
|
|
| 398 |
|
|