/[cvs]/nfo/php/libs/net.php.pear/Tree/Common.php
ViewVC logotype

Diff of /nfo/php/libs/net.php.pear/Tree/Common.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Thu Feb 27 16:49:56 2003 UTC revision 1.2 by joko, Wed Jul 7 02:49:19 2004 UTC
# Line 16  Line 16 
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');
# Line 68  class Tree_Common extends Tree_OptionsDB Line 67  class Tree_Common extends Tree_OptionsDB
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;
# Line 95  class Tree_Common extends Tree_OptionsDB Line 96  class Tree_Common extends Tree_OptionsDB
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;
# Line 116  class Tree_Common extends Tree_OptionsDB Line 117  class Tree_Common extends Tree_OptionsDB
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              }              }
# Line 291  class Tree_Common extends Tree_OptionsDB Line 290  class Tree_Common extends Tree_OptionsDB
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) )
# Line 364  class Tree_Common extends Tree_OptionsDB Line 381  class Tree_Common extends Tree_OptionsDB
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    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed