/** * Make a sitetree model * * @param \Cmsable\Routing\TreeScope\TreeScope $scope * @return \Cmsable\Model\SiteTreeModelInterface **/ protected function makeModel(TreeScope $scope) { $model = clone $this->treeModelPrototype; $model->setRootId($scope->getModelRootId()); $model->setPathPrefix($scope->getPathPrefix()); return $model; }
public function getCurrentScope() { if (!$this->currentScope) { $scope = new TreeScope(); $scope->setModelRootId(Config::get($this->configKey)); return $scope; } return $this->currentScope; }
public function getFirstMatchingNode(TreeScope $scope, $originalPath) { $pathPrefix = $this->cleanPathPrefix($scope->getPathPrefix()); $path = $this->getTranslatedPath($originalPath, $pathPrefix); $treeModel = $this->treeManager->get($scope); // If $path matches a node path return it if ($node = $treeModel->pageByPath($path)) { return $node; } else { $requestSegments = explode('/', $path); $pathStack = array(); $i = 0; foreach ($requestSegments as $segment) { $pathStack[] = $segment; $currentPath = implode('/', $pathStack); if ($this->isPathPrefix($segment, $pathPrefix, $i)) { continue; } $pathExists = $treeModel->pathExists($currentPath); if (!$pathExists && $i == 0) { return; } // if the first segment if (!$treeModel->pathExists($currentPath)) { array_pop($pathStack); $parentPath = implode('/', $pathStack); return $treeModel->pageByPath($parentPath); } $i++; } } }
/** * Convert a root node to a scope * * @param \Cmsable\Model\SiteTreeNodeInterface $node * @return \Cmsable\Routing\TreeScope\TreeScope **/ public function node2Scope(SiteTreeNodeInterface $node) { $scope = new TreeScope(); $urlSegment = trim($node->getUrlSegment(), '/'); $name = $urlSegment ? $urlSegment : TreeScope::DEFAULT_NAME; $scope->setPathPrefix($node->getUrlSegment()); $scope->setName($name); $scope->setTitle($node->getMenuTitle()); $scope->setModelRootId($node->{$this->treeModel->rootCol()}); return $scope; }