Open Monograph Press  3.3.0
Version.inc.php
1 <?php
2 
18 class Version extends DataObject {
22  function __construct($major, $minor, $revision, $build, $dateInstalled, $current,
23  $productType, $product, $productClassName, $lazyLoad, $sitewide) {
24 
25  parent::__construct();
26 
27  // Initialize object
28  $this->setMajor($major);
29  $this->setMinor($minor);
30  $this->setRevision($revision);
31  $this->setBuild($build);
32  $this->setDateInstalled($dateInstalled);
33  $this->setCurrent($current);
34  $this->setProductType($productType);
35  $this->setProduct($product);
36  $this->setProductClassName($productClassName);
37  $this->setLazyLoad($lazyLoad);
38  $this->setSitewide($sitewide);
39  }
40 
50  function compare($version) {
51  if (is_object($version)) {
52  return $this->compare($version->getVersionString());
53  }
54  return version_compare($this->getVersionString(), $version);
55  }
56 
67  static function fromString($versionString, $productType = null, $product = null, $productClass = '', $lazyLoad = 0, $sitewide = 1) {
68  $versionArray = explode('.', $versionString);
69 
70  if(!$product && !$productType) {
72  $product = $application->getName();
73  $productType = 'core';
74  }
75 
76  $version = new Version(
77  (isset($versionArray[0]) ? (int) $versionArray[0] : 0),
78  (isset($versionArray[1]) ? (int) $versionArray[1] : 0),
79  (isset($versionArray[2]) ? (int) $versionArray[2] : 0),
80  (isset($versionArray[3]) ? (int) $versionArray[3] : 0),
82  1,
83  $productType,
84  $product,
85  $productClass,
86  $lazyLoad,
87  $sitewide
88  );
89 
90  return $version;
91  }
92 
93  //
94  // Get/set methods
95  //
96 
101  function getMajor() {
102  return $this->getData('major');
103  }
104 
109  function setMajor($major) {
110  $this->setData('major', $major);
111  }
112 
117  function getMinor() {
118  return $this->getData('minor');
119  }
120 
125  function setMinor($minor) {
126  $this->setData('minor', $minor);
127  }
128 
133  function getRevision() {
134  return $this->getData('revision');
135  }
136 
141  function setRevision($revision) {
142  $this->setData('revision', $revision);
143  }
144 
149  function getBuild() {
150  return $this->getData('build');
151  }
152 
157  function setBuild($build) {
158  $this->setData('build', $build);
159  }
160 
165  function getDateInstalled() {
166  return $this->getData('dateInstalled');
167  }
168 
173  function setDateInstalled($dateInstalled) {
174  $this->setData('dateInstalled', $dateInstalled);
175  }
176 
181  function getCurrent() {
182  return $this->getData('current');
183  }
184 
189  function setCurrent($current) {
190  $this->setData('current', $current);
191  }
192 
197  function getProductType() {
198  return $this->getData('productType');
199  }
200 
205  function setProductType($productType) {
206  $this->setData('productType', $productType);
207  }
208 
213  function getProduct() {
214  return $this->getData('product');
215  }
216 
221  function setProduct($product) {
222  $this->setData('product', $product);
223  }
224 
229  function getProductClassName() {
230  return $this->getData('productClassName');
231  }
232 
237  function setProductClassName($productClassName) {
238  $this->setData('productClassName', $productClassName);
239  }
240 
245  function getLazyLoad() {
246  return $this->getData('lazyLoad');
247  }
248 
253  function setLazyLoad($lazyLoad) {
254  $this->setData('lazyLoad', $lazyLoad);
255  }
256 
261  function getSitewide() {
262  return $this->getData('sitewide');
263  }
264 
269  function setSitewide($sitewide) {
270  $this->setData('sitewide', $sitewide);
271  }
272 
278  function getVersionString($numeric = true) {
279  $numericVersion = sprintf('%d.%d.%d.%d', $this->getMajor(), $this->getMinor(), $this->getRevision(), $this->getBuild());
280  if (!$numeric && $this->getProduct() == 'omp' && preg_match('/^0\.9\.9\./', $numericVersion)) return ('1.0 Beta');
281  if (!$numeric && $this->getProduct() == 'ojs2' && preg_match('/^2\.9\.0\./', $numericVersion)) return ('3.0 Alpha 1');
282  if (!$numeric && $this->getProduct() == 'ojs2' && preg_match('/^2\.9\.9\.0/', $numericVersion)) return ('3.0 Beta 1');
283  if (!$numeric && $this->getProduct() == 'ops' && preg_match('/^3\.2\.0\.0/', $numericVersion)) return ('3.2.0 Beta');
284 
285  return $numericVersion;
286  }
287 }
288 
289 
DataObject\getData
& getData($key, $locale=null)
Definition: DataObject.inc.php:100
Version\getProductType
getProductType()
Definition: Version.inc.php:197
Version\setMajor
setMajor($major)
Definition: Version.inc.php:109
Version\getVersionString
getVersionString($numeric=true)
Definition: Version.inc.php:278
$application
$application
Definition: index.php:61
DataObject
Any class with an associated DAO should extend this class.
Definition: DataObject.inc.php:18
Version\getProduct
getProduct()
Definition: Version.inc.php:213
Version\setMinor
setMinor($minor)
Definition: Version.inc.php:125
Version
Describes system version history.
Definition: Version.inc.php:18
Version\__construct
__construct($major, $minor, $revision, $build, $dateInstalled, $current, $productType, $product, $productClassName, $lazyLoad, $sitewide)
Definition: Version.inc.php:22
Version\getProductClassName
getProductClassName()
Definition: Version.inc.php:229
Version\getMajor
getMajor()
Definition: Version.inc.php:101
Version\setLazyLoad
setLazyLoad($lazyLoad)
Definition: Version.inc.php:253
Version\getSitewide
getSitewide()
Definition: Version.inc.php:261
Version\setProductClassName
setProductClassName($productClassName)
Definition: Version.inc.php:237
Version\setDateInstalled
setDateInstalled($dateInstalled)
Definition: Version.inc.php:173
Version\compare
compare($version)
Definition: Version.inc.php:50
Version\setProduct
setProduct($product)
Definition: Version.inc.php:221
Version\getMinor
getMinor()
Definition: Version.inc.php:117
Version\fromString
static fromString($versionString, $productType=null, $product=null, $productClass='', $lazyLoad=0, $sitewide=1)
Definition: Version.inc.php:67
Version\setBuild
setBuild($build)
Definition: Version.inc.php:157
Version\getRevision
getRevision()
Definition: Version.inc.php:133
Version\getLazyLoad
getLazyLoad()
Definition: Version.inc.php:245
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
Version\setSitewide
setSitewide($sitewide)
Definition: Version.inc.php:269
Version\setCurrent
setCurrent($current)
Definition: Version.inc.php:189
Version\getDateInstalled
getDateInstalled()
Definition: Version.inc.php:165
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
Version\getCurrent
getCurrent()
Definition: Version.inc.php:181
Version\setProductType
setProductType($productType)
Definition: Version.inc.php:205
Version\getBuild
getBuild()
Definition: Version.inc.php:149
DataObject\setData
setData($key, $value, $locale=null)
Definition: DataObject.inc.php:132
Version\setRevision
setRevision($revision)
Definition: Version.inc.php:141