Exemple #1
0
 /**
  * Returns the level of this node in the tree
  *
  * @return int Tree level (1 = top level)
  */
 public function getLevel()
 {
     if ($this->parent === null) {
         return 0;
     }
     return $this->parent->getLevel() + 1;
 }
Exemple #2
0
 /**
  * Constructor.
  *
  * @param   Node    $parent     (optional) parent node
  */
 public function __construct($parent = null)
 {
     $this->parent = $parent;
     if (null !== $parent) {
         $this->level = 1 + $parent->getLevel();
     }
 }
 public function getLevel()
 {
     if ($this->parent) {
         return $this->parent->getLevel() + 1;
     } else {
         return 0;
     }
 }
Exemple #4
0
 /**
  * Returns a value indicating if this node is a child of the passed node.
  * This just checks the levels of the nodes. If this node is at a greater
  * level than the passed node if is a child of it.
  *
  * @param Node $node
  * @return bool TRUE if the node is a child of the passed node, FALSE if not
  */
 public function isChildOf($node)
 {
     return $this->getLevel() > $node->getLevel();
 }