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)  

RegistrationTypeDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('registration.RegistrationType');
19 
20 class RegistrationTypeDAO extends DAO {
27  function &getRegistrationType($typeId, $code = null) {
28  $params = array($typeId);
29  if ($code !== null) $params[] = $code;
30  $result =& $this->retrieve(
31  'SELECT * FROM registration_types WHERE type_id = ?' .
32  ($code !== null ? ' AND code = ?':''),
33  $params
34  );
35 
36  $returner = null;
37  if ($result->RecordCount() != 0) {
38  $returner =& $this->_returnRegistrationTypeFromRow($result->GetRowAssoc(false));
39  }
40 
41  $result->Close();
42  unset($result);
43 
44  return $returner;
45  }
46 
52  function getRegistrationTypeSchedConfId($typeId) {
53  $result =& $this->retrieve(
54  'SELECT sched_conf_id FROM registration_types WHERE type_id = ?', $typeId
55  );
56 
57  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
58 
59  $result->Close();
60  unset($result);
61 
62  return $returner;
63  }
64 
70  function getRegistrationTypeName($typeId) {
71  $result =& $this->retrieve(
72  'SELECT COALESCE(l.setting_value, p.setting_value) FROM registration_type_settings l LEFT JOIN registration_type_settings p ON (p.type_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.type_id = ? AND l.setting_name = ? AND l.locale = ?',
73  array(
74  $typeId, 'name', AppLocale::getLocale(),
75  $typeId, 'name', AppLocale::getPrimaryLocale()
76  )
77  );
78 
79  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
80 
81  $result->Close();
82  unset($result);
83 
84  return $returner;
85  }
86 
93  $result =& $this->retrieve(
94  'SELECT institutional FROM registration_types WHERE type_id = ?', $typeId
95  );
96 
97  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
98 
99  $result->Close();
100  unset($result);
101 
102  return $returner;
103  }
104 
110  function getRegistrationTypeMembership($typeId) {
111  $result =& $this->retrieve(
112  'SELECT membership FROM registration_types WHERE type_id = ?', $typeId
113  );
114 
115  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
116 
117  $result->Close();
118  unset($result);
119 
120  return $returner;
121  }
122 
128  function getRegistrationTypePublic($typeId) {
129  $result =& $this->retrieve(
130  'SELECT pub FROM registration_types WHERE type_id = ?', $typeId
131  );
132 
133  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
134 
135  $result->Close();
136  unset($result);
137 
138  return $returner;
139  }
140 
147  function registrationTypeExistsByTypeId($typeId, $schedConfId) {
148  $result =& $this->retrieve(
149  'SELECT COUNT(*)
150  FROM registration_types
151  WHERE type_id = ?
152  AND sched_conf_id = ?',
153  array(
154  $typeId,
155  $schedConfId
156  )
157  );
158  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
159 
160  $result->Close();
161  unset($result);
162 
163  return $returner;
164  }
165 
172  function openRegistrationTypeExistsByTypeId($typeId, $schedConfId) {
173  $time = $this->dateToDB(time());
174 
175  $result =& $this->retrieve(
176  'SELECT COUNT(*)
177  FROM registration_types
178  WHERE type_id = ?
179  AND sched_conf_id = ?
180  AND opening_date <= ' . $time . '
181  AND closing_date > ' . $time . '
182  AND pub = 1',
183  array(
184  $typeId,
185  $schedConfId
186  )
187  );
188  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
189 
190  $result->Close();
191  unset($result);
192 
193  return $returner;
194  }
195 
203  function checkCode($typeId, $schedConfId, $code) {
204  $result =& $this->retrieve(
205  'SELECT COUNT(*)
206  FROM registration_types
207  WHERE type_id = ?
208  AND sched_conf_id = ?
209  AND code = ?',
210  array(
211  $typeId,
212  $schedConfId,
213  $code
214  )
215  );
216  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
217 
218  $result->Close();
219  unset($result);
220 
221  return $returner;
222  }
223 
230  $registrationType = new RegistrationType();
231  $registrationType->setTypeId($row['type_id']);
232  $registrationType->setSchedConfId($row['sched_conf_id']);
233  $registrationType->setCode($row['code']);
234  $registrationType->setCost($row['cost']);
235  $registrationType->setCurrencyCodeAlpha($row['currency_code_alpha']);
236  $registrationType->setOpeningDate($this->dateFromDB($row['opening_date']));
237  $registrationType->setClosingDate($this->datetimeFromDB($row['closing_date']));
238  $registrationType->setExpiryDate($this->datetimeFromDB($row['expiry_date']));
239  $registrationType->setAccess($row['access']);
240  $registrationType->setInstitutional($row['institutional']);
241  $registrationType->setMembership($row['membership']);
242  $registrationType->setPublic($row['pub']);
243  $registrationType->setSequence($row['seq']);
244 
245  $this->getDataObjectSettings('registration_type_settings', 'type_id', $row['type_id'], $registrationType);
246 
247  HookRegistry::call('RegistrationTypeDAO::_returnRegistrationTypeFromRow', array(&$registrationType, &$row));
248 
249  return $registrationType;
250  }
251 
256  function getLocaleFieldNames() {
257  return array('name', 'description');
258  }
259 
264  function updateLocaleFields(&$registrationType) {
265  $this->updateDataObjectSettings('registration_type_settings', $registrationType, array(
266  'type_id' => $registrationType->getTypeId()
267  ));
268  }
269 
275  function insertRegistrationType(&$registrationType) {
276  $expiryDate = $registrationType->getExpiryDate();
277  $this->update(
278  sprintf('INSERT INTO registration_types
279  (sched_conf_id, cost, currency_code_alpha, opening_date, closing_date, expiry_date, access, institutional, membership, pub, seq, code)
280  VALUES
281  (?, ?, ?, %s, %s, %s, ?, ?, ?, ?, ?, ?)',
282  $this->dateToDB($registrationType->getOpeningDate()),
283  $this->datetimeToDB($registrationType->getClosingDate()),
284  $expiryDate === null?'null':$this->datetimeToDB($expiryDate)
285  ), array(
286  (int) $registrationType->getSchedConfId(),
287  (float) $registrationType->getCost(),
288  $registrationType->getCurrencyCodeAlpha(),
289  (int) $registrationType->getAccess(),
290  (int) $registrationType->getInstitutional(),
291  (int) $registrationType->getMembership(),
292  (int) $registrationType->getPublic(),
293  (float) $registrationType->getSequence(),
294  $registrationType->getCode()
295  )
296  );
297 
298  $registrationType->setTypeId($this->getInsertRegistrationTypeId());
299  $this->updateLocaleFields($registrationType);
300  return $registrationType->getTypeId();
301  }
302 
308  function updateRegistrationType(&$registrationType) {
309  $expiryDate = $registrationType->getExpiryDate();
310  $returner = $this->update(
311  sprintf('UPDATE registration_types
312  SET
313  sched_conf_id = ?,
314  cost = ?,
315  currency_code_alpha = ?,
316  opening_date = %s,
317  closing_date = %s,
318  expiry_date = %s,
319  access = ?,
320  institutional = ?,
321  membership = ?,
322  pub = ?,
323  seq = ?,
324  code = ?
325  WHERE type_id = ?',
326  $this->dateToDB($registrationType->getOpeningDate()),
327  $this->datetimeToDB($registrationType->getClosingDate()),
328  $expiryDate === null?'null':$this->datetimeToDB($expiryDate)
329  ), array(
330  (int) $registrationType->getSchedConfId(),
331  (float) $registrationType->getCost(),
332  $registrationType->getCurrencyCodeAlpha(),
333  (int) $registrationType->getAccess(),
334  (int) $registrationType->getInstitutional(),
335  (int) $registrationType->getMembership(),
336  (int) $registrationType->getPublic(),
337  (float) $registrationType->getSequence(),
338  $registrationType->getCode(),
339  (int) $registrationType->getTypeId()
340  )
341  );
342  $this->updateLocaleFields($registrationType);
343  return $returner;
344  }
345 
351  function deleteRegistrationType(&$registrationType) {
352  return $this->deleteRegistrationTypeById($registrationType->getTypeId());
353  }
354 
361  function deleteRegistrationTypeById($typeId) {
362  // Delete registration type
363  $this->update(
364  'DELETE FROM registration_types WHERE type_id = ?',
365  array((int) $typeId)
366  );
367 
368  // Delete all localization settings and registrations associated with this registration type
369  $this->deleteRegistrationOptionCosts($typeId);
370  $this->update('DELETE FROM registration_type_settings WHERE type_id = ?', $typeId);
371 
372  $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
373  return $registrationDao->deleteRegistrationByTypeId($typeId);
374  }
375 
376  function deleteRegistrationTypesBySchedConf($schedConfId) {
377  $registrationTypes =& $this->getRegistrationTypesBySchedConfId($schedConfId);
378  while ($registrationType =& $registrationTypes->next()) {
379  $this->deleteRegistrationType($registrationType);
380  unset($registrationType);
381  }
382  }
383 
389  function &getRegistrationTypesBySchedConfId($schedConfId, $rangeInfo = null) {
390  $result =& $this->retrieveRange(
391  'SELECT * FROM registration_types WHERE sched_conf_id = ? ORDER BY seq',
392  $schedConfId, $rangeInfo
393  );
394 
395  $returner = new DAOResultFactory($result, $this, '_returnRegistrationTypeFromRow');
396  return $returner;
397  }
398 
404  return $this->getInsertId('registration_types', 'type_id');
405  }
406 
410  function resequenceRegistrationTypes($schedConfId) {
411  $result =& $this->retrieve(
412  'SELECT type_id FROM registration_types WHERE sched_conf_id = ? ORDER BY seq',
413  $schedConfId
414  );
415 
416  for ($i=1; !$result->EOF; $i++) {
417  list($registrationTypeId) = $result->fields;
418  $this->update(
419  'UPDATE registration_types SET seq = ? WHERE type_id = ?',
420  array(
421  $i,
422  $registrationTypeId
423  )
424  );
425 
426  $result->moveNext();
427  }
428 
429  $result->close();
430  unset($result);
431  }
432 
440  function insertRegistrationOptionCost($typeId, $optionId, $cost) {
441  return $this->update(
442  'INSERT INTO registration_option_costs
443  (type_id, option_id, cost)
444  VALUES
445  (?, ?, ?)',
446  array(
447  (int) $typeId,
448  (int) $optionId,
449  $cost
450  )
451  );
452  }
453 
459  function getRegistrationOptionCosts($typeId) {
460  $result =& $this->retrieve(
461  'SELECT option_id, cost FROM registration_option_costs WHERE type_id = ?',
462  array((int) $typeId)
463  );
464 
465  $returner = array();
466  for ($i=1; !$result->EOF; $i++) {
467  list($optionId, $cost) = $result->fields;
468  $returner[$optionId] = $cost;
469  $result->moveNext();
470  }
471 
472  $result->close();
473  unset($result);
474  return $returner;
475  }
476 
481  function deleteRegistrationOptionCosts($typeId) {
482  return $this->update(
483  'DELETE FROM registration_option_costs WHERE type_id = ?',
484  array((int) $typeId)
485  );
486 
487  }
488 }
489 
490 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
resequenceRegistrationTypes($schedConfId)
& getRegistrationType($typeId, $code=null)
& getRegistrationTypesBySchedConfId($schedConfId, $rangeInfo=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
deleteRegistrationTypesBySchedConf($schedConfId)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
registrationTypeExistsByTypeId($typeId, $schedConfId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:412
dateToDB($d)
Definition: DAO.inc.php:267
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
updateLocaleFields(&$registrationType)
datetimeFromDB($dt)
Definition: DAO.inc.php:276
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
& getDAO($name, $dbconn=null)
deleteRegistrationType(&$registrationType)
Operations for retrieving and modifying RegistrationType objects.
call($hookName, $args=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:498
checkCode($typeId, $schedConfId, $code)
openRegistrationTypeExistsByTypeId($typeId, $schedConfId)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
Basic class describing a registration type.
insertRegistrationOptionCost($typeId, $optionId, $cost)
insertRegistrationType(&$registrationType)
dateFromDB($d)
Definition: DAO.inc.php:285
updateRegistrationType(&$registrationType)