/** * Sets the root page. * * @param CMS_page $page The new root page to set. * @return boolean true on success, false on failure * @access public */ function setRoot($page) { if (is_a($page, "CMS_page")) { $ws = CMS_tree::getPageWebsite($page); if ($ws->getRoot() == $page && $ws->getID() != $this->_id) { $this->raiseError("Root page to set is already a root page for the website : " . $ws->getLabel()); return false; } else { $this->_root = $page; return true; } } else { $this->raiseError("Root page to set is not a page"); return false; } }
/** * Check that the website is instanciated. * * @return void * @access private */ protected function _checkWebsite() { if (!is_object($this->_website)) { $this->_website = CMS_tree::getPageWebsite($this->_pageID); } if (!is_object($this->_website)) { $this->raiseError('No website found for page : ' . $this->_pageID); return false; } return true; }
/** * Returns the ancestor of the given page, at the given offset. * Offset : positive : 1 is for father, 2 for grand-father, and so on. * negative : -1 for the root sibling, -2 for the root grand-son (which are ancestors of $page) * Static function. * * @param CMS_page $page The page we want the brother of * @param integer $offset The ancestor offset (negative, will be sibling from root * @param boolean $stopAtWebsites Should the lineage stop at websites roots (other than the main website) ? * @return CMS_page The ancestor, or false if not found * @access public */ static function getAncestor(&$page, $offset, $stopAtWebsites = false, $publicTree = false) { if (!is_a($page, "CMS_page")) { CMS_grandFather::raiseError("Page must be instance of CMS_page"); return false; } if ($stopAtWebsites) { $ws = CMS_tree::getPageWebsite($page); $root = $ws->getRoot(); } else { $root = CMS_tree::getRoot(); } $lineage = CMS_tree::getLineage($root->getID(), $page->getID(), false, $publicTree); if (!$lineage) { return false; } if ($offset > 0) { $lineage = array_reverse($lineage); } else { $offset = abs($offset); } if ($offset >= sizeof($lineage)) { return false; } else { return CMS_tree::getPageByID($lineage[$offset]); } }