public function __construct($name, $payload = NULL) { parent::__construct($name, $payload); // if entry_id="4|5|6" was given, we filter them here $parameter = $this->param('entry_id'); if ($parameter) { $this->_entry_id_fn = 'array_intersect'; if (strncasecmp($parameter, 'not ', 4) == 0) { $this->_entry_id_fn = 'array_diff'; $parameter = substr($parameter, 4); } $parameter = trim($parameter, " |\r\n\t"); $this->_entry_id_opts = explode('|', $parameter); } }
/** * Branch length utility method. * */ protected function _find_longest_branch(EE_TreeNode $tree) { $it = new RecursiveIteratorIterator(new ParseNodeIterator(array($tree)), RecursiveIteratorIterator::LEAVES_ONLY); $longest = 0; foreach ($it as $leaf) { $depth = $it->getDepth(); if ($tree->is_root()) { $depth -= 1; } if ($depth > $longest) { $longest = $depth; } } return $longest; }
/** * Branch length utility method. * */ protected function _min_max_branches(EE_TreeNode $tree) { $it = new RecursiveIteratorIterator(new ParseNodeIterator(array($tree)), RecursiveIteratorIterator::LEAVES_ONLY); $shortest = INF; $longest = 0; foreach ($it as $leaf) { $depth = $it->getDepth(); if ($tree->is_root()) { $depth -= 1; } if ($depth < $shortest) { $shortest = $depth; } if ($depth > $longest) { $longest = $depth; } } if (is_infinite($shortest)) { $shortest = 0; } return compact('shortest', 'longest'); }
/** * Add a child node to the current node. * * Notifies the child of its parent and adds the child name to * the child name array. Does not enforce unique names since it * may be desireable to have non-unique named children. It's on * the developer to not rely on the get() method in that case * * @return void */ public function add(EE_TreeNode $child) { if ($child == $this) { throw new RuntimeException('Cannot add tree node to itself.'); } if ($this->_frozen) { throw new RuntimeException('Cannot add child. Tree node is frozen.'); } $this->children[] = $child; $this->children_names[$child->name] = $child; $child->_set_parent($this); }