Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ReviewRoundDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.submission.reviewRound.ReviewRound');
18 
19 class ReviewRoundDAO extends DAO {
23  function ReviewRoundDAO() {
24  parent::DAO();
25  }
26 
27  //
28  // Public methods
29  //
38  function build($submissionId, $stageId, $round, $status = null) {
39  // If one exists, fetch and return.
40  $reviewRound = $this->getReviewRound($submissionId, $stageId, $round);
41  if ($reviewRound) return $reviewRound;
42 
43  // Otherwise, check the args to build one.
44  if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW ||
45  $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW &&
46  $round > 0
47  ) {
48  unset($reviewRound);
49  $reviewRound = $this->newDataObject();
50  $reviewRound->setSubmissionId($submissionId);
51  $reviewRound->setRound($round);
52  $reviewRound->setStageId($stageId);
53  $reviewRound->setStatus($status);
54  $this->insertObject($reviewRound);
55  $reviewRound->setId($this->getInsertId());
56 
57  return $reviewRound;
58  } else {
59  assert(false);
60  return null;
61  }
62  }
63 
68  function newDataObject() {
69  return new ReviewRound();
70  }
71 
77  function insertObject($reviewRound) {
78  $this->update(
79  'INSERT INTO review_rounds
80  (submission_id, stage_id, round, status)
81  VALUES
82  (?, ?, ?, ?)',
83  array(
84  (int)$reviewRound->getSubmissionId(),
85  (int)$reviewRound->getStageId(),
86  (int)$reviewRound->getRound(),
87  (int)$reviewRound->getStatus()
88  )
89  );
90  return $reviewRound;
91  }
92 
98  function updateObject($reviewRound) {
99  $returner = $this->update(
100  'UPDATE review_rounds
101  SET status = ?
102  WHERE submission_id = ? AND
103  stage_id = ? AND
104  round = ?',
105  array(
106  (int)$reviewRound->getStatus(),
107  (int)$reviewRound->getSubmissionId(),
108  (int)$reviewRound->getStageId(),
109  (int)$reviewRound->getRound()
110  )
111  );
112  return $returner;
113  }
114 
121  function getReviewRound($submissionId, $stageId, $round) {
122  $result = $this->retrieve(
123  'SELECT * FROM review_rounds WHERE submission_id = ? AND stage_id = ? AND round = ?',
124  array((int) $submissionId, (int) $stageId, (int) $round)
125  );
126 
127  $returner = null;
128  if ($result->RecordCount() != 0) {
129  $returner = $this->_fromRow($result->GetRowAssoc(false));
130  }
131  $result->Close();
132  return $returner;
133  }
134 
140  function getById($reviewRoundId) {
141  $result = $this->retrieve(
142  'SELECT * FROM review_rounds WHERE review_round_id = ?',
143  (int) $reviewRoundId
144  );
145 
146  $returner = null;
147  if ($result->RecordCount() != 0) {
148  $returner = $this->_fromRow($result->GetRowAssoc(false));
149  }
150  $result->Close();
151  return $returner;
152  }
153 
159  function getBySubmissionFileId($submissionFileId) {
160  $result = $this->retrieve(
161  'SELECT * FROM review_rounds rr
162  INNER JOIN review_round_files rrf
163  ON rr.review_round_id = rrf.review_round_id
164  WHERE rrf.file_id = ?',
165  array((int) $submissionFileId));
166 
167  $returner = null;
168  if ($result->RecordCount() != 0) {
169  $returner = $this->_fromRow($result->GetRowAssoc(false));
170  }
171  $result->Close();
172  return $returner;
173  }
174 
181  function getBySubmissionId($submissionId, $stageId = null, $round = null) {
182  $params = array($submissionId);
183  if ($stageId) $params[] = $stageId;
184  if ($round) $params[] = $round;
185 
186  $result = $this->retrieve(
187  'SELECT * FROM review_rounds WHERE submission_id = ?' .
188  ($stageId ? ' AND stage_id = ?' : '') .
189  ($round ? ' AND round = ?' : '') .
190  ' ORDER BY stage_id ASC, round ASC',
191  $params
192  );
193 
194  return new DAOResultFactory($result, $this, '_fromRow');
195  }
196 
203  function getCurrentRoundBySubmissionId($submissionId, $stageId = null) {
204  $params = array((int)$submissionId);
205  if ($stageId) $params[] = (int) $stageId;
206  $result = $this->retrieve(
207  'SELECT MAX(stage_id) as stage_id, MAX(round) as round
208  FROM review_rounds
209  WHERE submission_id = ?' .
210  ($stageId ? ' AND stage_id = ?' : ''),
211  $params
212  );
213  $returner = isset($result->fields['round']) ? (int)$result->fields['round'] : 1;
214  $result->Close();
215  return $returner;
216  }
217 
224  function getLastReviewRoundBySubmissionId($submissionId, $stageId = null) {
225  $params = array((int)$submissionId);
226  if ($stageId) $params[] = (int) $stageId;
227  $result = $this->retrieve(
228  'SELECT *
229  FROM review_rounds
230  WHERE submission_id = ?
231  ' . ($stageId ? ' AND stage_id = ?' : '') . '
232  ORDER BY stage_id DESC, round DESC
233  LIMIT 1',
234  $params
235  );
236 
237  $returner = null;
238  if ($result->RecordCount() != 0) {
239  $returner = $this->_fromRow($result->GetRowAssoc(false));
240  }
241  $result->Close();
242  return $returner;
243  }
244 
249  function getInsertId() {
250  return $this->_getInsertId('review_rounds', 'review_round_id');
251  }
252 
262  function updateStatus($reviewRound, $reviewAssignments = array(), $status = null) {
263  assert(is_a($reviewRound, 'ReviewRound'));
264  $currentStatus = $reviewRound->getStatus();
265 
266  if (is_null($status)) {
267  assert(is_array($reviewAssignments));
268 
269  $viewsDao = DAORegistry::getDAO('ViewsDAO'); /* @var $viewsDao ViewsDAO */
270  $anyUnreadReview = false;
271  $anyIncompletedReview = false;
272 
273  foreach ($reviewAssignments as $reviewAssignment) { /* @var $reviewAssignment ReviewAssignment */
274  // Skip cancelled and declined reviews.
275  if ($reviewAssignment->getCancelled() ||
276  $reviewAssignment->getDeclined()) {
277  continue;
278  }
279 
280  // Check for an incomplete review.
281  if (!$reviewAssignment->getDateCompleted()) {
282  $anyIncompletedReview = true;
283  }
284 
285  // Check for an unread or unconsidered review.
286  if (!$viewsDao->getLastViewDate(ASSOC_TYPE_REVIEW_RESPONSE, $reviewAssignment->getId()) || $reviewAssignment->getUnconsidered() == REVIEW_ASSIGNMENT_UNCONSIDERED) {
287  $anyUnreadReview = true;
288 
289  }
290  }
291 
292  // Find the correct review round status based on the state of
293  // the current review assignments. The check order matters: the
294  // first conditions override the others.
295  if (empty($reviewAssignments)) {
296  $status = REVIEW_ROUND_STATUS_PENDING_REVIEWERS;
297  } else if ($anyIncompletedReview) {
298  $status = REVIEW_ROUND_STATUS_PENDING_REVIEWS;
299  } else if ($anyUnreadReview) {
300  $status = REVIEW_ROUND_STATUS_REVIEWS_READY;
301  } else {
302  $status = REVIEW_ROUND_STATUS_REVIEWS_COMPLETED;
303  }
304 
305  // Check for special cases where we don't want to update the status.
306  if (in_array($status, array(REVIEW_ROUND_STATUS_REVIEWS_COMPLETED, REVIEW_ROUND_STATUS_REVIEWS_READY))) {
307  if (in_array($reviewRound->getStatus(), $this->getEditorDecisionRoundStatus())) {
308  // We will skip changing the current review round status to
309  // "reviews completed" or "reviews ready" if the current round
310  // status is related with an editor decision.
311  return;
312  }
313  }
314 
315  // Don't update the review round status if it isn't the
316  // stage's current one.
317  $lastReviewRound = $this->getLastReviewRoundBySubmissionId($reviewRound->getSubmissionId(), $reviewRound->getStageId());
318  if ($lastReviewRound->getId() != $reviewRound->getId()) {
319  return;
320  }
321  }
322 
323  // Avoid unnecessary database access.
324  if ($status != $currentStatus) {
325  $this->update('UPDATE review_rounds SET status = ? WHERE review_round_id = ?',
326  array((int)$status, (int)$reviewRound->getId())
327  );
328  // Update the data in object too.
329  $reviewRound->setStatus($status);
330  }
331  }
332 
339  return array(
340  REVIEW_ROUND_STATUS_REVISIONS_REQUESTED,
341  REVIEW_ROUND_STATUS_RESUBMITTED,
342  REVIEW_ROUND_STATUS_SENT_TO_EXTERNAL,
343  REVIEW_ROUND_STATUS_ACCEPTED,
344  REVIEW_ROUND_STATUS_DECLINED
345  );
346  }
347 
348 
353  function deleteBySubmissionId($submissionId) {
354  $reviewRounds = $this->getBySubmissionId($submissionId);
355  while ($reviewRound = $reviewRounds->next()) {
356  $this->deleteObject($reviewRound);
357  }
358  }
359 
364  function deleteObject($reviewRound) {
365  $this->deleteById($reviewRound->getId());
366  }
367 
373  function deleteById($reviewRoundId) {
374  $this->update('DELETE FROM notifications WHERE assoc_type = ? AND assoc_id = ?', array((int) ASSOC_TYPE_REVIEW_ROUND, (int) $reviewRoundId));
375  return $this->update('DELETE FROM review_rounds WHERE review_round_id = ?', array((int) $reviewRoundId));
376  }
377 
378  //
379  // Private methods
380  //
386  function _fromRow($row) {
387  $reviewRound = $this->newDataObject();
388 
389  $reviewRound->setId((int)$row['review_round_id']);
390  $reviewRound->setSubmissionId((int)$row['submission_id']);
391  $reviewRound->setStageId((int)$row['stage_id']);
392  $reviewRound->setRound((int)$row['round']);
393  $reviewRound->setStatus((int)$row['status']);
394 
395  return $reviewRound;
396  }
397 }
398 
399 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getReviewRound($submissionId, $stageId, $round)
insertObject($reviewRound)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getCurrentRoundBySubmissionId($submissionId, $stageId=null)
getById($reviewRoundId)
deleteById($reviewRoundId)
Operations for retrieving and modifying ReviewRound objects.
Basic class describing a review round.
deleteObject($reviewRound)
getLastReviewRoundBySubmissionId($submissionId, $stageId=null)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getBySubmissionFileId($submissionFileId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteBySubmissionId($submissionId)
getBySubmissionId($submissionId, $stageId=null, $round=null)
updateObject($reviewRound)
updateStatus($reviewRound, $reviewAssignments=array(), $status=null)
build($submissionId, $stageId, $round, $status=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208