ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

VersionDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 // $Id$
17 
18 
19 import('site.Version');
20 
21 class VersionDAO extends DAO {
28  function &getCurrentVersion($product = null, $isPlugin = false) {
29  if(!$product) {
31  $product = $application->getName();
32  }
33 
34  // We only have to check whether we are on a version previous
35  // to the introduction of products when we're not looking for
36  // a product version anyway.
37  $returner = null;
38  if (!$isPlugin) {
39  $result =& $this->retrieve(
40  'SELECT * FROM versions WHERE current = 1'
41  );
42  // If we only have one current version then this must be
43  // the application version before the introduction of products
44  // into the versions table.
45  if ($result->RecordCount() == 1) {
46  $oldVersion =& $this->_returnVersionFromRow($result->GetRowAssoc(false));
47  if (isset($oldVersion)) $returner =& $oldVersion;
48  }
49  }
50 
51  if (!$returner) {
52  // From here on we can assume that we have the product
53  // column available in the versions table.
54  $result =& $this->retrieve(
55  'SELECT * FROM versions WHERE current = 1 AND product = ?',
56  array($product)
57  );
58  $versionCount = $result->RecordCount();
59  if ($versionCount == 1) {
60  $returner =& $this->_returnVersionFromRow($result->GetRowAssoc(false));
61  } elseif ($versionCount >1) {
62  fatalError('More than one current version defined for the product "'.$product.'"!');
63  }
64  }
65 
66  $result->Close();
67  unset($result);
68 
69  return $returner;
70  }
71 
77  function &getVersionHistory($product = null) {
78  $versions = array();
79 
80  if(!$product) {
82  $product = $application->getName();
83  }
84 
85  $result =& $this->retrieve(
86  'SELECT * FROM versions WHERE product = ? ORDER BY date_installed DESC',
87  array($product)
88  );
89 
90  while (!$result->EOF) {
91  $versions[] = $this->_returnVersionFromRow($result->GetRowAssoc(false));
92  $result->MoveNext();
93  }
94 
95  $result->Close();
96  unset($result);
97 
98  return $versions;
99  }
100 
106  function &_returnVersionFromRow(&$row) {
107  $version = new Version();
108  $version->setMajor($row['major']);
109  $version->setMinor($row['minor']);
110  $version->setRevision($row['revision']);
111  $version->setBuild($row['build']);
112  $version->setDateInstalled($this->datetimeFromDB($row['date_installed']));
113  $version->setCurrent($row['current']);
114  $version->setProductType(isset($row['product_type']) ? $row['product_type'] : null);
115  $version->setProduct(isset($row['product']) ? $row['product'] : null);
116 
117  HookRegistry::call('VersionDAO::_returnVersionFromRow', array(&$version, &$row));
118 
119  return $version;
120  }
121 
126  function insertVersion(&$version) {
127  if ($version->getCurrent()) {
128  // Version to insert is the new current, reset old current
129  $this->update('UPDATE versions SET current = 0 WHERE current = 1 AND product = ?', $version->getProduct());
130  }
131  if ($version->getDateInstalled() == null) {
132  $version->setDateInstalled(Core::getCurrentDate());
133  }
134 
135  return $this->update(
136  sprintf('INSERT INTO versions
137  (major, minor, revision, build, date_installed, current, product_type, product)
138  VALUES
139  (?, ?, ?, ?, %s, ?, ?, ?)',
140  $this->datetimeToDB($version->getDateInstalled())),
141  array(
142  (int) $version->getMajor(),
143  (int) $version->getMinor(),
144  (int) $version->getRevision(),
145  (int) $version->getBuild(),
146  (int) $version->getCurrent(),
147  $version->getProductType(),
148  $version->getProduct()
149  )
150  );
151  }
152 
158  function &getVersions($productType = null) {
159  $result =& $this->retrieveRange(
160  'SELECT * FROM versions WHERE current = 1 ' .
161  ($productType ? 'AND product_type LIKE ? ' : '') .
162  'ORDER BY product', $productType ? $productType . '%' : ''
163  );
164 
165  $returner = new DAOResultFactory($result, $this, '_returnVersionFromRow');
166  return $returner;
167  }
168 
173  function disableVersion($product) {
174  if ($product == 'NULL') {
175  $this->update(
176  'UPDATE versions SET current = 0 WHERE current = 1 AND product IS NULL'
177  );
178  } else {
179  $this->update(
180  'UPDATE versions SET current = 0 WHERE current = 1 AND product = ?',
181  array($product)
182  );
183  }
184  }
185 }
186 
187 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& getVersions($productType=null)
Operations for retrieving and modifying Version objects.
Describes system version history.
Definition: Version.inc.php:19
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
$application
Definition: index.php:64
& _returnVersionFromRow(&$row)
getCurrentDate($ts=null)
Definition: Core.inc.php:90
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
datetimeFromDB($dt)
Definition: DAO.inc.php:276
& getCurrentVersion($product=null, $isPlugin=false)
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
if(!function_exists('import')) if(!function_exists('file_get_contents')) fatalError($reason)
& getVersionHistory($product=null)
call($hookName, $args=null)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
insertVersion(&$version)
disableVersion($product)