/** * Removes a node * @param \ride\library\cms\node\Node $node Node to delete * @param boolean $recursive Flag to see if child nodes should be deleted * @return */ public function removeNode(Node $node, $recursive = true) { $siteId = $node->getRootNodeId(); $revision = $node->getRevision(); $parent = $node->getParent(); $path = $node->getPath(); $orderIndex = $node->getOrderIndex(); $baseOrderIndex = $orderIndex - 1; $changedNodes = array(); // remove children or move the children the the parent's path $numChildren = 0; $children = $this->getNodesByPath($siteId, $revision, $path); foreach ($children as $child) { if ($recursive) { $this->removeNode($child, true); continue; } $childParent = $child->getParent(); if ($childParent === $path) { $child->setOrderIndex($baseOrderIndex + $child->getOrderIndex()); $numChildren++; } $child->setParent(str_replace($path, $parent, $childParent)); $changedNodes[] = $child; } if (!$recursive) { // fix order index for nodes after the removed node $siblings = $this->getChildren($node->getRootNodeId(), $node->getRevision(), $parent, 0); foreach ($siblings as $sibling) { $siblingOrderIndex = $sibling->getOrderIndex(); if ($siblingOrderIndex <= $orderIndex) { continue; } $sibling->setOrderIndex($siblingOrderIndex + $numChildren - 1); $changedNodes[] = $sibling; } } // save and remove the necessairy nodes foreach ($changedNodes as $changedNode) { $this->setNode($changedNode); } $this->deleteNode($node); unset($this->nodes[$siteId][$revision][$node->getId()]); }
/** * Gets the number of children levels for the provided node * @param \ride\library\cms\node\Node $node * @return integer */ public function getChildrenLevels(Node $node) { $nodeLevel = $node->getLevel(); $path = $node->getPath(); $levels = 0; $nodes = $this->getNodesByPath($node->getRootNodeId(), $node->getRevision(), $path); foreach ($nodes as $node) { $parent = $node->getParent(); $level = strlen($parent) - strlen(str_replace(Node::PATH_SEPARATOR, '', $parent)) + 1; $levels = max($levels, $level); } return $levels - $nodeLevel; }
/** * Sets the parent node * @param Node|null Parent node if set, null otherwise */ public function setParentNode(Node $node = null) { $this->parentNode = $node; $this->parentPath = $node->getPath(); }
/** * Set or toggle the collapse status of a node * @param \ride\library\cms\node\Node $node * @param boolean $isCollapsed * @return boolean Collapse state of the provided node */ public function collapseNode(Node $node, $isCollapsed = null) { $collapsedNodes = $this->getCollapsedNodes(); $path = $node->getPath() . '[' . $node->getRevision() . ']'; if ($isCollapsed !== null) { if ($isCollapsed && !isset($collapsedNodes[$path])) { $collapsedNodes[$path] = true; } elseif (!$isCollapsed && isset($collapsedNodes[$path])) { unset($collapsedNodes[$path]); } } elseif (isset($collapsedNodes[$path])) { unset($collapsedNodes[$path]); $isCollapsed = false; } else { $collapsedNodes[$path] = true; $isCollapsed = true; } $this->request->getSession()->set(self::SESSION_COLLAPSED_NODES, $collapsedNodes); $user = $this->securityManager->getUser(); if ($user) { $user->setPreference(self::SESSION_COLLAPSED_NODES, $collapsedNodes); $this->securityManager->getSecurityModel()->saveUser($user); } return $isCollapsed; }