/** * Returns an Url object for node and language * @param \Cx\Core\ContentManager\Model\Entity\Node $node Node to get the Url of * @param int $lang (optional) Language to use, default is FRONTENT_LANG_ID * @param array $parameters (optional) HTTP GET parameters to append * @param string $protocol (optional) The protocol to use * @return \Cx\Core\Routing\Url Url object for the supplied module, cmd and lang */ public static function fromNode($node, $lang = '', $parameters = array(), $protocol = '') { if ($lang == '') { $lang = FRONTEND_LANG_ID; } $page = $node->getPage($lang); return static::fromPage($page, $parameters, $protocol); }
/** * Returns the array representation of a fallback page * @param \Cx\Core\ContentManager\Model\Entity\Node $node Node to get the page of * @param string $lang Language code to get the fallback of * @return array Array representing a fallback page */ private function getFallbackPageArray($node, $lang) { $page = null; foreach ($node->getPages() as $page) { if ($page->getLang() == \FWLanguage::getLanguageIdByCode($this->fallbacks[$lang])) { break; } } if (!$page) { throw new \Cx\Core\ContentManager\Model\Entity\NodeException('Node (id ' . $node->getId() . ') has no pages.'); } // Access Permissions $pg = \Env::get('pageguard'); $accessData = array(); $accessData['frontend'] = array('groups' => $pg->getGroups(true), 'assignedGroups' => $pg->getAssignedGroupIds($page, true)); $accessData['backend'] = array('groups' => $pg->getGroups(false), 'assignedGroups' => $pg->getAssignedGroupIds($page, false)); $pageArray = array('id' => 0, 'lang' => $lang, 'node' => $node->getId(), 'type' => $this->fallbacks[$lang] ? 'fallback' : 'content', 'name' => $page->getTitle(), 'title' => $page->getContentTitle(), 'metatitle' => $page->getMetatitle(), 'metadesc' => $page->getMetadesc(), 'metakeys' => $page->getMetakeys(), 'metarobots' => $page->getMetarobots(), 'frontend_protection' => $page->isFrontendProtected(), 'backend_protection' => $page->isBackendProtected(), 'accessData' => $accessData, 'slug' => $page->getSlug(), 'sourceMode' => false, 'sourceMode' => $page->getSourceMode()); return $pageArray; }
/** * Tries to recover a branch - assuming that level and left of $rootNode are correct! * @param \Cx\Core\ContentManager\Model\Entity\Node $rootNode Node to start with */ private function recoverBranch($rootNode, &$left = null, $level = null) { if ($left == null) { $left = $rootNode->getLft(); } if ($level == null) { $level = $rootNode->getLvl(); } // The order in which the children are returned by $rootnode->getChildren() is wrong. // Therefore we'll have to manually put the children in the right order. // Tote that $children is an object, which is why we have to transform it into an array // to be able to using usort() to sort the children. $children = $rootNode->getChildren(); $aChildren = array(); foreach ($children as $child) { $aChildren[] = $child; } usort($aChildren, function ($a, $b) { if ($a->getLft() < $b->getLft()) { return -1; } elseif ($a->getLft() > $b->getLft()) { return 1; } else { return 0; } }); $level++; foreach ($aChildren as $child) { $left++; $child->setLft($left); $child->setLvl($level); $this->recoverBranch($child, $left, $level); } $left++; $rootNode->setRgt($left); $this->em->persist($rootNode); $this->em->flush(); }
public function __toString() { $this->_load(); return parent::__toString(); }