mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
API Add VersionTitle and Archived fields to config
BUG Fix version comparison between `3` and `3.5` (3 is newer)
This commit is contained in:
parent
9d7a1f6210
commit
babf1580b9
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
31
tests/DocumentationEntityTest.php
Normal file
31
tests/DocumentationEntityTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class DocumentationEntityTest extends SapphireTest
|
||||
{
|
||||
public function dataCompare() {
|
||||
return array(
|
||||
array('3', '3.0', 1),
|
||||
array('3.1', '3.1', 0),
|
||||
array('3.0', '3', -1),
|
||||
array('4', '3', 1),
|
||||
array('3', '4', -1),
|
||||
array('3.4.1', '4', -1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataCompare
|
||||
* @param string $left
|
||||
* @param string $right
|
||||
* @param int $result
|
||||
*/
|
||||
public function testCompare($left, $right, $result) {
|
||||
$leftVersion = new DocumentationEntity('Framework');
|
||||
$leftVersion->setVersion($left);
|
||||
|
||||
$rightVersion = new DocumentationEntity('Framework');
|
||||
$rightVersion->setVersion($right);
|
||||
|
||||
$this->assertEquals($result, $leftVersion->compare($rightVersion));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user