Open Journal Systems  2.4.8
 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 
201  function &getReviewerSubmissionsByReviewerId($reviewerId, $journalId, $active = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
202  $primaryLocale = AppLocale::getPrimaryLocale();
203  $locale = AppLocale::getLocale();
204  $sql = 'SELECT a.*,
205  r.*,
206  r2.review_revision,
207  u.first_name, u.last_name,
208  COALESCE(atl.setting_value, atpl.setting_value) AS submission_title,
209  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
210  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
211  FROM articles a
212  LEFT JOIN review_assignments r ON (a.article_id = r.submission_id)
213  LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = a.locale)
214  LEFT JOIN article_settings atl ON (atl.article_id = a.article_id AND atl.setting_name = ? AND atl.locale = ?)
215  LEFT JOIN sections s ON (s.section_id = a.section_id)
216  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
217  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
218  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
219  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
220  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
221  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
222  WHERE a.journal_id = ? AND
223  r.reviewer_id = ? AND
224  r.date_notified IS NOT NULL';
225 
226  if ($active) {
227  $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;
228  } else {
229  $sql .= ' AND (r.date_completed IS NOT NULL OR r.cancelled = 1 OR r.declined = 1 OR a.status <> ' . STATUS_QUEUED . ')';
230  }
231 
232  if ($sortBy) {
233  $sql .= ' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection);
234  }
235 
236  $result =& $this->retrieveRange(
237  $sql,
238  array(
239  'cleanTitle', // Article title
240  'cleanTitle',
241  $locale,
242  'title', // Section title
243  $primaryLocale,
244  'title',
245  $locale,
246  'abbrev', // Section abbreviation
247  $primaryLocale,
248  'abbrev',
249  $locale,
250  $journalId,
251  $reviewerId
252  ),
253  $rangeInfo
254  );
255 
256  $returner = new DAOResultFactory($result, $this, '_returnReviewerSubmissionFromRow');
257  return $returner;
258  }
259 
265  function getSubmissionsCount($reviewerId, $journalId) {
266  $submissionsCount = array();
267  $submissionsCount[0] = 0;
268  $submissionsCount[1] = 0;
269 
270  $sql = 'SELECT r.date_completed, r.declined, r.cancelled, a.status
271  FROM articles a
272  LEFT JOIN review_assignments r ON (a.article_id = r.submission_id)
273  LEFT JOIN sections s ON (s.section_id = a.section_id)
274  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
275  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.round = r2.round)
276  WHERE a.journal_id = ? AND
277  r.reviewer_id = ? AND
278  r.date_notified IS NOT NULL';
279 
280  $result =& $this->retrieve($sql, array($journalId, $reviewerId));
281 
282  while (!$result->EOF) {
283  if ($result->fields['date_completed'] == null && $result->fields['declined'] != 1 && $result->fields['cancelled'] != 1 && $result->fields['status'] == STATUS_QUEUED) {
284  $submissionsCount[0] += 1;
285  } else {
286  $submissionsCount[1] += 1;
287  }
288  $result->moveNext();
289  }
290 
291  $result->Close();
292  unset($result);
293 
294  return $submissionsCount;
295  }
296 
302  function getEditorDecisions($articleId, $round = null) {
303  $decisions = array();
304 
305  if ($round == null) {
306  $result =& $this->retrieve(
307  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? ORDER BY date_decided ASC', $articleId
308  );
309  } else {
310  $result =& $this->retrieve(
311  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? AND round = ? ORDER BY date_decided ASC',
312  array($articleId, $round)
313  );
314  }
315 
316  while (!$result->EOF) {
317  $decisions[] = array(
318  'editDecisionId' => $result->fields['edit_decision_id'],
319  'editorId' => $result->fields['editor_id'],
320  'decision' => $result->fields['decision'],
321  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
322  );
323  $result->moveNext();
324  }
325 
326  $result->Close();
327  unset($result);
328 
329  return $decisions;
330  }
331 
337  function getSortMapping($heading) {
338  switch ($heading) {
339  case 'id': return 'a.article_id';
340  case 'assignDate': return 'r.date_assigned';
341  case 'dueDate': return 'r.date_due';
342  case 'section': return 'section_abbrev';
343  case 'title': return 'submission_title';
344  case 'round': return 'r.round';
345  case 'review': return 'r.recommendation';
346  default: return null;
347  }
348  }
349 }
350 
351 ?>
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)