diff --git a/code/DocumentationManifest.php b/code/DocumentationManifest.php index 4bacd6d..8011f48 100644 --- a/code/DocumentationManifest.php +++ b/code/DocumentationManifest.php @@ -138,6 +138,12 @@ class DocumentationManifest $version = (isset($details['Version'])) ? $details['Version'] : ''; + $versionTitle = isset($details['VersionTitle']) + ? $details['VersionTitle'] + : $version; + + $archived = !empty($details['Archived']); + $branch = (isset($details['Branch'])) ? $details['Branch'] : ''; $langs = scandir($path); @@ -147,6 +153,7 @@ class DocumentationManifest foreach ($langs as $k => $lang) { if (isset($possible[$lang])) { + /** @var DocumentationEntity $entity */ $entity = Injector::inst()->create( 'DocumentationEntity', $key ); @@ -155,7 +162,9 @@ class DocumentationManifest $entity->setTitle($details['Title']); $entity->setLanguage($lang); $entity->setVersion($version); + $entity->setVersionTitle($versionTitle); $entity->setBranch($branch); + $entity->setIsArchived($archived); if (isset($details['Stable'])) { $entity->setIsStable($details['Stable']); @@ -720,8 +729,7 @@ class DocumentationManifest } /** - * @param DocumentationEntity - * + * @param DocumentationEntity $entity * @return ArrayList */ public function getVersions($entity) @@ -732,13 +740,16 @@ class DocumentationManifest $output = new ArrayList(); + /** @var DocumentationEntity $check */ foreach ($this->getEntities() as $check) { if ($check->getKey() == $entity->getKey()) { if ($check->getLanguage() == $entity->getLanguage()) { $same = ($check->getVersion() == $entity->getVersion()); $output->push(new ArrayData(array( - 'Title' => $check->getVersion(), + 'Title' => $check->getVersionTitle(), + 'Version' => $check->getVersion(), + 'Archived' => $check->getIsArchived(), 'Link' => $check->Link(), 'LinkingMode' => ($same) ? 'current' : 'link', 'IsStable' => $check->getIsStable() diff --git a/code/models/DocumentationEntity.php b/code/models/DocumentationEntity.php index 6d18e2b..9ce838f 100755 --- a/code/models/DocumentationEntity.php +++ b/code/models/DocumentationEntity.php @@ -35,6 +35,13 @@ class DocumentationEntity extends ViewableData */ protected $title; + /** + * Label for this version + * + * @var string + */ + protected $versionTitle; + /** * If the system is setup to only document one entity then you may only * want to show a single entity in the URL and the sidebar. Set this when @@ -45,6 +52,13 @@ class DocumentationEntity extends ViewableData */ protected $defaultEntity; + /** + * Set if this version is archived + * + * @var bool + */ + protected $archived = false; + /** * @var mixed */ @@ -77,10 +91,11 @@ class DocumentationEntity extends ViewableData protected $language; /** - * + * @param string $key Key of module */ public function __construct($key) { + parent::__construct(); $this->key = DocumentationHelper::clean_page_url($key); } @@ -101,7 +116,7 @@ class DocumentationEntity extends ViewableData /** * @param string $title - * @return this + * @return $this */ public function setTitle($title) { @@ -172,12 +187,12 @@ class DocumentationEntity extends ViewableData } /** - * @param boolean $bool + * @param bool $bool + * @return $this */ public function setIsDefaultEntity($bool) { $this->defaultEntity = $bool; - return $this; } @@ -208,7 +223,7 @@ class DocumentationEntity extends ViewableData /** * @param string * - * @return this + * @return $this */ public function setLanguage($language) { @@ -219,6 +234,7 @@ class DocumentationEntity extends ViewableData /** * @param string + * @return $this */ public function setVersion($version) { @@ -235,8 +251,47 @@ class DocumentationEntity extends ViewableData 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) { @@ -264,7 +319,7 @@ class DocumentationEntity extends ViewableData /** * @param string $path * - * @return this + * @return $this */ public function setPath($path) { @@ -274,7 +329,8 @@ class DocumentationEntity extends ViewableData } /** - * @param boolean + * @param bool + * @return $this */ public function setIsStable($stable) { @@ -298,12 +354,25 @@ class DocumentationEntity extends ViewableData * 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 string $version + * @param DocumentationEntity $other * @return int */ public function compare(DocumentationEntity $other) { - return version_compare($this->getVersion(), $other->getVersion()); + $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); } /** diff --git a/tests/DocumentationEntityTest.php b/tests/DocumentationEntityTest.php new file mode 100644 index 0000000..ec7458c --- /dev/null +++ b/tests/DocumentationEntityTest.php @@ -0,0 +1,31 @@ +setVersion($left); + + $rightVersion = new DocumentationEntity('Framework'); + $rightVersion->setVersion($right); + + $this->assertEquals($result, $leftVersion->compare($rightVersion)); + } +}