Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/base/tree.php

Documentation is available at tree.php

  1. <?php
  2. /**
  3.  * @version        $Id: tree.php 6613 2007-02-13 01:36:19Z chrisdavenport $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Base
  6.  * @copyright    Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
  7.  * @license        GNU/GPL, see LICENSE.php
  8.  *  Joomla! is free software. This version may have been modified pursuant to the
  9.  *  GNU General Public License, and as distributed it includes or is derivative
  10.  *  of works licensed under the GNU General Public License or other free or open
  11.  *  source software licenses. See COPYRIGHT.php for copyright notices and
  12.  *  details.
  13.  */
  14.  
  15. // Check to ensure this file is within the rest of the framework
  16. defined('JPATH_BASE'or die();
  17.  
  18. /**
  19.  * Tree Class.
  20.  *
  21.  * @author        Louis Landry <[email protected]>
  22.  * @package     Joomla.Framework
  23.  * @subpackage    Base
  24.  * @since        1.5
  25.  */
  26. class JTree extends JObject
  27. {
  28.     /**
  29.      * Root node
  30.      */
  31.     var $_root = null;
  32.  
  33.     /**
  34.      * Current working node
  35.      */
  36.     var $_current = null;
  37.  
  38.     function __construct()
  39.     {
  40.         $this->_root = new JNode('ROOT');
  41.         $this->_current = $this->_root;
  42.     }
  43.  
  44.     function addChild(&$node$setCurrent false)
  45.     {
  46.         $this->_current->addChild($node);
  47.         if ($setCurrent{
  48.             $this->_current =$node;
  49.         }
  50.     }
  51.  
  52.     function getParent()
  53.     {
  54.         $this->_current =$this->_current->getParent();
  55.     }
  56.  
  57.     function reset()
  58.     {
  59.         $this->_current =$this->_root;
  60.     }
  61. }
  62.  
  63. /**
  64.  * Tree Node Class.
  65.  *
  66.  * @author        Louis Landry <[email protected]>
  67.  * @package     Joomla.Framework
  68.  * @subpackage    Base
  69.  * @since        1.5
  70.  */
  71. class JNode extends JObject
  72. {
  73.     /**
  74.      * Parent node
  75.      */
  76.     var $_parent = null;
  77.  
  78.     /**
  79.      * Array of Children
  80.      */
  81.     var $_children = array();
  82.  
  83.     function __construct()
  84.     {
  85.         return true;
  86.     }
  87.  
  88.     function addChild&$node )
  89.     {
  90.         $node->setParent($this);
  91.         $this->_children[$node;
  92.     }
  93.  
  94.     function &getParent()
  95.     {
  96.         return $this->_parent;
  97.     }
  98.  
  99.     function setParent&$node )
  100.     {
  101.         $this->_parent = $node;
  102.     }
  103.  
  104.     function hasChildren()
  105.     {
  106.         return count($this->_children);
  107.     }
  108.  
  109.     function &getChildren()
  110.     {
  111.         return $this->_children;
  112.     }
  113. }
  114. ?>

Documentation generated on Mon, 05 Mar 2007 21:29:44 +0000 by phpDocumentor 1.3.1