/** * Constructs a new template view * @param \ride\library\template\Template $template Instance of the * template to render * @return null */ public function __construct(Node $node, Theme $theme, $locale) { $template = new GenericThemedTemplate(); $template->setResource('cms/frontend/index'); $template->setResourceId($node->getId()); $template->setTheme($theme->getName()); $template->set('app', array('cms' => array('node' => $node, 'site' => $node->getRootNodeId()), 'locale' => $locale)); parent::__construct($template); $this->cache = null; $this->cacheItem = null; $this->cachedViews = null; $this->contentView = null; }
/** * Gets a site tree for the provided node * @param \ride\library\cms\node\Node $node Selected node of the tree * @param string $locale Locale for the tree * @return TreeNode Tree Node for the site of the provided node */ public function getTree(Node $node, $locale) { $this->locale = $locale; $this->node = $node; $this->nodeId = $node->getId(); if ($this->nodeId) { $this->rootNodeId = $node->getRootNodeId(); } else { $parentNode = $node->getParentNode(); if ($parentNode) { $this->rootNodeId = $parentNode->getRootNodeId(); } else { return; } } $site = $this->cms->getNode($this->rootNodeId, $node->getRevision(), $this->rootNodeId, null, true); $onlyCurrentLocale = $site->isLocalizationMethodUnique(); return $this->getTreeNode($site, $onlyCurrentLocale); }
/** * 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 file for the node * @param \ride\library\cms\node\Node $node * @return \ride\library\system\file\File */ protected function getNodeFile(Node $node) { $rootNodeId = $node->getRootNodeId(); $revision = $node->getRevision(); $nodeId = $node->getId(); return $this->path->getChild($rootNodeId . '/' . $revision . '/' . $nodeId . '.ini'); }
/** * 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; }
/** * Gets the collapsed nodes for the provided node * @param \ride\library\cms\node\Node $node * @return array Array with the collapsed node id as key and true as value */ protected function getCollapsedNodes(Node $node) { $site = $node->getRootNodeId(); $revision = '[' . $node->getRevision() . ']'; $nodes = array(); $collapsedNodes = $this->cms->getCollapsedNodes(); foreach ($collapsedNodes as $node => $flag) { if (strpos($node, $site) !== 0 || strpos($node, $revision) === false) { continue; } $node = str_replace($revision, '', $node); $tokens = explode(Node::PATH_SEPARATOR, $node); $nodes[array_pop($tokens)] = true; } return $nodes; }
/** * Gets a list of the available nodes * @param \ride\library\cms\node\Node $node Root node for the list * @param string $locale Code of the locale * @param boolean $includeRootNode Flag to see if the root node should be * included in the result * @param boolean $includeEmpty Flag to see if a empty value should be * included in the result * @param boolean $onlyFrontendNodes Flag to filter on frontend nodes * @return array Array with the node id as key and a string as value */ public function getNodeList(Node $node, $locale, $includeRootNode = false, $includeEmpty = true, $onlyFrontendNodes = true) { $rootNode = $this->nodeModel->getNode($node->getRootNodeId(), $node->getRevision(), $node->getId(), null, true); $options = $this->nodeModel->getListFromNodes(array($rootNode), $locale, $onlyFrontendNodes); if ($includeRootNode) { $options = array($rootNode->getId() => '/' . $rootNode->getName($locale)) + $options; } if ($includeEmpty) { $options = array('' => '---') + $options; } return $options; }