protected function init() { if (!$this->ready) { $this->enqueue($this->root->getChildren()); // $this->enqueue([$this->root]); //TODO tu je zrejme chyba - otazne - mal by iterator iterovat aj cez root? $this->ready = TRUE; } }
protected function copyNodesRelationsAndReplace(INode $source, INode $destination) { foreach ($source->getChildren() as $index => $child) { /* @var $child INode */ $destination->addChild($child, $index); } $parent = $source->getParent(); if ($parent instanceof INode && $parent !== $source) { $parent->addChild($destination, $parent->getChildIndex($source)); } }
/** * Appends a child into the children array. * If an index is specified, it is possible to override an existing child node with the same index! * * This node becomes the direct parent of the inserted child node. * * Note: adding to NULL index is only possible by adding to '' (empty string) index. * * * @param INode $node * @param scalar $index = NULL index * @return NodeBase the new/inserted node */ public function addChild(INode $node, $index = NULL) { $node->setParent($this); if ($index === NULL) { $this->children[] = $node; } else { $this->children[$index] = $node; } return $node; }
/** * Replaces a node with a new one. Copies all its relationships and resets its child index if it has a parent. * @internal * * * @param INode $source * @param mixed $data data for the node * @param string $hierarchy the hierarchy member string value * @return INode */ protected function replaceNode(INode $source, $data, $hierarchy) { /* @var $destination INode */ $destination = $this->createNode($data); foreach ($source->getChildren() as $index => $child) { $destination->addChild($child, $index); } $parent = $source->getParent(); if ($parent instanceof INode && $parent !== $source) { $parent->removeChild($parent->getChildIndex($source)); $parent->addChild($destination, $this->getChildIndex($hierarchy, $destination)); } return $destination; }
protected static function bf(INode $node) { $list = $node->getChildren(); foreach ($list as $child) { $list = array_merge($list, self::bf($child)); } return $list; }