Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
ReviewerSubmissionDAO.inc.php
1 <?php
2 
17 import('classes.submission.reviewer.ReviewerSubmission');
18 
19 class ReviewerSubmissionDAO extends DAO {
20  var $articleDao;
21  var $authorDao;
22  var $userDao;
23  var $reviewAssignmentDao;
24  var $editAssignmentDao;
25  var $articleFileDao;
26  var $suppFileDao;
27  var $articleCommentDao;
28 
32  function ReviewerSubmissionDAO() {
33  parent::DAO();
34  $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
35  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
36  $this->userDao =& DAORegistry::getDAO('UserDAO');
37  $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
38  $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
39  $this->articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
40  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
41  $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
42  }
43 
50  function &getReviewerSubmission($reviewId) {
51  $primaryLocale = AppLocale::getPrimaryLocale();
52  $locale = AppLocale::getLocale();
53  $result =& $this->retrieve(
54  'SELECT a.*,
55  r.*,
56  r2.review_revision,
57  u.first_name, u.last_name,
58  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
59  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
60  FROM articles a
61  LEFT JOIN review_assignments r ON (a.article_id = r.submission_id)
62  LEFT JOIN sections s ON (s.section_id = a.section_id)
63  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
64  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
65  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
66  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
67  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
68  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
69  WHERE r.review_id = ?',
70  array(
71  'title',
72  $primaryLocale,
73  'title',
74  $locale,
75  'abbrev',
76  $primaryLocale,
77  'abbrev',
78  $locale,
79  $reviewId
80  )
81  );
82 
83  $returner = null;
84  if ($result->RecordCount() != 0) {
85  $returner =& $this->_returnReviewerSubmissionFromRow($result->GetRowAssoc(false));
86  }
87 
88  $result->Close();
89  unset($result);
90 
91  return $returner;
92  }
93 
100  $reviewerSubmission = new ReviewerSubmission();
101 
102  // Editor Assignment
103  $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
104  $reviewerSubmission->setEditAssignments($editAssignments->toArray());
105 
106  // Files
107  $reviewerSubmission->setSubmissionFile($this->articleFileDao->getArticleFile($row['submission_file_id']));
108  $reviewerSubmission->setRevisedFile($this->articleFileDao->getArticleFile($row['revised_file_id']));
109  $reviewerSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
110  $reviewerSubmission->setReviewFile($this->articleFileDao->getArticleFile($row['review_file_id']));
111  $reviewerSubmission->setReviewerFile($this->articleFileDao->getArticleFile($row['reviewer_file_id']));
112  $reviewerSubmission->setReviewerFileRevisions($this->articleFileDao->getArticleFileRevisions($row['reviewer_file_id']));
113 
114  // Comments
115  $reviewerSubmission->setMostRecentPeerReviewComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_PEER_REVIEW, $row['review_id']));
116 
117  // Editor Decisions
118  for ($i = 1; $i <= $row['current_round']; $i++) {
119  $reviewerSubmission->setDecisions($this->getEditorDecisions($row['article_id'], $i), $i);
120  }
121 
122  // Review Assignment
123  $reviewerSubmission->setReviewId($row['review_id']);
124  $reviewerSubmission->setReviewerId($row['reviewer_id']);
125  $reviewerSubmission->setReviewerFullName($row['first_name'].' '.$row['last_name']);
126  $reviewerSubmission->setCompetingInterests($row['competing_interests']);
127  $reviewerSubmission->setRecommendation($row['recommendation']);
128  $reviewerSubmission->setDateAssigned($this->datetimeFromDB($row['date_assigned']));
129  $reviewerSubmission->setDateNotified($this->datetimeFromDB($row['date_notified']));
130  $reviewerSubmission->setDateConfirmed($this->datetimeFromDB($row['date_confirmed']));
131  $reviewerSubmission->setDateCompleted($this->datetimeFromDB($row['date_completed']));
132  $reviewerSubmission->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
133  $reviewerSubmission->setDateDue($this->datetimeFromDB($row['date_due']));
134  $reviewerSubmission->setDeclined($row['declined']);
135  $reviewerSubmission->setReplaced($row['replaced']);
136  $reviewerSubmission->setCancelled($row['cancelled']==1?1:0);
137  $reviewerSubmission->setReviewerFileId($row['reviewer_file_id']);
138  $reviewerSubmission->setQuality($row['quality']);
139  $reviewerSubmission->setRound($row['round']);
140  $reviewerSubmission->setReviewFileId($row['review_file_id']);
141  $reviewerSubmission->setReviewRevision($row['review_revision']);
142 
143  // Article attributes
144  $this->articleDao->_articleFromRow($reviewerSubmission, $row);
145 
146  HookRegistry::call('ReviewerSubmissionDAO::_returnReviewerSubmissionFromRow', array(&$reviewerSubmission, &$row));
147 
148  return $reviewerSubmission;
149  }
150 
155  function updateReviewerSubmission(&$reviewerSubmission) {
156  return $this->update(
157  sprintf('UPDATE review_assignments
158  SET submission_id = ?,
159  reviewer_id = ?,
160  round = ?,
161  competing_interests = ?,
162  recommendation = ?,
163  declined = ?,
164  replaced = ?,
165  cancelled = ?,
166  date_assigned = %s,
167  date_notified = %s,
168  date_confirmed = %s,
169  date_completed = %s,
170  date_acknowledged = %s,
171  date_due = %s,
172  reviewer_file_id = ?,
173  quality = ?
174  WHERE review_id = ?',
175  $this->datetimeToDB($reviewerSubmission->getDateAssigned()), $this->datetimeToDB($reviewerSubmission->getDateNotified()), $this->datetimeToDB($reviewerSubmission->getDateConfirmed()), $this->datetimeToDB($reviewerSubmission->getDateCompleted()), $this->datetimeToDB($reviewerSubmission->getDateAcknowledged()), $this->datetimeToDB($reviewerSubmission->getDateDue())),
176  array(
177  $reviewerSubmission->getId(),
178  $reviewerSubmission->getReviewerId(),
179  $reviewerSubmission->getRound(),
180  $reviewerSubmission->getCompetingInterests(),
181  $reviewerSubmission->getRecommendation(),
182  $reviewerSubmission->getDeclined(),
183  $reviewerSubmission->getReplaced(),
184  $reviewerSubmission->getCancelled(),
185  $reviewerSubmission->getReviewerFileId(),
186  $reviewerSubmission->getQuality(),
187  $reviewerSubmission->getReviewId()
188  )
189  );
190  }
191 
199  function &getReviewerSubmissionsByReviewerId($reviewerId, $journalId, $active = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
200  $primaryLocale = AppLocale::getPrimaryLocale();
201  $locale = AppLocale::getLocale();
202  $sql = 'SELECT a.*,
203  r.*,
204  r2.review_revision,
205  u.first_name, u.last_name,
206  COALESCE(atl.setting_value, atpl.setting_value) AS submission_title,
207  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
208  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
209  FROM articles a
210  LEFT JOIN review_assignments r ON (a.article_id = r.submission_id)
211  LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = a.locale)
212  LEFT JOIN article_settings atl ON (atl.article_id = a.article_id AND atl.setting_name = ? AND atl.locale = ?)
213  LEFT JOIN sections s ON (s.section_id = a.section_id)
214  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
215  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
216  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
217  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
218  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
219  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
220  WHERE a.journal_id = ? AND
221  r.reviewer_id = ? AND
222  r.date_notified IS NOT NULL';
223 
224  if ($active) {
225  $sql .= ' AND r.date_completed IS NULL AND r.declined <> 1 AND (r.cancelled = 0 OR r.cancelled IS NULL) AND a.status = ' . STATUS_QUEUED;
226  } else {
227  $sql .= ' AND (r.date_completed IS NOT NULL OR r.cancelled = 1 OR r.declined = 1 OR a.status <> ' . STATUS_QUEUED . ')';
228  }
229 
230  if ($sortBy) {
231  $sql .= ' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection);
232  }
233 
234  $result =& $this->retrieveRange(
235  $sql,
236  array(
237  'cleanTitle', // Article title
238  'cleanTitle',
239  $locale,
240  'title', // Section title
241  $primaryLocale,
242  'title',
243  $locale,
244  'abbrev', // Section abbreviation
245  $primaryLocale,
246  'abbrev',
247  $locale,
248  $journalId,
249  $reviewerId
250  ),
251  $rangeInfo
252  );
253 
254  $returner = new DAOResultFactory($result, $this, '_returnReviewerSubmissionFromRow');
255  return $returner;
256  }
257 
263  function getSubmissionsCount($reviewerId, $journalId) {
264  $submissionsCount = array();
265  $submissionsCount[0] = 0;
266  $submissionsCount[1] = 0;
267 
268  $sql = 'SELECT r.date_completed, r.declined, r.cancelled, a.status
269  FROM articles a
270  LEFT JOIN review_assignments r ON (a.article_id = r.submission_id)
271  LEFT JOIN sections s ON (s.section_id = a.section_id)
272  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
273  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
274  WHERE a.journal_id = ? AND
275  r.reviewer_id = ? AND
276  r.date_notified IS NOT NULL';
277 
278  $result =& $this->retrieve($sql, array($journalId, $reviewerId));
279 
280  while (!$result->EOF) {
281  if ($result->fields['date_completed'] == null && $result->fields['declined'] != 1 && $result->fields['cancelled'] != 1 && $result->fields['status'] == STATUS_QUEUED) {
282  $submissionsCount[0] += 1;
283  } else {
284  $submissionsCount[1] += 1;
285  }
286  $result->moveNext();
287  }
288 
289  $result->Close();
290  unset($result);
291 
292  return $submissionsCount;
293  }
294 
300  function getEditorDecisions($articleId, $round = null) {
301  $decisions = array();
302 
303  if ($round == null) {
304  $result =& $this->retrieve(
305  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? ORDER BY date_decided ASC', $articleId
306  );
307  } else {
308  $result =& $this->retrieve(
309  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? AND round = ? ORDER BY date_decided ASC',
310  array($articleId, $round)
311  );
312  }
313 
314  while (!$result->EOF) {
315  $decisions[] = array(
316  'editDecisionId' => $result->fields['edit_decision_id'],
317  'editorId' => $result->fields['editor_id'],
318  'decision' => $result->fields['decision'],
319  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
320  );
321  $result->moveNext();
322  }
323 
324  $result->Close();
325  unset($result);
326 
327  return $decisions;
328  }
329 
335  function getSortMapping($heading) {
336  switch ($heading) {
337  case 'id': return 'a.article_id';
338  case 'assignDate': return 'r.date_assigned';
339  case 'dueDate': return 'r.date_due';
340  case 'section': return 'section_abbrev';
341  case 'title': return 'submission_title';
342  case 'round': return 'r.round';
343  case 'review': return 'r.recommendation';
344  default: return null;
345  }
346  }
347 }
348 
349 ?>
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
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
& getReviewerSubmissionsByReviewerId($reviewerId, $journalId, $active=true, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
getSubmissionsCount($reviewerId, $journalId)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getDAO($name, $dbconn=null)
ReviewerSubmission class.
updateReviewerSubmission(&$reviewerSubmission)
Operations for retrieving and modifying ReviewerSubmission objects.
call($hookName, $args=null)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
getDirectionMapping($direction)
Definition: DAO.inc.php:588
getEditorDecisions($articleId, $round=null)