/** * Internal helper function to get node with children. * * @param \BaseObject $instance * @return array */ protected function _objectToJson(\BaseObject $instance) { $nodes = $this->lazy ? $instance->getChildren($this->query) : $instance->getDescendants($this->query); if ($nodes instanceof \PropelCollection) { $nodes = $nodes->getArrayCopy(); } array_unshift($nodes, $instance); $level = array(); foreach ($nodes as $node) { $p = call_user_func($this->nodeCallback, $node, $this, $node->getTreeLevel()); $level[$node->getLevel()] =& $p; if (isset($level[$node->getLevel() - 1])) { $level[$node->getLevel() - 1]['children'][] =& $p; } unset($p); } return $level[$instance->getLevel()]; }
/** * Deletes given node direct children. * * @param BaseObject $node */ public function deleteChildren(BaseObject $node) { // array_reverse() call is necessary for root node properties to be correctly updated foreach (array_reverse($node->getChildren()) as $child) { $child->delete(); } }