Open Journal Systems  3.3.0
ReviewRoundDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.submission.reviewRound.ReviewRound');
18 
19 class ReviewRoundDAO extends DAO {
20 
21  //
22  // Public methods
23  //
32  function build($submissionId, $stageId, $round, $status = null) {
33  // If one exists, fetch and return.
34  $reviewRound = $this->getReviewRound($submissionId, $stageId, $round);
35  if ($reviewRound) return $reviewRound;
36 
37  // Otherwise, check the args to build one.
38  if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW ||
39  $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW &&
40  $round > 0
41  ) {
42  unset($reviewRound);
43  $reviewRound = $this->newDataObject();
44  $reviewRound->setSubmissionId($submissionId);
45  $reviewRound->setRound($round);
46  $reviewRound->setStageId($stageId);
47  $reviewRound->setStatus($status);
48  $this->insertObject($reviewRound);
49  $reviewRound->setId($this->getInsertId());
50 
51  return $reviewRound;
52  } else {
53  assert(false);
54  return null;
55  }
56  }
57 
62  function newDataObject() {
63  return new ReviewRound();
64  }
65 
71  function insertObject($reviewRound) {
72  $this->update(
73  'INSERT INTO review_rounds
74  (submission_id, stage_id, round, status)
75  VALUES
76  (?, ?, ?, ?)',
77  array(
78  (int)$reviewRound->getSubmissionId(),
79  (int)$reviewRound->getStageId(),
80  (int)$reviewRound->getRound(),
81  (int)$reviewRound->getStatus()
82  )
83  );
84  return $reviewRound;
85  }
86 
92  function updateObject($reviewRound) {
93  $returner = $this->update(
94  'UPDATE review_rounds
95  SET status = ?
96  WHERE submission_id = ? AND
97  stage_id = ? AND
98  round = ?',
99  array(
100  (int)$reviewRound->getStatus(),
101  (int)$reviewRound->getSubmissionId(),
102  (int)$reviewRound->getStageId(),
103  (int)$reviewRound->getRound()
104  )
105  );
106  return $returner;
107  }
108 
115  function getReviewRound($submissionId, $stageId, $round) {
116  $result = $this->retrieve(
117  'SELECT * FROM review_rounds WHERE submission_id = ? AND stage_id = ? AND round = ?',
118  array((int) $submissionId, (int) $stageId, (int) $round)
119  );
120 
121  $returner = null;
122  if ($result->RecordCount() != 0) {
123  $returner = $this->_fromRow($result->GetRowAssoc(false));
124  }
125  $result->Close();
126  return $returner;
127  }
128 
134  function getById($reviewRoundId) {
135  $result = $this->retrieve(
136  'SELECT * FROM review_rounds WHERE review_round_id = ?',
137  (int) $reviewRoundId
138  );
139 
140  $returner = null;
141  if ($result->RecordCount() != 0) {
142  $returner = $this->_fromRow($result->GetRowAssoc(false));
143  }
144  $result->Close();
145  return $returner;
146  }
147 
153  function getBySubmissionFileId($submissionFileId) {
154  $result = $this->retrieve(
155  'SELECT * FROM review_rounds rr
156  INNER JOIN review_round_files rrf
157  ON rr.review_round_id = rrf.review_round_id
158  WHERE rrf.file_id = ?',
159  array((int) $submissionFileId));
160 
161  $returner = null;
162  if ($result->RecordCount() != 0) {
163  $returner = $this->_fromRow($result->GetRowAssoc(false));
164  }
165  $result->Close();
166  return $returner;
167  }
168 
175  function getBySubmissionId($submissionId, $stageId = null, $round = null) {
176  $params = array($submissionId);
177  if ($stageId) $params[] = $stageId;
178  if ($round) $params[] = $round;
179 
180  $result = $this->retrieve(
181  'SELECT * FROM review_rounds WHERE submission_id = ?' .
182  ($stageId ? ' AND stage_id = ?' : '') .
183  ($round ? ' AND round = ?' : '') .
184  ' ORDER BY stage_id ASC, round ASC',
185  $params
186  );
187 
188  return new DAOResultFactory($result, $this, '_fromRow');
189  }
190 
197  function getCurrentRoundBySubmissionId($submissionId, $stageId = null) {
198  $params = array((int)$submissionId);
199  if ($stageId) $params[] = (int) $stageId;
200  $result = $this->retrieve(
201  'SELECT MAX(stage_id) as stage_id, MAX(round) as round
202  FROM review_rounds
203  WHERE submission_id = ?' .
204  ($stageId ? ' AND stage_id = ?' : ''),
205  $params
206  );
207  $returner = isset($result->fields['round']) ? (int)$result->fields['round'] : 1;
208  $result->Close();
209  return $returner;
210  }
211 
218  function getLastReviewRoundBySubmissionId($submissionId, $stageId = null) {
219  $params = array((int)$submissionId);
220  if ($stageId) $params[] = (int) $stageId;
221  $result = $this->retrieveLimit(
222  'SELECT *
223  FROM review_rounds
224  WHERE submission_id = ?
225  ' . ($stageId ? ' AND stage_id = ?' : '') . '
226  ORDER BY stage_id DESC, round DESC',
227  $params,
228  1
229  );
230 
231  $returner = null;
232  if ($result->RecordCount() != 0) {
233  $returner = $this->_fromRow($result->GetRowAssoc(false));
234  }
235  $result->Close();
236  return $returner;
237  }
238 
243  function getInsertId() {
244  return $this->_getInsertId('review_rounds', 'review_round_id');
245  }
246 
255  function updateStatus($reviewRound, $status = null) {
256  assert(is_a($reviewRound, 'ReviewRound'));
257  $currentStatus = $reviewRound->getStatus();
258 
259  if (is_null($status)) {
260  $status = $reviewRound->determineStatus();
261  }
262 
263  // Avoid unnecessary database access.
264  if ($status != $currentStatus) {
265  $this->update('UPDATE review_rounds SET status = ? WHERE review_round_id = ?',
266  array((int)$status, (int)$reviewRound->getId())
267  );
268  // Update the data in object too.
269  $reviewRound->setStatus($status);
270  }
271  }
272 
273 
278  function deleteBySubmissionId($submissionId) {
279  $reviewRounds = $this->getBySubmissionId($submissionId);
280  while ($reviewRound = $reviewRounds->next()) {
281  $this->deleteObject($reviewRound);
282  }
283  }
284 
289  function deleteObject($reviewRound) {
290  $this->deleteById($reviewRound->getId());
291  }
292 
298  function deleteById($reviewRoundId) {
299  $this->update('DELETE FROM notifications WHERE assoc_type = ? AND assoc_id = ?', array((int) ASSOC_TYPE_REVIEW_ROUND, (int) $reviewRoundId));
300  return $this->update('DELETE FROM review_rounds WHERE review_round_id = ?', array((int) $reviewRoundId));
301  }
302 
303  //
304  // Private methods
305  //
311  function _fromRow($row) {
312  $reviewRound = $this->newDataObject();
313 
314  $reviewRound->setId((int)$row['review_round_id']);
315  $reviewRound->setSubmissionId((int)$row['submission_id']);
316  $reviewRound->setStageId((int)$row['stage_id']);
317  $reviewRound->setRound((int)$row['round']);
318  $reviewRound->setStatus((int)$row['status']);
319 
320  return $reviewRound;
321  }
322 }
323 
324 
ReviewRoundDAO\updateObject
updateObject($reviewRound)
Definition: ReviewRoundDAO.inc.php:92
ReviewRoundDAO\deleteObject
deleteObject($reviewRound)
Definition: ReviewRoundDAO.inc.php:289
ReviewRoundDAO\getInsertId
getInsertId()
Definition: ReviewRoundDAO.inc.php:243
ReviewRoundDAO\deleteBySubmissionId
deleteBySubmissionId($submissionId)
Definition: ReviewRoundDAO.inc.php:278
ReviewRoundDAO\getCurrentRoundBySubmissionId
getCurrentRoundBySubmissionId($submissionId, $stageId=null)
Definition: ReviewRoundDAO.inc.php:197
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
ReviewRoundDAO\getBySubmissionFileId
getBySubmissionFileId($submissionFileId)
Definition: ReviewRoundDAO.inc.php:153
ReviewRound
Basic class describing a review round.
Definition: ReviewRound.inc.php:48
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
ReviewRoundDAO
Operations for retrieving and modifying ReviewRound objects.
Definition: ReviewRoundDAO.inc.php:19
ReviewRoundDAO\getBySubmissionId
getBySubmissionId($submissionId, $stageId=null, $round=null)
Definition: ReviewRoundDAO.inc.php:175
ReviewRoundDAO\insertObject
insertObject($reviewRound)
Definition: ReviewRoundDAO.inc.php:71
ReviewRoundDAO\getLastReviewRoundBySubmissionId
getLastReviewRoundBySubmissionId($submissionId, $stageId=null)
Definition: ReviewRoundDAO.inc.php:218
ReviewRoundDAO\getReviewRound
getReviewRound($submissionId, $stageId, $round)
Definition: ReviewRoundDAO.inc.php:115
ReviewRoundDAO\getById
getById($reviewRoundId)
Definition: ReviewRoundDAO.inc.php:134
ReviewRoundDAO\build
build($submissionId, $stageId, $round, $status=null)
Definition: ReviewRoundDAO.inc.php:32
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
ReviewRoundDAO\updateStatus
updateStatus($reviewRound, $status=null)
Definition: ReviewRoundDAO.inc.php:255
ReviewRoundDAO\_fromRow
_fromRow($row)
Definition: ReviewRoundDAO.inc.php:311
ReviewRoundDAO\deleteById
deleteById($reviewRoundId)
Definition: ReviewRoundDAO.inc.php:298
DAO\retrieveLimit
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:148
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
ReviewRoundDAO\newDataObject
newDataObject()
Definition: ReviewRoundDAO.inc.php:62