public function toJsTree(NodeInterface $node, $titleProperty, $currentIdentifier = '', &$string = NULL) { if ($string === NULL) { $string = '<ul>'; } $liClasses = ['jstree-open']; if ($node->isRootNode()) { $liClasses[] = 'root-node'; } $spanClasses = []; if ($currentIdentifier == $node->getIdentifier()) { $spanClasses[] = 'active'; } $liClass = implode(' ', $liClasses); $spanClass = implode(' ', $spanClasses); $title = $node->{$titleProperty}; $id = $node->getIdentifier(); $string .= "\n <li id=\"node-{$id}\" class=\"{$liClass}\"><span class=\"{$spanClass}\">{$title}</span>"; if (count($node->childNodes())) { $string .= "\n <ul>"; foreach ($node->childNodes() as $child) { $this->toJsTree($child, $titleProperty, $currentIdentifier, $string); } $string .= "\n </ul>"; } $string .= "</li>"; return $string . "\n</ul>"; }
/** * @brief Removes a child node * * @return NodeInterface */ public function removeChildNode(NodeInterface $childNode) { $deleteIndex = -1; $idx = 0; foreach ($this->_childNodes as $child) { if ($child->getIdentifier() == $childNode->getIdentifier()) { $deleteIndex = $idx; break; } $idx++; } if ($deleteIndex != -1) { unset($this->_childNodes[$deleteIndex]); $this->_childNodes = array_values($this->_childNodes); } return $this; }