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 07:09:28 +02:00
|
|
|
* documentation. An entity not an individual page but a `section` of
|
|
|
|
* documentation.
|
|
|
|
*
|
|
|
|
* Each section must have a version (defaults to `master`) which stores the
|
|
|
|
* actual path to the documentation (i.e framework 3.0, 3.1 docs point to
|
|
|
|
* different paths).
|
|
|
|
*
|
|
|
|
* Under each {@link DocumentationEntityVersion} contains languages. Most people
|
|
|
|
* will just have the one `en` folder but that translates to the
|
|
|
|
* {@link DocumentationEntityLanguage} instance to which the page relates to.
|
2014-09-07 01:26:12 +02:00
|
|
|
*
|
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 10:35:08 +02:00
|
|
|
$sortedVersions = $this->getVersions()->toArray();
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
usort($sortedVersions, create_function('$a,$b', 'return version_compare($a,$b);'));
|
|
|
|
|
|
|
|
return array_pop($sortedVersions);
|
2011-07-08 04:42:52 +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 07:09:28 +02:00
|
|
|
* Returns the web accessible link to this entity. This does not include any
|
|
|
|
* of the language information, the URL without the language should be a
|
|
|
|
* permanent direct to 'en' documentation or the first language.
|
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
|
|
|
|
2014-09-07 07:09:28 +02:00
|
|
|
/**
|
|
|
|
* @param DocumentationPage $page
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function hasRecord(DocumentationPage $page) {
|
|
|
|
foreach($this->getVersions() as $version) {
|
2014-09-07 11:28:21 +02:00
|
|
|
if(strstr($page->getPath(), $version->getPath()) !== false) {
|
|
|
|
return true;
|
2014-09-07 07:09:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-24 16:22:41 +02:00
|
|
|
}
|