Ejemplo n.º 1
0
 /**
  * Add child nodes
  *
  * @param array $children
  * @param string $path
  * @param Node $parentNode
  * @param bool $withChildren
  * @param int $level
  * @return void
  */
 protected function _addChildNodes($children, $path, $parentNode, $withChildren = false, $level = 0)
 {
     if (isset($children[$path])) {
         foreach ($children[$path] as $child) {
             $nodeId = isset($child[$this->_idField]) ? $child[$this->_idField] : false;
             if ($parentNode && $nodeId && ($node = $parentNode->getChildren()->searchById($nodeId))) {
                 $node->addData($child);
             } else {
                 $node = new Node($child, $this->_idField, $this, $parentNode);
                 $node->setLevel($node->getData($this->_levelField));
                 $node->setPathId($node->getData($this->_pathField));
                 $this->addNode($node, $parentNode);
             }
             if ($withChildren) {
                 $this->_loaded = false;
                 $node->loadChildren(1);
                 $this->_loaded = false;
             }
             if ($path) {
                 $childrenPath = explode('/', $path);
             } else {
                 $childrenPath = array();
             }
             $childrenPath[] = $node->getId();
             $childrenPath = implode('/', $childrenPath);
             $this->_addChildNodes($children, $childrenPath, $node, $withChildren, $level + 1);
         }
     }
 }