Example #1
0
 public function root(Node $node)
 {
     while ($parent = $node->getParent()) {
         $node = $parent;
         if ($parent->isRoot()) {
             return $parent;
         }
     }
 }
Example #2
0
 public function indexOf(Node $node)
 {
     $count = $this->count();
     for ($i = 0; $i < $count; $i++) {
         if ($node->getId() == $this->_children[$i]->getId()) {
             return $i;
         }
     }
     throw new OutOfBoundsException('Node ' . $node->getId() . ' not found');
 }
Example #3
0
 public function flatify(Node $node, &$flatArray = NULL)
 {
     if ($flatArray === NULL) {
         $flatArray = [];
     }
     $flatArray[] = $node;
     if (!$node->hasChildren()) {
         return $flatArray;
     }
     foreach ($node->getChildren() as $child) {
         $this->flatify($child, $flatArray);
     }
     return $flatArray;
 }
Example #4
0
 /**
  * Set the parent node of this node (Only in memory)
  * 
  * @param self $parent
  * @return self
  */
 public function setParent(Node $parent)
 {
     $this->relations['parent'] = $parent;
     $parent->addChild($this);
     return $this;
 }
 protected function getLastChildPosition(Node $parent)
 {
     $parentIdName = $this->getParentIdName();
     $query = $this->newQuery();
     $pos = $query->where($parentIdName, $parent->getId())->max($this->getPositionName());
     if (is_numeric($pos) && $pos) {
         return (int) $pos + 1;
     }
     return 1;
 }