Open Journal Systems  2.4.8
 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_merge(parent::getLocaleFieldNames(), 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  WHERE rf.assoc_type = ? AND assoc_id = ? AND rf.is_active = 1
282  ORDER BY rf.seq',
283  array((int) $assocType, (int) $assocId), $rangeInfo
284  );
285 
286  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
287  return $returner;
288  }
289 
297  function &getUsedByAssocId($assocType, $assocId, $rangeInfo = null) {
298  $result =& $this->retrieveRange(
299  'SELECT rf.*
300  FROM review_forms rf
301  WHERE rf.assoc_type = ? AND rf.assoc_id = ? AND rf.is_active = 1
302  AND EXISTS (
303  SELECT ra.review_form_id
304  FROM review_assignments ra
305  WHERE rf.review_form_id = ra.review_form_id
306  AND ((ra.date_confirmed IS NULL AND ra.date_notified IS NOT NULL) OR ra.date_confirmed IS NOT NULL)
307  )
308  ORDER BY rf.seq',
309  array((int) $assocType, (int) $assocId), $rangeInfo
310  );
311 
312  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
313  return $returner;
314  }
315 
323  function &getUnusedByAssocId($assocType, $assocId, $rangeInfo = null) {
324  $result =& $this->retrieveRange(
325  'SELECT rf.*
326  FROM review_forms rf
327  WHERE rf.assoc_type = ? AND rf.assoc_id = ?
328  AND NOT EXISTS (
329  SELECT ra.review_form_id
330  FROM review_assignments ra
331  WHERE rf.review_form_id = ra.review_form_id
332  AND ((ra.date_confirmed IS NULL AND ra.date_notified IS NOT NULL) OR ra.date_confirmed IS NOT NULL)
333  )
334  ORDER BY rf.seq',
335  array((int) $assocType, (int) $assocId), $rangeInfo
336  );
337 
338  $returner = new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
339  return $returner;
340  }
341 
349  function &getTitlesByAssocId($assocType, $assocId, $used) {
350  $reviewFormTitles = array();
351 
352  if ($used) {
353  $reviewForms =& $this->getUsedByAssocId($assocType, $assocId);
354  } else {
355  $reviewForms =& $this->getUnusedByAssocId($assocType, $assocId);
356  }
357  while (($reviewForm =& $reviewForms->next())) {
358  $reviewFormTitles[$reviewForm->getId()] = $reviewForm->getLocalizedTitle();
359  unset($reviewForm);
360  }
361 
362  return $reviewFormTitles;
363  }
364 
372  function unusedReviewFormExists($reviewFormId, $assocType = null, $assocId = null) {
373  $params = array((int) $reviewFormId);
374  if ($assocType !== null && $assocId !== null) {
375  $params[] = (int) $assocType;
376  $params[] = (int) $assocId;
377  } else {
378  $assocType = $assocId = null;
379  }
380 
381  $result =& $this->retrieve (
382  'SELECT rf.review_form_id
383  FROM review_forms rf
384  WHERE rf.review_form_id = ?' . ($assocType !== null ? ' AND rf.assoc_type = ? AND rf.assoc_id = ?':'') . '
385  AND NOT EXISTS (
386  SELECT ra.review_form_id
387  FROM review_assignments ra
388  WHERE rf.review_form_id = ra.review_form_id
389  AND ((ra.date_confirmed IS NULL AND ra.date_notified IS NOT NULL) OR ra.date_confirmed IS NOT NULL)
390  )',
391  $params
392  );
393 
394  $returner = $result->RecordCount() != 0;
395 
396  $result->Close();
397  unset($result);
398 
399  return $returner;
400  }
401 
407  function resequenceReviewForms($assocType, $assocId) {
408  $result =& $this->retrieve(
409  'SELECT review_form_id FROM review_forms WHERE assoc_type = ? AND assoc_id = ? ORDER BY seq',
410  array((int) $assocType, (int) $assocId)
411  );
412 
413  for ($i=1; !$result->EOF; $i++) {
414  list($reviewFormId) = $result->fields;
415  $this->update(
416  'UPDATE review_forms SET seq = ? WHERE review_form_id = ?',
417  array(
418  $i,
419  $reviewFormId
420  )
421  );
422 
423  $result->MoveNext();
424  }
425 
426  $result->Close();
427  unset($result);
428  }
429 
435  return $this->getInsertId('review_forms', 'review_form_id');
436  }
437 
440  function insertReviewForm(&$reviewForm) {
441  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
442  $this->insertObject($reviewForm);
443  }
444  function updateReviewForm(&$reviewForm) {
445  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
446  $this->updateObject($reviewForm);
447  }
448  function deleteReviewForm(&$reviewForm) {
449  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
450  $this->deleteObject($reviewForm);
451  }
452  function deleteReviewFormById($reviewFormId, $arg = null) {
453  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
454  $this->deleteById($reviewFormId);
455  }
456 }
457 
458 ?>
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)