Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
ReviewFormDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.reviewForm.ReviewForm');
19 
20 class ReviewFormDAO extends DAO {
21 
25  function ReviewFormDAO() {
26  parent::DAO();
27  }
28 
36  function &getReviewForm($reviewFormId, $assocType = null, $assocId = null) {
37  $params = array((int) $reviewFormId);
38  if ($assocType !== null && $assocId !== null) {
39  $params[] = (int) $assocType;
40  $params[] = (int) $assocId;
41  } else {
42  $assocType = $assocId = null;
43  }
44 
45  $result =& $this->retrieve (
46  'SELECT rf.*
47  FROM review_forms rf
48  WHERE rf.review_form_id = ? ' . (($assocType !== null) ? 'AND rf.assoc_type = ? AND rf.assoc_id = ?' : ''),
49  $params
50  );
51 
52  $returner = null;
53  if ($result->RecordCount() != 0) {
54  $returner =& $this->_returnReviewFormFromRow($result->GetRowAssoc(false));
55  }
56 
57  $result->Close();
58  unset($result);
59 
60  return $returner;
61  }
62 
70  function getUseCounts($assocType, $assocId, $completion = null) {
71  $params = array((int) $assocType, (int) $assocId);
72 
73  $result =& $this->retrieve (
74  'SELECT rf.review_form_id AS review_form_id,
75  count(ra.review_form_id) AS rf_count
76  FROM review_forms rf
77  LEFT JOIN review_assignments ra ON (
78  ra.review_form_id = rf.review_form_id' .
79  ($completion === true?' AND ra.date_confirmed IS NOT NULL':'') .
80  ($completion === false?' AND ra.date_notified IS NOT NULL AND ra.date_confirmed IS NULL':'') . '
81  )
82  WHERE rf.assoc_type = ? AND rf.assoc_id = ?
83  GROUP BY rf.review_form_id',
84  $params
85  );
86 
87  $returner = array();
88  while (!$result->EOF) {
89  $row = $result->getRowAssoc(false);
90  $returner[$row['review_form_id']] = $row['rf_count'];
91  $result->MoveNext();
92  }
93  $result->Close();
94  unset($result);
95 
96  return $returner;
97  }
98 
103  function newDataObject() {
104  return new ReviewForm();
105  }
106 
112  function &_returnReviewFormFromRow(&$row) {
113  $reviewForm = $this->newDataObject();
114  $reviewForm->setId($row['review_form_id']);
115  $reviewForm->setAssocType($row['assoc_type']);
116  $reviewForm->setAssocId($row['assoc_id']);
117  $reviewForm->setSequence($row['seq']);
118  $reviewForm->setActive($row['is_active']);
119 
120  $this->getDataObjectSettings('review_form_settings', 'review_form_id', $row['review_form_id'], $reviewForm);
121 
122  HookRegistry::call('ReviewFormDAO::_returnReviewFormFromRow', array(&$reviewForm, &$row));
123 
124  return $reviewForm;
125  }
126 
134  function reviewFormExists($reviewFormId, $assocType, $assocId) {
135  $result =& $this->retrieve(
136  'SELECT COUNT(*) FROM review_forms WHERE review_form_id = ? AND assoc_type = ? AND assoc_id = ?',
137  array($reviewFormId, $assocType, $assocId)
138  );
139  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
140 
141  $result->Close();
142  unset($result);
143 
144  return $returner;
145  }
146 
151  function getLocaleFieldNames() {
152  return array('title', 'description');
153  }
154 
159  function updateLocaleFields(&$reviewForm) {
160  $this->updateDataObjectSettings('review_form_settings', $reviewForm, array(
161  'review_form_id' => $reviewForm->getId()
162  ));
163  }
164 
169  function insertObject(&$reviewForm) {
170  $this->update(
171  'INSERT INTO review_forms
172  (assoc_type, assoc_id, seq, is_active)
173  VALUES
174  (?, ?, ?, ?)',
175  array(
176  $reviewForm->getAssocType(),
177  $reviewForm->getAssocId(),
178  $reviewForm->getSequence() == null ? 0 : $reviewForm->getSequence(),
179  $reviewForm->getActive() ? 1 : 0
180  )
181  );
182 
183  $reviewForm->setId($this->getInsertReviewFormId());
184  $this->updateLocaleFields($reviewForm);
185 
186  return $reviewForm->getId();
187  }
188 
193  function updateObject(&$reviewForm) {
194  $returner = $this->update(
195  'UPDATE review_forms
196  SET
197  assoc_type = ?,
198  assoc_id = ?,
199  seq = ?,
200  is_active = ?
201  WHERE review_form_id = ?',
202  array(
203  $reviewForm->getAssocType(),
204  $reviewForm->getAssocId(),
205  $reviewForm->getSequence(),
206  $reviewForm->getActive(),
207  $reviewForm->getId()
208  )
209  );
210 
211  $this->updateLocaleFields($reviewForm);
212 
213  return $returner;
214  }
215 
220  function deleteObject(&$reviewForm) {
221  return $this->deleteById($reviewForm->getId());
222  }
223 
228  function deleteById($reviewFormId) {
229  $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
230  $reviewFormElementDao->deleteByReviewFormId($reviewFormId);
231 
232  $this->update('DELETE FROM review_form_settings WHERE review_form_id = ?', array($reviewFormId));
233  return $this->update('DELETE FROM review_forms WHERE review_form_id = ?', array($reviewFormId));
234  }
235 
241  function deleteByAssocId($assocType, $assocId) {
242  $reviewForms = $this->getByAssocId($assocType, $assocId);
243 
244  while (!$reviewForms->eof()) {
245  $reviewForm =& $reviewForms->next();
246  $this->deleteById($reviewForm->getId());
247  }
248  }
249 
257  function &getByAssocId($assocType, $assocId, $rangeInfo = null) {
258  $result =& $this->retrieveRange(
259  'SELECT *
260  FROM review_forms
261  WHERE assoc_type = ? AND assoc_id = ?
262  ORDER BY seq',
263  array((int) $assocType, (int) $assocId), $rangeInfo
264  );
265 
266  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
267  return $returner;
268  }
269 
277  function &getActiveByAssocId($assocType, $assocId, $rangeInfo = null) {
278  $result =& $this->retrieveRange(
279  'SELECT rf.*
280  FROM review_forms rf
281  LEFT JOIN review_assignments rac ON (
282  rac.review_form_id = rf.review_form_id AND
283  rac.date_confirmed IS NOT NULL
284  )
285  LEFT JOIN review_assignments rai ON (
286  rai.review_form_id = rf.review_form_id AND
287  rai.date_notified IS NOT NULL AND
288  rai.date_confirmed IS NULL
289  )
290  WHERE rf.assoc_type = ? AND assoc_id = ? AND rf.is_active = 1
291  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
292  ORDER BY rf.seq',
293  array((int) $assocType, (int) $assocId), $rangeInfo
294  );
295 
296  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
297  return $returner;
298  }
299 
307  function &getUsedByAssocId($assocType, $assocId, $rangeInfo = null) {
308  $result =& $this->retrieveRange(
309  'SELECT rf.*
310  FROM review_forms rf
311  LEFT JOIN review_assignments rac ON (
312  rac.review_form_id = rf.review_form_id AND
313  rac.date_confirmed IS NOT NULL
314  )
315  LEFT JOIN review_assignments rai ON (
316  rai.review_form_id = rf.review_form_id AND
317  rai.date_notified IS NOT NULL AND
318  rai.date_confirmed IS NULL
319  )
320  WHERE rf.assoc_type = ? AND rf.assoc_id = ? AND rf.is_active = 1
321  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
322  HAVING COUNT(rac.review_id) > 0 OR COUNT(rai.review_id) > 0
323  ORDER BY rf.seq',
324  array((int) $assocType, (int) $assocId), $rangeInfo
325  );
326 
327  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
328  return $returner;
329  }
330 
338  function &getUnusedByAssocId($assocType, $assocId, $rangeInfo = null) {
339  $result =& $this->retrieveRange(
340  'SELECT rf.*
341  FROM review_forms rf
342  LEFT JOIN review_assignments rac ON (
343  rac.review_form_id = rf.review_form_id AND
344  rac.date_confirmed IS NOT NULL
345  )
346  LEFT JOIN review_assignments rai ON (
347  rai.review_form_id = rf.review_form_id AND
348  rai.date_notified IS NOT NULL AND
349  rai.date_confirmed IS NULL
350  )
351  WHERE rf.assoc_type = ? AND rf.assoc_id = ?
352  GROUP BY rf.assoc_type, rf.assoc_id, rf.review_form_id, rf.seq, rf.is_active
353  HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0
354  ORDER BY rf.seq',
355  array((int) $assocType, (int) $assocId), $rangeInfo
356  );
357 
358  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
359  return $returner;
360  }
361 
369  function &getTitlesByAssocId($assocType, $assocId, $used) {
370  $reviewFormTitles = array();
371 
372  if ($used) {
373  $reviewForms =& $this->getUsedByAssocId($assocType, $assocId);
374  } else {
375  $reviewForms =& $this->getUnusedByAssocId($assocType, $assocId);
376  }
377  while (($reviewForm =& $reviewForms->next())) {
378  $reviewFormTitles[$reviewForm->getId()] = $reviewForm->getLocalizedTitle();
379  unset($reviewForm);
380  }
381 
382  return $reviewFormTitles;
383  }
384 
392  function unusedReviewFormExists($reviewFormId, $assocType = null, $assocId = null) {
393  $params = array((int) $reviewFormId);
394  if ($assocType !== null && $assocId !== null) {
395  $params[] = (int) $assocType;
396  $params[] = (int) $assocId;
397  } else {
398  $assocType = $assocId = null;
399  }
400 
401  $result =& $this->retrieve (
402  'SELECT rf.review_form_id,
403  COUNT(rac.review_id) AS complete_count,
404  COUNT(rai.review_id) AS incomplete_count
405  FROM review_forms rf
406  LEFT JOIN review_assignments rac ON (
407  rac.review_form_id = rf.review_form_id AND
408  rac.date_confirmed IS NOT NULL
409  )
410  LEFT JOIN review_assignments rai ON (
411  rai.review_form_id = rf.review_form_id AND
412  rai.date_notified IS NOT NULL AND
413  rai.date_confirmed IS NULL
414  )
415  WHERE rf.review_form_id = ?' . ($assocType !== null ? ' AND rf.assoc_type = ? AND rf.assoc_id = ?':'') . '
416  GROUP BY rf.review_form_id
417  HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0',
418  $params
419  );
420 
421  $returner = $result->RecordCount() != 0;
422 
423  $result->Close();
424  unset($result);
425 
426  return $returner;
427  }
428 
434  function resequenceReviewForms($assocType, $assocId) {
435  $result =& $this->retrieve(
436  'SELECT review_form_id FROM review_forms WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
437  array((int) $assocType, (int) $assocId)
438  );
439 
440  for ($i=1; !$result->EOF; $i++) {
441  list($reviewFormId) = $result->fields;
442  $this->update(
443  'UPDATE review_forms SET seq = ? WHERE review_form_id = ?',
444  array(
445  $i,
446  $reviewFormId
447  )
448  );
449 
450  $result->MoveNext();
451  }
452 
453  $result->Close();
454  unset($result);
455  }
456 
462  return $this->getInsertId('review_forms', 'review_form_id');
463  }
464 
467  function insertReviewForm(&$reviewForm) {
468  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
469  $this->insertObject($reviewForm);
470  }
471  function updateReviewForm(&$reviewForm) {
472  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
473  $this->updateObject($reviewForm);
474  }
475  function deleteReviewForm(&$reviewForm) {
476  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
477  $this->deleteObject($reviewForm);
478  }
479  function deleteReviewFormById($reviewFormId, $arg = null) {
480  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
481  $this->deleteById($reviewFormId);
482  }
483 }
484 
485 ?>
deleteByAssocId($assocType, $assocId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
updateObject(&$reviewForm)
unusedReviewFormExists($reviewFormId, $assocType=null, $assocId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
& getUnusedByAssocId($assocType, $assocId, $rangeInfo=null)
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& getTitlesByAssocId($assocType, $assocId, $used)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
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 &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getDAO($name, $dbconn=null)
insertObject(&$reviewForm)
& getActiveByAssocId($assocType, $assocId, $rangeInfo=null)
call($hookName, $args=null)
reviewFormExists($reviewFormId, $assocType, $assocId)
& getReviewForm($reviewFormId, $assocType=null, $assocId=null)
resequenceReviewForms($assocType, $assocId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteById($reviewFormId)
getUseCounts($assocType, $assocId, $completion=null)
& getByAssocId($assocType, $assocId, $rangeInfo=null)
insertReviewForm(&$reviewForm)