Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
ReviewAssignmentDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.submission.reviewAssignment.ReviewAssignment');
19 
20 class ReviewAssignmentDAO extends DAO {
21  var $userDao;
22 
26  function ReviewAssignmentDAO() {
27  parent::DAO();
28  $this->userDao = DAORegistry::getDAO('UserDAO');
29  }
30 
31 
38  function getByReviewRoundId($reviewRoundId, $excludeCancelled = false) {
39  $params = array((int)$reviewRoundId);
40 
41  $query = $this->_getSelectQuery() .
42  ' WHERE r.review_round_id = ?';
43 
44  if ($excludeCancelled) {
45  $query .= ' AND (r.cancelled = 0 OR r.cancelled IS NULL)';
46  }
47 
48  $query .= ' ORDER BY review_id';
49 
50  return $this->_getReviewAssignmentsArray($query, $params);
51  }
52 
60  function _getReviewAssignmentsArray($query, $queryParams) {
61  $reviewAssignments = array();
62 
63  $result = $this->retrieve($query, $queryParams);
64 
65  while (!$result->EOF) {
66  $reviewAssignments[$result->fields['review_id']] = $this->_fromRow($result->GetRowAssoc(false));
67  $result->MoveNext();
68  }
69 
70  $result->Close();
71  return $reviewAssignments;
72  }
73 
79  function getReviewRoundJoin() {
80  return 'r.review_round_id = r2.review_round_id';
81  }
82 
83 
84  //
85  // Public methods.
86  //
93  function getReviewAssignment($reviewRoundId, $reviewerId) {
94  $result = $this->retrieve(
95  $this->_getSelectQuery() .
96  ' WHERE r.review_round_id = ? AND
97  r.reviewer_id = ? AND
98  r.cancelled <> 1',
99  array(
100  (int) $reviewRoundId,
101  (int) $reviewerId
102  )
103  );
104 
105  $returner = null;
106  if ($result->RecordCount() != 0) {
107  $returner = $this->_fromRow($result->GetRowAssoc(false));
108  }
109 
110  $result->Close();
111  return $returner;
112  }
113 
114 
120  function getById($reviewId) {
121  $reviewRoundJoinString = $this->getReviewRoundJoin();
122  if ($reviewRoundJoinString) {
123  $result = $this->retrieve(
124  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
125  FROM review_assignments r
126  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
127  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
128  WHERE r.review_id = ?',
129  (int) $reviewId
130  );
131 
132  $returner = null;
133  if ($result->RecordCount() != 0) {
134  $returner = $this->_fromRow($result->GetRowAssoc(false));
135  }
136 
137  $result->Close();
138  return $returner;
139  } else {
140  assert(false);
141  }
142  }
143 
150  $reviewAssignments = array();
151  $reviewRoundJoinString = $this->getReviewRoundJoin();
152  if ($reviewRoundJoinString) {
153  $result = $this->retrieve(
154  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
155  FROM review_assignments r
156  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
157  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
159  ' ORDER BY r.submission_id'
160  );
161 
162  while (!$result->EOF) {
163  $reviewAssignments[] = $this->_fromRow($result->GetRowAssoc(false));
164  $result->MoveNext();
165  }
166 
167  $result->Close();
168  } else {
169  assert(false);
170  }
171 
172  return $reviewAssignments;
173  }
174 
181  return ' (r.cancelled IS NULL OR r.cancelled = 0) AND
182  r.date_notified IS NOT NULL AND
183  r.date_completed IS NULL AND
184  r.declined <> 1';
185  }
186 
194  function getBySubmissionId($submissionId, $reviewRoundId = null, $stageId = null) {
195  $query = $this->_getSelectQuery() .
196  ' WHERE r.submission_id = ?';
197 
198  $orderBy = ' ORDER BY review_id';
199 
200  $queryParams[] = (int) $submissionId;
201 
202  if ($reviewRoundId != null) {
203  $query .= ' AND r2.review_round_id = ?';
204  $queryParams[] = (int) $reviewRoundId;
205  } else {
206  $orderBy .= ', r2.review_round_id';
207  }
208 
209  if ($stageId != null) {
210  $query .= ' AND r2.stage_id = ?';
211  $queryParams[] = (int) $stageId;
212  } else {
213  $orderBy .= ', r2.stage_id';
214  }
215 
216  $query .= $orderBy;
217 
218  return $this->_getReviewAssignmentsArray($query, $queryParams);
219  }
220 
226  function getByUserId($userId) {
227  $reviewAssignments = array();
228  $reviewRoundJoinString = $this->getReviewRoundJoin();
229 
230  if ($reviewRoundJoinString) {
231  $result = $this->retrieve(
232  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
233  FROM review_assignments r
234  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
235  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
236  WHERE r.reviewer_id = ?
237  ORDER BY round, review_id',
238  (int) $userId
239  );
240 
241  while (!$result->EOF) {
242  $reviewAssignments[] = $this->_fromRow($result->GetRowAssoc(false));
243  $result->MoveNext();
244  }
245 
246  $result->Close();
247  } else {
248  assert(false);
249  }
250 
251  return $reviewAssignments;
252  }
253 
260  function reviewerExists($reviewRoundId, $reviewerId) {
261  $result = $this->retrieve(
262  'SELECT COUNT(*)
263  FROM review_assignments
264  WHERE review_round_id = ? AND
265  reviewer_id = ? AND
266  cancelled = 0',
267  array((int) $reviewRoundId, (int) $reviewerId)
268  );
269  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
270 
271  $result->Close();
272  return $returner;
273  }
274 
280  function getByReviewFormId($reviewFormId) {
281  $reviewAssignments = array();
282  $reviewRoundJoinString = $this->getReviewRoundJoin();
283 
284  if ($reviewRoundJoinString) {
285  $result = $this->retrieve(
286  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
287  FROM review_assignments r
288  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
289  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
290  WHERE r.review_form_id = ?
291  ORDER BY round, review_id',
292  (int) $reviewFormId
293  );
294 
295  while (!$result->EOF) {
296  $reviewAssignments[] = $this->_fromRow($result->GetRowAssoc(false));
297  $result->MoveNext();
298  }
299 
300  $result->Close();
301  } else {
302  assert(false);
303  }
304 
305  return $reviewAssignments;
306  }
307 
313  function getCancelsAndRegrets($submissionId) {
314  $reviewAssignments = array();
315  $reviewRoundJoinString = $this->getReviewRoundJoin();
316 
317  if ($reviewRoundJoinString) {
318  $result = $this->retrieve(
319  'SELECT r.*, r2.review_revision, u.first_name, u.last_name
320  FROM review_assignments r
321  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
322  LEFT JOIN review_rounds r2 ON (' . $reviewRoundJoinString . ')
323  WHERE r.submission_id = ? AND
324  (r.cancelled = 1 OR r.declined = 1)
325  ORDER BY round, review_id',
326  (int) $submissionId
327  );
328 
329  while (!$result->EOF) {
330  $reviewAssignments[] = $this->_fromRow($result->GetRowAssoc(false));
331  $result->MoveNext();
332  }
333 
334  $result->Close();
335  } else {
336  assert(false);
337  }
338 
339  return $reviewAssignments;
340  }
341 
348  function getReviewIndexesForRound($submissionId, $reviewRoundId) {
349  $result = $this->retrieve(
350  'SELECT review_id
351  FROM review_assignments
352  WHERE submission_id = ? AND
353  review_round_id = ? AND
354  (cancelled = 0 OR cancelled IS NULL)
355  ORDER BY review_id',
356  array((int) $submissionId, (int) $reviewRoundId)
357  );
358 
359  $index = 0;
360  $returner = array();
361  while (!$result->EOF) {
362  $row = $result->GetRowAssoc(false);
363  $returner[$row['review_id']] = $index++;
364  $result->MoveNext();
365  }
366 
367  $result->Close();
368  return $returner;
369  }
370 
375  function insertObject($reviewAssignment) {
376  $this->update(
377  sprintf('INSERT INTO review_assignments (
378  submission_id,
379  reviewer_id,
380  stage_id,
381  review_method,
382  round,
383  competing_interests,
384  recommendation,
385  declined, replaced, cancelled,
386  date_assigned, date_notified, date_confirmed,
387  date_completed, date_acknowledged, date_due, date_response_due,
388  quality, date_rated,
389  last_modified,
390  date_reminded, reminder_was_automatic,
391  review_form_id,
392  review_round_id,
393  unconsidered
394  ) VALUES (
395  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, %s, %s, %s, %s, %s, %s, %s, ?, %s, %s, %s, ?, ?, ?, ?
396  )',
397  $this->datetimeToDB($reviewAssignment->getDateAssigned()),
398  $this->datetimeToDB($reviewAssignment->getDateNotified()),
399  $this->datetimeToDB($reviewAssignment->getDateConfirmed()),
400  $this->datetimeToDB($reviewAssignment->getDateCompleted()),
401  $this->datetimeToDB($reviewAssignment->getDateAcknowledged()),
402  $this->datetimeToDB($reviewAssignment->getDateDue()),
403  $this->datetimeToDB($reviewAssignment->getDateResponseDue()),
404  $this->datetimeToDB($reviewAssignment->getDateRated()),
405  $this->datetimeToDB($reviewAssignment->getLastModified()),
406  $this->datetimeToDB($reviewAssignment->getDateReminded())
407  ), array(
408  (int) $reviewAssignment->getSubmissionId(),
409  (int) $reviewAssignment->getReviewerId(),
410  (int) $reviewAssignment->getStageId(),
411  (int) $reviewAssignment->getReviewMethod(),
412  max((int) $reviewAssignment->getRound(), 1),
413  $reviewAssignment->getCompetingInterests(),
414  $reviewAssignment->getRecommendation(),
415  (int) $reviewAssignment->getDeclined(),
416  (int) $reviewAssignment->getReplaced(),
417  (int) $reviewAssignment->getCancelled(),
418  $reviewAssignment->getQuality(),
419  (int) $reviewAssignment->getReminderWasAutomatic(),
420  $reviewAssignment->getReviewFormId(),
421  (int) $reviewAssignment->getReviewRoundId(),
422  (int) $reviewAssignment->getUnconsidered(),
423  )
424  );
425 
426  $reviewAssignment->setId($this->getInsertId());
427  return $reviewAssignment->getId();
428  }
429 
434  function updateObject($reviewAssignment) {
435  return $this->update(
436  sprintf('UPDATE review_assignments
437  SET submission_id = ?,
438  reviewer_id = ?,
439  stage_id = ?,
440  review_method = ?,
441  round = ?,
442  competing_interests = ?,
443  recommendation = ?,
444  declined = ?,
445  replaced = ?,
446  cancelled = ?,
447  date_assigned = %s,
448  date_notified = %s,
449  date_confirmed = %s,
450  date_completed = %s,
451  date_acknowledged = %s,
452  date_due = %s,
453  date_response_due = %s,
454  quality = ?,
455  date_rated = %s,
456  last_modified = %s,
457  date_reminded = %s,
458  reminder_was_automatic = ?,
459  review_form_id = ?,
460  review_round_id = ?,
461  unconsidered = ?
462  WHERE review_id = ?',
463  $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())),
464  array(
465  (int) $reviewAssignment->getSubmissionId(),
466  (int) $reviewAssignment->getReviewerId(),
467  (int) $reviewAssignment->getStageId(),
468  (int) $reviewAssignment->getReviewMethod(),
469  (int) $reviewAssignment->getRound(),
470  $reviewAssignment->getCompetingInterests(),
471  $reviewAssignment->getRecommendation(),
472  (int) $reviewAssignment->getDeclined(),
473  (int) $reviewAssignment->getReplaced(),
474  (int) $reviewAssignment->getCancelled(),
475  $reviewAssignment->getQuality(),
476  $reviewAssignment->getReminderWasAutomatic(),
477  $reviewAssignment->getReviewFormId(),
478  (int) $reviewAssignment->getReviewRoundId(),
479  (int) $reviewAssignment->getUnconsidered(),
480  (int) $reviewAssignment->getId()
481  )
482  );
483  }
484 
490  function _fromRow($row) {
491  $reviewAssignment = $this->newDataObject();
492 
493  $reviewAssignment->setId($row['review_id']);
494  $reviewAssignment->setSubmissionId($row['submission_id']);
495  $reviewAssignment->setReviewerId($row['reviewer_id']);
496  $reviewAssignment->setReviewerFullName($row['first_name'].' '.$row['last_name']);
497  $reviewAssignment->setCompetingInterests($row['competing_interests']);
498  $reviewAssignment->setRecommendation($row['recommendation']);
499  $reviewAssignment->setDateAssigned($this->datetimeFromDB($row['date_assigned']));
500  $reviewAssignment->setDateNotified($this->datetimeFromDB($row['date_notified']));
501  $reviewAssignment->setDateConfirmed($this->datetimeFromDB($row['date_confirmed']));
502  $reviewAssignment->setDateCompleted($this->datetimeFromDB($row['date_completed']));
503  $reviewAssignment->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
504  $reviewAssignment->setDateDue($this->datetimeFromDB($row['date_due']));
505  $reviewAssignment->setDateResponseDue($this->datetimeFromDB($row['date_response_due']));
506  $reviewAssignment->setLastModified($this->datetimeFromDB($row['last_modified']));
507  $reviewAssignment->setDeclined($row['declined']);
508  $reviewAssignment->setReplaced($row['replaced']);
509  $reviewAssignment->setCancelled($row['cancelled']);
510  $reviewAssignment->setQuality($row['quality']);
511  $reviewAssignment->setDateRated($this->datetimeFromDB($row['date_rated']));
512  $reviewAssignment->setDateReminded($this->datetimeFromDB($row['date_reminded']));
513  $reviewAssignment->setReminderWasAutomatic($row['reminder_was_automatic']);
514  $reviewAssignment->setRound($row['round']);
515  $reviewAssignment->setReviewFormId($row['review_form_id']);
516  $reviewAssignment->setReviewRoundId($row['review_round_id']);
517  $reviewAssignment->setReviewMethod($row['review_method']);
518  $reviewAssignment->setStageId($row['stage_id']);
519  $reviewAssignment->setUnconsidered($row['unconsidered']);
520 
521  return $reviewAssignment;
522  }
523 
528  function newDataObject() {
529  return new ReviewAssignment();
530  }
531 
536  function deleteById($reviewId) {
537  $reviewFormResponseDao = DAORegistry::getDAO('ReviewFormResponseDAO');
538  $reviewFormResponseDao->deleteByReviewId($reviewId);
539 
540  $reviewFilesDao = DAORegistry::getDAO('ReviewFilesDAO');
541  $reviewFilesDao->revokeByReviewId($reviewId);
542 
543  $notificationDao = DAORegistry::getDAO('NotificationDAO');
544  $notificationDao->deleteByAssoc(ASSOC_TYPE_REVIEW_ASSIGNMENT, $reviewId);
545 
546  return $this->update(
547  'DELETE FROM review_assignments WHERE review_id = ?',
548  (int) $reviewId
549  );
550  }
551 
557  function deleteBySubmissionId($submissionId) {
558  $returner = false;
559  $result = $this->retrieve(
560  'SELECT review_id FROM review_assignments WHERE submission_id = ?',
561  array((int) $submissionId)
562  );
563 
564  while (!$result->EOF) {
565  $row = $result->GetRowAssoc(false);
566  $this->deleteById($row['review_id']);
567  $result->MoveNext();
568  $returner = true;
569  }
570  $result->Close();
571  return $returner;
572  }
573 
578  function getInsertId() {
579  return $this->_getInsertId('review_assignments', 'review_id');
580  }
581 
588  function getLastReviewRoundReviewAssignmentByReviewer($submissionId, $reviewerId) {
589  $params = array(
590  (int) $submissionId,
591  (int) $reviewerId
592  );
593 
594  $result = $this->retrieve(
595  $this->_getSelectQuery() .
596  ' WHERE r.submission_id = ? AND
597  r.reviewer_id = ? AND
598  r.cancelled <> 1
599  ORDER BY r2.stage_id DESC, r2.round DESC LIMIT 1',
600  $params
601  );
602 
603  $returner = null;
604  if ($result->RecordCount() != 0) {
605  $returner = $this->_fromRow($result->GetRowAssoc(false));
606  }
607 
608  $result->Close();
609  return $returner;
610  }
611 
617  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_EDITOR);
618  return array(
619  SUBMISSION_REVIEW_METHOD_DOUBLEBLIND => 'editor.submissionReview.doubleBlind',
620  SUBMISSION_REVIEW_METHOD_BLIND => 'editor.submissionReview.blind',
621  SUBMISSION_REVIEW_METHOD_OPEN => 'editor.submissionReview.open',
622  );
623  }
624 
629  function _getSelectQuery() {
630  return 'SELECT r.*, r2.review_revision, u.first_name, u.last_name FROM review_assignments r
631  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
632  LEFT JOIN review_rounds r2 ON (r.review_round_id = r2.review_round_id)';
633  }
634 }
635 
636 ?>
static & getDAO($name, $dbconn=null)
getReviewIndexesForRound($submissionId, $reviewRoundId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getByReviewRoundId($reviewRoundId, $excludeCancelled=false)
insertObject($reviewAssignment)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getLastReviewRoundReviewAssignmentByReviewer($submissionId, $reviewerId)
static requireComponents()
updateObject($reviewAssignment)
getReviewAssignment($reviewRoundId, $reviewerId)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getBySubmissionId($submissionId, $reviewRoundId=null, $stageId=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
_getReviewAssignmentsArray($query, $queryParams)
reviewerExists($reviewRoundId, $reviewerId)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Describes review assignment properties.
Class for DAO relating reviewers to submissions.