Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
PKPReviewAssignmentDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.submission.reviewAssignment.PKPReviewAssignment');
19 
20 class PKPReviewAssignmentDAO extends DAO {
21  var $userDao;
22 
27  parent::DAO();
28  $this->userDao =& DAORegistry::getDAO('UserDAO');
29  }
30 
31 
32  //
33  // Template methods.
34  //
40  function getReviewRoundJoin() {
41  return false;
42  }
43 
44 
45  //
46  // Public methods.
47  //
48 
57  function &getReviewAssignment($submissionId, $reviewerId, $round, $stageId = null) {
58  $params = array(
59  (int) $submissionId,
60  (int) $reviewerId,
61  (int) $round
62  );
63  if ($stageId !== null) $params[] = (int) $stageId;
64 
65  $result =& $this->retrieve(
66  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
67  FROM review_assignments r
68  JOIN users u ON (r.reviewer_id = u.user_id)
69  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
70  WHERE r.submission_id = ? AND
71  r.reviewer_id = ? AND
72  r.cancelled <> 1 AND
73  r.round = ?' .
74  ($stageId !== null? ' AND r.stage_id = ?' : ''),
75  $params
76  );
77 
78  $returner = null;
79  if ($result->RecordCount() != 0) {
80  $returner =& $this->_fromRow($result->GetRowAssoc(false));
81  }
82 
83  $result->Close();
84  unset($result);
85 
86  return $returner;
87  }
88 
94  function &getById($reviewId) {
95  $reviewRoundJoinString = $this->getReviewRoundJoin();
96  if ($reviewRoundJoinString) {
97  $result =& $this->retrieve(
98  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
99  FROM review_assignments r
100  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
101  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
102  WHERE r.review_id = ?',
103  (int) $reviewId
104  );
105 
106  $returner = null;
107  if ($result->RecordCount() != 0) {
108  $returner =& $this->_fromRow($result->GetRowAssoc(false));
109  }
110 
111  $result->Close();
112  unset($result);
113 
114  return $returner;
115  } else {
116  assert(false);
117  }
118  }
119 
126  $reviewAssignments = array();
127  $reviewRoundJoinString = $this->getReviewRoundJoin();
128  if ($reviewRoundJoinString) {
129  $result =& $this->retrieve(
130  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
131  FROM review_assignments r
132  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
133  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
135  ' ORDER BY r.submission_id'
136  );
137 
138  while (!$result->EOF) {
139  $reviewAssignments[] =& $this->_fromRow($result->GetRowAssoc(false));
140  $result->MoveNext();
141  }
142 
143  $result->Close();
144  unset($result);
145  } else {
146  assert(false);
147  }
148 
149  return $reviewAssignments;
150  }
151 
158  return ' (r.cancelled IS NULL OR r.cancelled = 0) AND
159  r.date_notified IS NOT NULL AND
160  r.date_completed IS NULL AND
161  r.declined <> 1';
162  }
163 
170  function &getBySubmissionId($submissionId, $round = null, $stageId = null) {
171  $reviewAssignments = array();
172 
173  $query = 'SELECT r.*, r2.review_revision, u.first_name, u.last_name
174  FROM review_assignments r
175  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
176  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round AND r.stage_id = r2.stage_id)
177  WHERE r.submission_id = ?';
178 
179  $orderBy = ' ORDER BY review_id';
180 
181  $queryParams[] = (int) $submissionId;
182 
183  if ($round != null) {
184  $query .= ' AND r.round = ?';
185  $queryParams[] = (int) $round;
186  } else {
187  $orderBy .= ', r.round';
188  }
189 
190  if ($stageId != null) {
191  $query .= ' AND r.stage_id = ?';
192  $queryParams[] = (int) $stageId;
193  } else {
194  $orderBy .= ', r.stage_id';
195  }
196 
197  $query .= $orderBy;
198 
199  $result =& $this->retrieve($query, $queryParams);
200 
201  while (!$result->EOF) {
202  $reviewAssignments[$result->fields['review_id']] =& $this->_fromRow($result->GetRowAssoc(false));
203  $result->MoveNext();
204  }
205 
206  $result->Close();
207  unset($result);
208 
209  return $reviewAssignments;
210  }
211 
219  function &getReviewerIdsBySubmissionId($submissionId, $round = null, $stageId = null) {
220  $query = 'SELECT r.reviewer_id
221  FROM review_assignments r
222  WHERE r.submission_id = ?';
223 
224  $queryParams[] = (int) $submissionId;
225 
226  if ($round != null) {
227  $query .= ' AND r.round = ?';
228  $queryParams[] = (int) $round;
229  }
230 
231  if ($stageId != null) {
232  $query .= ' AND r.stage_id = ?';
233  $queryParams[] = (int) $stageId;
234  }
235 
236  $result =& $this->retrieve($query, $queryParams);
237 
238  $reviewAssignments = array();
239  while (!$result->EOF) {
240  $row = $result->GetRowAssoc(false);
241  $reviewAssignments[] = $row['reviewer_id'];
242  $result->MoveNext();
243  }
244 
245  $result->Close();
246  unset($result);
247 
248  return $reviewAssignments;
249  }
250 
256  function &getByUserId($userId) {
257  $reviewAssignments = array();
258  $reviewRoundJoinString = $this->getReviewRoundJoin();
259 
260  if ($reviewRoundJoinString) {
261  $result =& $this->retrieve(
262  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
263  FROM review_assignments r
264  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
265  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
266  WHERE r.reviewer_id = ?
267  ORDER BY round, review_id',
268  (int) $userId
269  );
270 
271  while (!$result->EOF) {
272  $reviewAssignments[] =& $this->_fromRow($result->GetRowAssoc(false));
273  $result->MoveNext();
274  }
275 
276  $result->Close();
277  unset($result);
278  } else {
279  assert(false);
280  }
281 
282  return $reviewAssignments;
283  }
284 
290  function &getByReviewFormId($reviewFormId) {
291  $reviewAssignments = array();
292  $reviewRoundJoinString = $this->getReviewRoundJoin();
293 
294  if ($reviewRoundJoinString) {
295  $result =& $this->retrieve(
296  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
297  FROM review_assignments r
298  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
299  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
300  WHERE r.review_form_id = ?
301  ORDER BY round, review_id',
302  (int) $reviewFormId
303  );
304 
305  while (!$result->EOF) {
306  $reviewAssignments[] =& $this->_fromRow($result->GetRowAssoc(false));
307  $result->MoveNext();
308  }
309 
310  $result->Close();
311  unset($result);
312  } else {
313  assert(false);
314  }
315 
316  return $reviewAssignments;
317  }
318 
324  function &getCancelsAndRegrets($submissionId) {
325  $reviewAssignments = array();
326  $reviewRoundJoinString = $this->getReviewRoundJoin();
327 
328  if ($reviewRoundJoinString) {
329  $result =& $this->retrieve(
330  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
331  FROM review_assignments r
332  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
333  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
334  WHERE r.submission_id = ? AND
335  (r.cancelled = 1 OR r.declined = 1)
336  ORDER BY round, review_id',
337  (int) $submissionId
338  );
339 
340  while (!$result->EOF) {
341  $reviewAssignments[] =& $this->_fromRow($result->GetRowAssoc(false));
342  $result->MoveNext();
343  }
344 
345  $result->Close();
346  unset($result);
347  } else {
348  assert(false);
349  }
350 
351  return $reviewAssignments;
352  }
353 
360  function &getReviewIndexesForRound($submissionId, $round) {
361  $result =& $this->retrieve(
362  'SELECT review_id
363  FROM review_assignments
364  WHERE submission_id = ? AND
365  round = ? AND
366  (cancelled = 0 OR cancelled IS NULL)
367  ORDER BY review_id',
368  array((int) $submissionId, (int) $round)
369  );
370 
371  $index = 0;
372  $returner = array();
373  while (!$result->EOF) {
374  $row = $result->GetRowAssoc(false);
375  $returner[$row['review_id']] = $index++;
376  $result->MoveNext();
377  }
378 
379  $result->Close();
380  unset($result);
381 
382  return $returner;
383  }
384 
391  function &getLastModifiedByRound($submissionId) {
392  $returner = array();
393 
394  $result =& $this->retrieve(
395  'SELECT round, MAX(last_modified) as last_modified
396  FROM review_assignments
397  WHERE submission_id = ?
398  GROUP BY round',
399  (int) $submissionId
400  );
401 
402  while (!$result->EOF) {
403  $row = $result->GetRowAssoc(false);
404  $returner[$row['round']] = $this->datetimeFromDB($row['last_modified']);
405  $result->MoveNext();
406  }
407 
408  $result->Close();
409  unset($result);
410 
411  return $returner;
412  }
413 
420  function &getEarliestNotificationByRound($submissionId) {
421  $returner = array();
422 
423  $result =& $this->retrieve(
424  'SELECT round, MIN(date_notified) as earliest_date
425  FROM review_assignments
426  WHERE submission_id = ?
427  GROUP BY round',
428  (int) $submissionId
429  );
430 
431  while (!$result->EOF) {
432  $row = $result->GetRowAssoc(false);
433  $returner[$row['round']] = $this->datetimeFromDB($row['earliest_date']);
434  $result->MoveNext();
435  }
436 
437  $result->Close();
438  unset($result);
439 
440  return $returner;
441  }
442 
443  function insertReviewAssignment(&$reviewAssignment) {
444  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
445  return $this->insertObject($reviewAssignment);
446  }
447 
452  function insertObject(&$reviewAssignment) {
453  $this->update(
454  sprintf('INSERT INTO review_assignments (
455  submission_id,
456  reviewer_id,
457  stage_id,
458  review_method,
459  regret_message,
460  round,
461  competing_interests,
462  recommendation,
463  declined, replaced, cancelled,
464  date_assigned, date_notified, date_confirmed,
465  date_completed, date_acknowledged, date_due, date_response_due,
466  reviewer_file_id,
467  quality, date_rated,
468  last_modified,
469  date_reminded, reminder_was_automatic,
470  review_form_id,
471  review_round_id,
472  unconsidered
473  ) VALUES (
474  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, %s, %s, %s, %s, %s, %s, %s, ?, ?, %s, %s, %s, ?, ?, ?, ?
475  )',
476  $this->datetimeToDB($reviewAssignment->getDateAssigned()), $this->datetimeToDB($reviewAssignment->getDateNotified()), $this->datetimeToDB($reviewAssignment->getDateConfirmed()), $this->datetimeToDB($reviewAssignment->getDateCompleted()), $this->datetimeToDB($reviewAssignment->getDateAcknowledged()), $this->datetimeToDB($reviewAssignment->getDateDue()), $this->datetimeToDB($reviewAssignment->getDateResponseDue()), $this->datetimeToDB($reviewAssignment->getDateRated()), $this->datetimeToDB($reviewAssignment->getLastModified()), $this->datetimeToDB($reviewAssignment->getDateReminded())),
477  array(
478  (int) $reviewAssignment->getSubmissionId(),
479  (int) $reviewAssignment->getReviewerId(),
480  (int) $reviewAssignment->getStageId(),
481  (int) $reviewAssignment->getReviewMethod(),
482  $reviewAssignment->getRegretMessage(),
483  max((int) $reviewAssignment->getRound(), 1),
484  $reviewAssignment->getCompetingInterests(),
485  $reviewAssignment->getRecommendation(),
486  (int) $reviewAssignment->getDeclined(),
487  (int) $reviewAssignment->getReplaced(),
488  (int) $reviewAssignment->getCancelled(),
489  $reviewAssignment->getReviewerFileId(),
490  $reviewAssignment->getQuality(),
491  $reviewAssignment->getReminderWasAutomatic(),
492  $reviewAssignment->getReviewFormId(),
493  (int) $reviewAssignment->getReviewRoundId(),
494  (int) $reviewAssignment->getUnconsidered(),
495  )
496  );
497 
498  $reviewAssignment->setId($this->getInsertReviewId());
499  return $reviewAssignment->getId();
500  }
501 
506  function updateReviewAssignment(&$reviewAssignment) {
507  return $this->update(
508  sprintf('UPDATE review_assignments
509  SET submission_id = ?,
510  reviewer_id = ?,
511  stage_id = ?,
512  review_method = ?,
513  regret_message = ?,
514  round = ?,
515  competing_interests = ?,
516  recommendation = ?,
517  declined = ?,
518  replaced = ?,
519  cancelled = ?,
520  date_assigned = %s,
521  date_notified = %s,
522  date_confirmed = %s,
523  date_completed = %s,
524  date_acknowledged = %s,
525  date_due = %s,
526  date_response_due = %s,
527  reviewer_file_id = ?,
528  quality = ?,
529  date_rated = %s,
530  last_modified = %s,
531  date_reminded = %s,
532  reminder_was_automatic = ?,
533  review_form_id = ?,
534  review_round_id = ?,
535  unconsidered = ?
536  WHERE review_id = ?',
537  $this->datetimeToDB($reviewAssignment->getDateAssigned()), $this->datetimeToDB($reviewAssignment->getDateNotified()), $this->datetimeToDB($reviewAssignment->getDateConfirmed()), $this->datetimeToDB($reviewAssignment->getDateCompleted()), $this->datetimeToDB($reviewAssignment->getDateAcknowledged()), $this->datetimeToDB($reviewAssignment->getDateDue()), $this->datetimeToDB($reviewAssignment->getDateResponseDue()), $this->datetimeToDB($reviewAssignment->getDateRated()), $this->datetimeToDB($reviewAssignment->getLastModified()), $this->datetimeToDB($reviewAssignment->getDateReminded())),
538  array(
539  (int) $reviewAssignment->getSubmissionId(),
540  (int) $reviewAssignment->getReviewerId(),
541  (int) $reviewAssignment->getStageId(),
542  (int) $reviewAssignment->getReviewMethod(),
543  $reviewAssignment->getRegretMessage(),
544  (int) $reviewAssignment->getRound(),
545  $reviewAssignment->getCompetingInterests(),
546  $reviewAssignment->getRecommendation(),
547  (int) $reviewAssignment->getDeclined(),
548  (int) $reviewAssignment->getReplaced(),
549  (int) $reviewAssignment->getCancelled(),
550  $reviewAssignment->getReviewerFileId(),
551  $reviewAssignment->getQuality(),
552  $reviewAssignment->getReminderWasAutomatic(),
553  $reviewAssignment->getReviewFormId(),
554  (int) $reviewAssignment->getReviewRoundId(),
555  (int) $reviewAssignment->getUnconsidered(),
556  (int) $reviewAssignment->getId()
557  )
558  );
559  }
560 
566  function &_fromRow(&$row) {
567  $reviewAssignment = $this->newDataObject();
568 
569  $reviewAssignment->setId($row['review_id']);
570  $reviewAssignment->setSubmissionId($row['submission_id']);
571  $reviewAssignment->setReviewerId($row['reviewer_id']);
572  $reviewAssignment->setReviewerFullName($row['first_name'].' '.$row['last_name']);
573  $reviewAssignment->setCompetingInterests($row['competing_interests']);
574  $reviewAssignment->setRegretMessage($row['regret_message']);
575  $reviewAssignment->setRecommendation($row['recommendation']);
576  $reviewAssignment->setDateAssigned($this->datetimeFromDB($row['date_assigned']));
577  $reviewAssignment->setDateNotified($this->datetimeFromDB($row['date_notified']));
578  $reviewAssignment->setDateConfirmed($this->datetimeFromDB($row['date_confirmed']));
579  $reviewAssignment->setDateCompleted($this->datetimeFromDB($row['date_completed']));
580  $reviewAssignment->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
581  $reviewAssignment->setDateDue($this->datetimeFromDB($row['date_due']));
582  $reviewAssignment->setDateResponseDue($this->datetimeFromDB($row['date_response_due']));
583  $reviewAssignment->setLastModified($this->datetimeFromDB($row['last_modified']));
584  $reviewAssignment->setDeclined($row['declined']);
585  $reviewAssignment->setReplaced($row['replaced']);
586  $reviewAssignment->setCancelled($row['cancelled']);
587  $reviewAssignment->setReviewerFileId($row['reviewer_file_id']);
588  $reviewAssignment->setQuality($row['quality']);
589  $reviewAssignment->setDateRated($this->datetimeFromDB($row['date_rated']));
590  $reviewAssignment->setDateReminded($this->datetimeFromDB($row['date_reminded']));
591  $reviewAssignment->setReminderWasAutomatic($row['reminder_was_automatic']);
592  $reviewAssignment->setRound($row['round']);
593  $reviewAssignment->setReviewRevision($row['review_revision']);
594  $reviewAssignment->setReviewFormId($row['review_form_id']);
595  $reviewAssignment->setReviewRoundId($row['review_round_id']);
596  $reviewAssignment->setReviewMethod($row['review_method']);
597  $reviewAssignment->setStageId($row['stage_id']);
598  $reviewAssignment->setUnconsidered($row['unconsidered']);
599 
600  return $reviewAssignment;
601  }
602 
607  function newDataObject() {
608  assert(false); // Should be implemented by subclasses
609  }
610 
611  function deleteReviewAssignmentById($reviewId) {
612  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
613  return $this->deleteById($reviewId);
614  }
615 
620  function deleteById($reviewId) {
621  $reviewFormResponseDao =& DAORegistry::getDAO('ReviewFormResponseDAO');
622  $reviewFormResponseDao->deleteByReviewId($reviewId);
623 
624  return $this->update(
625  'DELETE FROM review_assignments WHERE review_id = ?',
626  (int) $reviewId
627  );
628  }
629 
635  function deleteBySubmissionId($submissionId) {
636  $returner = false;
637  $result =& $this->retrieve(
638  'SELECT review_id FROM review_assignments WHERE submission_id = ?',
639  array((int) $submissionId)
640  );
641 
642  while (!$result->EOF) {
643  $row = $result->GetRowAssoc(false);
644  $reviewId = $row['review_id'];
645 
646  $this->update('DELETE FROM review_form_responses WHERE review_id = ?', $reviewId);
647  $this->update('DELETE FROM review_assignments WHERE review_id = ?', $reviewId);
648 
649  $result->MoveNext();
650  $returner = true;
651  }
652  $result->Close();
653  return $returner;
654  }
655 
660  function getInsertReviewId() {
661  return $this->getInsertId('review_assignments', 'review_id');
662  }
663 }
664 
665 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
& getReviewIndexesForRound($submissionId, $round)
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& getBySubmissionId($submissionId, $round=null, $stageId=null)
updateReviewAssignment(&$reviewAssignment)
& getReviewerIdsBySubmissionId($submissionId, $round=null, $stageId=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
& getReviewAssignment($submissionId, $reviewerId, $round, $stageId=null)
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getDAO($name, $dbconn=null)
Class for DAO relating reviewers to submissions.
& getEarliestNotificationByRound($submissionId)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211