2010-06-24 16:22:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-09-06 01:13:12 +02:00
|
|
|
* A {@link DocumentationEntity} represents a module or folder with
|
2014-09-07 01:26:12 +02:00
|
|
|
* documentation not an individual page. Entities are loaded via
|
|
|
|
* {@link DocumentationService::register()} and individual pages are represented
|
|
|
|
* by a {@link DocumentationPage} and are loaded by the manifest.
|
|
|
|
*
|
2010-08-01 09:03:48 +02:00
|
|
|
*
|
2012-04-08 11:36:16 +02:00
|
|
|
* @package docsviewer
|
2011-07-01 08:49:31 +02:00
|
|
|
* @subpackage models
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
class DocumentationEntity extends ViewableData {
|
|
|
|
|
2011-07-08 04:42:52 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-03-26 11:08:44 +01:00
|
|
|
private static $casting = array(
|
2014-09-07 01:26:12 +02:00
|
|
|
'Title' => 'Text'
|
2010-06-24 16:22:41 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* @var string $title
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
protected $title;
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* @var string $folder
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
protected $folder;
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* @var ArrayList $versions
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
protected $versions;
|
2010-06-24 16:22:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor. You do not need to pass the langs to this as
|
|
|
|
* it will work out the languages from the filesystem
|
|
|
|
*
|
2011-07-01 08:49:31 +02:00
|
|
|
* @param string $folder folder name
|
2010-12-21 10:42:44 +01:00
|
|
|
* @param string $title
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function __construct($folder, $title = false) {
|
|
|
|
$this->versions = new ArrayList();
|
2011-07-01 08:49:31 +02:00
|
|
|
$this->folder = $folder;
|
2014-09-07 01:26:12 +02:00
|
|
|
$this->title = (!$title) ? $folder : $title;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Get the title of this module.
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function getTitle() {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-01 08:49:31 +02:00
|
|
|
* Return the versions which have been registered for this entity.
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
2011-07-01 08:49:31 +02:00
|
|
|
* @return array
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
|
|
|
public function getVersions() {
|
2014-09-07 01:26:12 +02:00
|
|
|
return $this->versions;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
2010-08-01 09:03:48 +02:00
|
|
|
/**
|
2011-07-08 04:42:52 +02:00
|
|
|
* @return string|boo
|
2010-08-01 09:03:48 +02:00
|
|
|
*/
|
2011-07-08 04:42:52 +02:00
|
|
|
public function getStableVersion() {
|
2014-09-07 01:26:12 +02:00
|
|
|
if(!$this->hasVersions()) {
|
|
|
|
return false;
|
2014-09-06 01:13:12 +02:00
|
|
|
}
|
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
$sortedVersions = $this->getVersions();
|
|
|
|
|
|
|
|
usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);'));
|
|
|
|
|
|
|
|
return array_pop($sortedVersions);
|
2011-07-08 04:42:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 string $version
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function compare($version) {
|
|
|
|
$latest = $this->getStableVersion();
|
|
|
|
|
|
|
|
return version_compare($version, $latest);
|
2010-08-01 09:03:48 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
/**
|
|
|
|
* Return whether we have a given version of this entity
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasVersion($version) {
|
2014-09-07 01:26:12 +02:00
|
|
|
return $this->versions->find('Version', $version);
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether we have any versions at all0
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasVersions() {
|
2014-09-07 01:26:12 +02:00
|
|
|
return $this->versions->count() > 0;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add another version to this entity
|
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @param DocumentationEntityVersion
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function addVersion($version) {
|
|
|
|
$this->versions->push($version);
|
2011-07-01 03:19:35 +02:00
|
|
|
|
2014-09-07 01:26:12 +02:00
|
|
|
return $this;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a version from this entity
|
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @param float $version
|
|
|
|
*
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function removeVersion($version) {
|
|
|
|
$this->versions->remove('Version', $version);
|
|
|
|
|
|
|
|
return $this;
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Return the absolute path to this documentation entity.
|
2010-06-24 16:22:41 +02:00
|
|
|
*
|
2010-12-22 09:21:49 +01:00
|
|
|
* @return string
|
2010-06-24 16:22:41 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getPath() {
|
|
|
|
return $this->path;
|
2010-08-01 09:03:50 +02:00
|
|
|
}
|
|
|
|
|
2010-12-22 09:21:49 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function getFolder() {
|
|
|
|
return $this->folder;
|
2011-01-16 21:17:56 +01:00
|
|
|
}
|
2014-09-06 01:13:12 +02:00
|
|
|
|
2011-07-01 08:49:31 +02:00
|
|
|
/**
|
2014-09-07 01:26:12 +02:00
|
|
|
* Returns the web accessible link to this Entity
|
2011-07-01 08:49:31 +02:00
|
|
|
*
|
2014-09-07 01:26:12 +02:00
|
|
|
* @return string
|
2011-07-01 08:49:31 +02:00
|
|
|
*/
|
2014-09-07 01:26:12 +02:00
|
|
|
public function Link() {
|
|
|
|
return Controller::join_links(
|
|
|
|
Config::inst()->get('DocumentationViewer', 'link_base'),
|
|
|
|
$this->getFolder()
|
|
|
|
);
|
2011-07-01 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2010-12-21 10:42:44 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-09-06 01:13:12 +02:00
|
|
|
public function __toString() {
|
2010-08-01 09:03:50 +02:00
|
|
|
return sprintf('DocumentationEntity: %s)', $this->getPath());
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|
2014-09-07 01:26:12 +02:00
|
|
|
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|