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)  

ReviewFormDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
17 import('reviewForm.ReviewForm');
18 
19 class ReviewFormDAO extends DAO {
20 
24  function ReviewFormDAO() {
25  parent::DAO();
26  }
27 
35  function &getReviewForm($reviewFormId, $assocType = null, $assocId = null) {
36  $params = array((int) $reviewFormId);
37  if ($assocType !== null && $assocId !== null) {
38  $params[] = (int) $assocType;
39  $params[] = (int) $assocId;
40  } else {
41  $assocType = $assocId = null;
42  }
43 
44  $result =& $this->retrieve (
45  'SELECT rf.review_form_id,
46  rf.assoc_type,
47  rf.assoc_id,
48  rf.seq,
49  rf.is_active,
50  COUNT(rac.review_id) AS complete_count,
51  COUNT(rai.review_id) AS incomplete_count
52  FROM review_forms rf
53  LEFT JOIN review_assignments rac ON (
54  rac.review_form_id = rf.review_form_id AND
55  rac.date_confirmed IS NOT NULL
56  )
57  LEFT JOIN review_assignments rai ON (
58  rai.review_form_id = rf.review_form_id AND
59  rai.date_notified IS NOT NULL AND
60  rai.date_confirmed IS NULL
61  )
62  WHERE rf.review_form_id = ? ' . (($assocType !== null) ? 'AND rf.assoc_type = ? AND rf.assoc_id = ?' : '') . '
63  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active',
64  $params
65  );
66 
67  $returner = null;
68  if ($result->RecordCount() != 0) {
69  $returner =& $this->_returnReviewFormFromRow($result->GetRowAssoc(false));
70  }
71 
72  $result->Close();
73  unset($result);
74 
75  return $returner;
76  }
77 
82  function newDataObject() {
83  return new ReviewForm();
84  }
85 
91  function &_returnReviewFormFromRow(&$row) {
92  $reviewForm = $this->newDataObject();
93  $reviewForm->setId($row['review_form_id']);
94  $reviewForm->setAssocType($row['assoc_type']);
95  $reviewForm->setAssocId($row['assoc_id']);
96  $reviewForm->setSequence($row['seq']);
97  $reviewForm->setActive($row['is_active']);
98  $reviewForm->setCompleteCount($row['complete_count']);
99  $reviewForm->setIncompleteCount($row['incomplete_count']);
100 
101  $this->getDataObjectSettings('review_form_settings', 'review_form_id', $row['review_form_id'], $reviewForm);
102 
103  HookRegistry::call('ReviewFormDAO::_returnReviewFormFromRow', array(&$reviewForm, &$row));
104 
105  return $reviewForm;
106  }
107 
115  function reviewFormExists($reviewFormId, $assocType, $assocId) {
116  $result =& $this->retrieve(
117  'SELECT COUNT(*) FROM review_forms WHERE review_form_id = ? AND assoc_type = ? AND assoc_id = ?',
118  array($reviewFormId, $assocType, $assocId)
119  );
120  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
121 
122  $result->Close();
123  unset($result);
124 
125  return $returner;
126  }
127 
132  function getLocaleFieldNames() {
133  return array('title', 'description');
134  }
135 
140  function updateLocaleFields(&$reviewForm) {
141  $this->updateDataObjectSettings('review_form_settings', $reviewForm, array(
142  'review_form_id' => $reviewForm->getId()
143  ));
144  }
145 
150  function insertObject(&$reviewForm) {
151  $this->update(
152  'INSERT INTO review_forms
153  (assoc_type, assoc_id, seq, is_active)
154  VALUES
155  (?, ?, ?, ?)',
156  array(
157  $reviewForm->getAssocType(),
158  $reviewForm->getAssocId(),
159  $reviewForm->getSequence() == null ? 0 : $reviewForm->getSequence(),
160  $reviewForm->getActive() ? 1 : 0
161  )
162  );
163 
164  $reviewForm->setId($this->getInsertReviewFormId());
165  $this->updateLocaleFields($reviewForm);
166 
167  return $reviewForm->getId();
168  }
169 
174  function updateObject(&$reviewForm) {
175  $returner = $this->update(
176  'UPDATE review_forms
177  SET
178  assoc_type = ?,
179  assoc_id = ?,
180  seq = ?,
181  is_active = ?
182  WHERE review_form_id = ?',
183  array(
184  $reviewForm->getAssocType(),
185  $reviewForm->getAssocId(),
186  $reviewForm->getSequence(),
187  $reviewForm->getActive(),
188  $reviewForm->getId()
189  )
190  );
191 
192  $this->updateLocaleFields($reviewForm);
193 
194  return $returner;
195  }
196 
201  function deleteObject(&$reviewForm) {
202  return $this->deleteById($reviewForm->getId());
203  }
204 
209  function deleteById($reviewFormId) {
210  $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
211  $reviewFormElementDao->deleteByReviewFormId($reviewFormId);
212 
213  $this->update('DELETE FROM review_form_settings WHERE review_form_id = ?', array($reviewFormId));
214  return $this->update('DELETE FROM review_forms WHERE review_form_id = ?', array($reviewFormId));
215  }
216 
222  function deleteByAssocId($assocType, $assocId) {
223  $reviewForms = $this->getByAssocId($assocType, $assocId);
224 
225  while (!$reviewForms->eof()) {
226  $reviewForm =& $reviewForms->next();
227  $this->deleteById($reviewForm->getId());
228  }
229  }
230 
238  function &getByAssocId($assocType, $assocId, $rangeInfo = null) {
239  $result =& $this->retrieveRange(
240  'SELECT rf.review_form_id,
241  rf.assoc_type,
242  rf.assoc_id,
243  rf.seq,
244  rf.is_active,
245  COUNT(rac.review_id) AS complete_count,
246  COUNT(rai.review_id) AS incomplete_count
247  FROM review_forms rf
248  LEFT JOIN review_assignments rac ON (
249  rac.review_form_id = rf.review_form_id AND
250  rac.date_confirmed IS NOT NULL
251  )
252  LEFT JOIN review_assignments rai ON (
253  rai.review_form_id = rf.review_form_id AND
254  rai.date_notified IS NOT NULL AND
255  rai.date_confirmed IS NULL
256  )
257  WHERE rf.assoc_type = ? AND rf.assoc_id = ?
258  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
259  ORDER BY rf.seq',
260  array($assocType, $assocId), $rangeInfo
261  );
262 
263  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
264  return $returner;
265  }
266 
274  function &getActiveByAssocId($assocType, $assocId, $rangeInfo = null) {
275  $result =& $this->retrieveRange(
276  'SELECT rf.review_form_id,
277  rf.assoc_type,
278  rf.assoc_id,
279  rf.seq,
280  rf.is_active,
281  COUNT(rac.review_id) AS complete_count,
282  COUNT(rai.review_id) AS incomplete_count
283  FROM review_forms rf
284  LEFT JOIN review_assignments rac ON (
285  rac.review_form_id = rf.review_form_id AND
286  rac.date_confirmed IS NOT NULL
287  )
288  LEFT JOIN review_assignments rai ON (
289  rai.review_form_id = rf.review_form_id AND
290  rai.date_notified IS NOT NULL AND
291  rai.date_confirmed IS NULL
292  )
293  WHERE rf.assoc_type = ? AND assoc_id = ? AND rf.is_active = 1
294  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
295  ORDER BY rf.seq',
296  array($assocType, $assocId), $rangeInfo
297  );
298 
299  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
300  return $returner;
301  }
302 
310  function &getUsedByAssocId($assocType, $assocId, $rangeInfo = null) {
311  $result =& $this->retrieveRange(
312  'SELECT rf.review_form_id,
313  rf.assoc_type,
314  rf.assoc_id,
315  rf.seq,
316  rf.is_active,
317  COUNT(rac.review_id) AS complete_count,
318  COUNT(rai.review_id) AS incomplete_count
319  FROM review_forms rf
320  LEFT JOIN review_assignments rac ON (
321  rac.review_form_id = rf.review_form_id AND
322  rac.date_confirmed IS NOT NULL
323  )
324  LEFT JOIN review_assignments rai ON (
325  rai.review_form_id = rf.review_form_id AND
326  rai.date_notified IS NOT NULL AND
327  rai.date_confirmed IS NULL
328  )
329  WHERE rf.assoc_type = ? AND rf.assoc_id = ? AND rf.is_active = 1
330  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
331  HAVING COUNT(rac.review_id) > 0 OR COUNT(rai.review_id) > 0
332  ORDER BY rf.seq',
333  array($assocType, $assocId), $rangeInfo
334  );
335 
336  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
337  return $returner;
338  }
339 
347  function &getUnusedByAssocId($assocType, $assocId, $rangeInfo = null) {
348  $result =& $this->retrieveRange(
349  'SELECT rf.review_form_id,
350  rf.assoc_type,
351  rf.assoc_id,
352  rf.seq,
353  rf.is_active,
354  COUNT(rac.review_id) AS complete_count,
355  COUNT(rai.review_id) AS incomplete_count
356  FROM review_forms rf
357  LEFT JOIN review_assignments rac ON (
358  rac.review_form_id = rf.review_form_id AND
359  rac.date_confirmed IS NOT NULL
360  )
361  LEFT JOIN review_assignments rai ON (
362  rai.review_form_id = rf.review_form_id AND
363  rai.date_notified IS NOT NULL AND
364  rai.date_confirmed IS NULL
365  )
366  WHERE rf.assoc_type = ? AND rf.assoc_id = ?
367  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
368  HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0
369  ORDER BY rf.seq',
370  array($assocType, $assocId), $rangeInfo
371  );
372 
373  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
374  return $returner;
375  }
376 
384  function &getTitlesByAssocId($assocType, $assocId, $used) {
385  $reviewFormTitles = array();
386 
387  if ($used) {
388  $reviewForms =& $this->getUsedByAssocId($assocType, $assocId);
389  } else {
390  $reviewForms =& $this->getUnusedByAssocId($assocType, $assocId);
391  }
392  while (($reviewForm =& $reviewForms->next())) {
393  $reviewFormTitles[$reviewForm->getId()] = $reviewForm->getLocalizedTitle();
394  unset($reviewForm);
395  }
396 
397  return $reviewFormTitles;
398  }
399 
407  function unusedReviewFormExists($reviewFormId, $assocType = null, $assocId = null) {
408  $params = array((int) $reviewFormId);
409  if ($assocType !== null && $assocId !== null) {
410  $params[] = (int) $assocType;
411  $params[] = (int) $assocId;
412  } else {
413  $assocType = $assocId = null;
414  }
415 
416  $result =& $this->retrieve (
417  'SELECT rf.review_form_id,
418  COUNT(rac.review_id) AS complete_count,
419  COUNT(rai.review_id) AS incomplete_count
420  FROM review_forms rf
421  LEFT JOIN review_assignments rac ON (
422  rac.review_form_id = rf.review_form_id AND
423  rac.date_confirmed IS NOT NULL
424  )
425  LEFT JOIN review_assignments rai ON (
426  rai.review_form_id = rf.review_form_id AND
427  rai.date_notified IS NOT NULL AND
428  rai.date_confirmed IS NULL
429  )
430  WHERE rf.review_form_id = ?' . ($assocType !== null ? ' AND rf.assoc_type = ? AND rf.assoc_id = ?':'') . '
431  GROUP BY rf.review_form_id
432  HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0',
433  $params
434  );
435 
436  $returner = $result->RecordCount() != 0;
437 
438  $result->Close();
439  unset($result);
440 
441  return $returner;
442  }
443 
449  function resequenceReviewForms($assocType, $assocId) {
450  $result =& $this->retrieve(
451  'SELECT review_form_id FROM review_forms WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
452  array((int) $assocType, (int) $assocId)
453  );
454 
455  for ($i=1; !$result->EOF; $i++) {
456  list($reviewFormId) = $result->fields;
457  $this->update(
458  'UPDATE review_forms SET seq = ? WHERE review_form_id = ?',
459  array(
460  $i,
461  $reviewFormId
462  )
463  );
464 
465  $result->moveNext();
466  }
467 
468  $result->close();
469  unset($result);
470  }
471 
477  return $this->getInsertId('review_forms', 'review_form_id');
478  }
479 
482  function insertReviewForm(&$reviewForm) {
483  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
484  $this->insertObject($reviewForm);
485  }
486  function updateReviewForm(&$reviewForm) {
487  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
488  $this->updateObject($reviewForm);
489  }
490  function deleteReviewForm(&$reviewForm) {
491  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
492  $this->deleteObject($reviewForm);
493  }
494  function deleteReviewFormById($reviewFormId, $arg = null) {
495  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
496  $this->deleteById($reviewFormId);
497  }
498 }
499 
500 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
deleteByAssocId($assocType, $assocId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
updateObject(&$reviewForm)
unusedReviewFormExists($reviewFormId, $assocType=null, $assocId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
updateReviewForm(&$reviewForm)
& getUnusedByAssocId($assocType, $assocId, $rangeInfo=null)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
deleteReviewForm(&$reviewForm)
& getTitlesByAssocId($assocType, $assocId, $used)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:412
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
deleteObject(&$reviewForm)
Basic class describing a review form.
& _returnReviewFormFromRow(&$row)
& getUsedByAssocId($assocType, $assocId, $rangeInfo=null)
Operations for retrieving and modifying ReviewForm objects.
updateLocaleFields(&$reviewForm)
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
& getDAO($name, $dbconn=null)
insertObject(&$reviewForm)
& getActiveByAssocId($assocType, $assocId, $rangeInfo=null)
call($hookName, $args=null)
reviewFormExists($reviewFormId, $assocType, $assocId)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:498
& getReviewForm($reviewFormId, $assocType=null, $assocId=null)
deleteReviewFormById($reviewFormId, $arg=null)
resequenceReviewForms($assocType, $assocId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
deleteById($reviewFormId)
& getByAssocId($assocType, $assocId, $rangeInfo=null)
insertReviewForm(&$reviewForm)