Exemple #1
0
 /**
  * Get node children
  *
  * This function returns the tree branch holdning the designated node
  * and its children
  * <br/>Example:
  * <code>
  * $content = new EfrontContentTree(4);		//Create the content tree for lesson with id 4
  * $content -> getChildren(54);				//Get node's 54 children
  * </code>
  * The function uses RecursiveArrayIterator :: getChildren() to get the branch
  *
  * @param mixed $node Either the node id or an EfrontNode object
  * @return RecursiveArrayIterator The tree branch
  * @since 3.5.0
  * @access public
  * @see RecursiveArrayIterator :: getChildren()
  */
 public function getNodeChildren($node)
 {
     $node instanceof ArrayObject ? $nodeId = $node['id'] : ($nodeId = $node);
     $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($this->tree), RecursiveIteratorIterator::SELF_FIRST));
     //Create iterators for the tree
     $iterator->rewind();
     //Initialize iterator
     while ($iterator->valid() && $iterator->key() != $nodeId) {
         //Advance iterator until we reach the designated node
         $iterator->next();
     }
     if ($iterator->valid()) {
         //If we found the designated node
         return $iterator->getChildren();
     } else {
         throw new EfrontTreeException(_NODEDOESNOTEXIST . ': ' . $nodeId, EfrontTreeException::NODE_NOT_EXISTS);
     }
 }