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)); } }
/** * 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; }