key = DocumentationHelper::clean_page_url($key); } /** * Get the title of this module. * * @return string */ public function getTitle() { if (!$this->title) { $this->title = DocumentationHelper::clean_page_name($this->key); } return $this->title; } /** * @param string $title * @return $this */ public function setTitle($title) { $this->title = $title; return $this; } /** * Returns the web accessible link to this entity. * * Includes the version information * * @param boolean $short If true, will attempt to return a short version of the url * This might omit the version number if this is the default version. * @return string */ public function Link($short = false) { if ($this->getIsDefaultEntity()) { $base = Controller::join_links( Config::inst()->get('DocumentationViewer', 'link_base'), $this->getLanguage(), '/' ); } else { $base = Controller::join_links( Config::inst()->get('DocumentationViewer', 'link_base'), $this->getLanguage(), $this->getKey(), '/' ); } $base = ltrim(str_replace('//', '/', $base), '/'); if ($short && $this->stable) { return $base; } return Controller::join_links( $base, $this->getVersion(), '/' ); } /** * @return string */ public function __toString() { return sprintf('DocumentationEntity: %s)', $this->getPath()); } /** * @param DocumentationPage $page * * @return boolean */ public function hasRecord($page) { if (!$page) { return false; } return strstr($page->getPath(), $this->getPath()) !== false; } /** * @param bool $bool * @return $this */ public function setIsDefaultEntity($bool) { $this->defaultEntity = $bool; return $this; } /** * @return boolean */ public function getIsDefaultEntity() { return $this->defaultEntity; } /** * @return string */ public function getKey() { return $this->key; } /** * @return string */ public function getLanguage() { return $this->language; } /** * @param string * * @return $this */ public function setLanguage($language) { $this->language = $language; return $this; } /** * @param string * @return $this */ public function setVersion($version) { $this->version = $version; return $this; } /** * @return float */ public function getVersion() { return $this->version; } /** * Get the version for this title * * @return string */ public function getVersionTitle() { return $this->versionTitle; } /** * Sets the title for this version * * @param string $title * @return $this */ public function setVersionTitle($title) { $this->versionTitle = $title; return $this; } /** * Set if this is archived * * @param bool $archived * @return $this */ public function setIsArchived($archived) { $this->archived = $archived; return $this; } /** * @return bool */ public function getIsArchived() { return $this->archived; } /** * @param string * @return $this */ public function setBranch($branch) { $this->branch = $branch; return $this; } /** * @return float */ public function getBranch() { return $this->branch; } /** * @return string */ public function getPath() { return $this->path; } /** * @param string $path * * @return $this */ public function setPath($path) { $this->path = $path; return $this; } /** * @param bool * @return $this */ public function setIsStable($stable) { $this->stable = $stable; return $this; } /** * @return boolean */ public function getIsStable() { return $this->stable; } /** * Returns an integer value based on if a given version is the latest * version. Will return -1 for if the version is older, 0 if versions are * the same and 1 if the version is greater than. * * @param DocumentationEntity $other * @return int */ public function compare(DocumentationEntity $other) { $v1 = $this->getVersion(); $v2 = $other->getVersion(); // Normalise versions prior to comparison $dots = substr_count($v1, '.') - substr_count($v2, '.'); while($dots > 0) { $dots--; $v2 .= '.99999'; } while ($dots < 0) { $dots++; $v1 .= '.99999'; } return version_compare($v1, $v2); } /** * @return array */ public function toMap() { return array( 'Key' => $this->key, 'Path' => $this->getPath(), 'Version' => $this->getVersion(), 'Branch' => $this->getBranch(), 'IsStable' => $this->getIsStable(), 'Language' => $this->getLanguage() ); } }