Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ReviewerSubmissionDAO.inc.php
1 <?php
2 
17 import('classes.monograph.MonographDAO');
18 import('classes.submission.reviewer.ReviewerSubmission');
19 
21  var $authorDao;
22  var $userDao;
23  var $reviewAssignmentDao;
24  var $submissionFileDao;
25  var $submissionCommentDao;
26 
30  function ReviewerSubmissionDAO() {
31  parent::MonographDAO();
32  $this->authorDao = DAORegistry::getDAO('AuthorDAO');
33  $this->userDao = DAORegistry::getDAO('UserDAO');
34  $this->reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
35  $this->submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
36  $this->submissionCommentDao = DAORegistry::getDAO('SubmissionCommentDAO');
37  }
38 
45  function getReviewerSubmission($reviewId) {
46  $primaryLocale = AppLocale::getPrimaryLocale();
47  $locale = AppLocale::getLocale();
48  $result = $this->retrieve(
49  'SELECT m.*, pm.date_published,
50  r.*,
51  u.first_name, u.last_name,
52  COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
53  COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev
54  FROM submissions m
55  LEFT JOIN published_submissions pm ON (m.submission_id = pm.submission_id)
56  LEFT JOIN review_assignments r ON (m.submission_id = r.submission_id)
57  LEFT JOIN series s ON (s.series_id = m.series_id)
58  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
59  LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
60  LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
61  LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
62  LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
63  WHERE r.review_id = ?',
64  array(
65  'title', $primaryLocale, // Series title
66  'title', $locale, // Series title
67  'abbrev', $primaryLocale, // Series abbreviation
68  'abbrev', $locale, // Series abbreviation
69  (int) $reviewId
70  )
71  );
72 
73  $returner = null;
74  if ($result->RecordCount() != 0) {
75  $returner = $this->_fromRow($result->GetRowAssoc(false));
76  }
77 
78  $result->Close();
79  return $returner;
80  }
81 
86  function newDataObject() {
87  return new ReviewerSubmission();
88  }
89 
95  function _fromRow($row) {
96  // Get the ReviewerSubmission object, populated with Monograph data
97  $reviewerSubmission = parent::_fromRow($row);
98 
99  // Editor Decisions
100  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO');
101  $decisions = $editDecisionDao->getEditorDecisions($row['submission_id']);
102  $reviewerSubmission->setDecisions($decisions);
103 
104  // Review Assignment
105  $reviewerSubmission->setReviewId($row['review_id']);
106  $reviewerSubmission->setReviewerId($row['reviewer_id']);
107  $reviewerSubmission->setReviewerFullName($row['first_name'].' '.$row['last_name']);
108  $reviewerSubmission->setCompetingInterests($row['competing_interests']);
109  $reviewerSubmission->setRecommendation($row['recommendation']);
110  $reviewerSubmission->setDateAssigned($this->datetimeFromDB($row['date_assigned']));
111  $reviewerSubmission->setDateNotified($this->datetimeFromDB($row['date_notified']));
112  $reviewerSubmission->setDateConfirmed($this->datetimeFromDB($row['date_confirmed']));
113  $reviewerSubmission->setDateCompleted($this->datetimeFromDB($row['date_completed']));
114  $reviewerSubmission->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
115  $reviewerSubmission->setDateDue($this->datetimeFromDB($row['date_due']));
116  $reviewerSubmission->setDateResponseDue($this->datetimeFromDB($row['date_response_due']));
117  $reviewerSubmission->setDeclined($row['declined']);
118  $reviewerSubmission->setReplaced($row['replaced']);
119  $reviewerSubmission->setCancelled((int) $row['cancelled']);
120  $reviewerSubmission->setQuality($row['quality']);
121  $reviewerSubmission->setRound($row['round']);
122  $reviewerSubmission->setStep($row['step']);
123  $reviewerSubmission->setStageId($row['stage_id']);
124  $reviewerSubmission->setReviewMethod($row['review_method']);
125 
126  HookRegistry::call('ReviewerSubmissionDAO::_fromRow', array(&$reviewerSubmission, &$row));
127  return $reviewerSubmission;
128  }
129 
134  function updateReviewerSubmission($reviewerSubmission) {
135  $this->update(
136  sprintf('UPDATE review_assignments
137  SET submission_id = ?,
138  reviewer_id = ?,
139  stage_id = ?,
140  review_method = ?,
141  round = ?,
142  step = ?,
143  competing_interests = ?,
144  recommendation = ?,
145  declined = ?,
146  replaced = ?,
147  cancelled = ?,
148  date_assigned = %s,
149  date_notified = %s,
150  date_confirmed = %s,
151  date_completed = %s,
152  date_acknowledged = %s,
153  date_due = %s,
154  date_response_due = %s,
155  quality = ?
156  WHERE review_id = ?',
157  $this->datetimeToDB($reviewerSubmission->getDateAssigned()),
158  $this->datetimeToDB($reviewerSubmission->getDateNotified()),
159  $this->datetimeToDB($reviewerSubmission->getDateConfirmed()),
160  $this->datetimeToDB($reviewerSubmission->getDateCompleted()),
161  $this->datetimeToDB($reviewerSubmission->getDateAcknowledged()),
162  $this->datetimeToDB($reviewerSubmission->getDateDue()),
163  $this->datetimeToDB($reviewerSubmission->getDateResponseDue())),
164  array(
165  (int) $reviewerSubmission->getId(),
166  (int) $reviewerSubmission->getReviewerId(),
167  (int) $reviewerSubmission->getStageId(),
168  (int) $reviewerSubmission->getReviewMethod(),
169  (int) $reviewerSubmission->getRound(),
170  (int) $reviewerSubmission->getStep(),
171  $reviewerSubmission->getCompetingInterests(),
172  (int) $reviewerSubmission->getRecommendation(),
173  (int) $reviewerSubmission->getDeclined(),
174  (int) $reviewerSubmission->getReplaced(),
175  (int) $reviewerSubmission->getCancelled(),
176  (int) $reviewerSubmission->getQuality(),
177  (int) $reviewerSubmission->getReviewId()
178  )
179  );
180  }
181 
189  function getReviewerSubmissionsByReviewerId($reviewerId, $pressId = null, $active = true, $skipDeclined = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
190  $primaryLocale = AppLocale::getPrimaryLocale();
191  $locale = AppLocale::getLocale();
192  $sql = 'SELECT m.*, pm.date_published,
193  r.*,
194  u.first_name, u.last_name,
195  atl.setting_value AS submission_title,
196  COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
197  COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev
198  FROM submissions m
199  LEFT JOIN published_submissions pm ON (pm.submission_id = m.submission_id)
200  LEFT JOIN review_assignments r ON (m.submission_id = r.submission_id)
201  LEFT JOIN submission_settings atl ON (atl.submission_id = m.submission_id AND atl.setting_name = ? AND atl.locale = ?)
202  LEFT JOIN series s ON (s.series_id = m.series_id)
203  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
204  LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
205  LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
206  LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
207  LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
208  WHERE r.reviewer_id = ? ' . ($pressId? ' AND m.context_id = ? ':'') .
209  'AND r.date_notified IS NOT NULL';
210 
211  if ($active) {
212  $sql .= ' AND r.date_completed IS NULL AND r.declined <> 1 AND (r.cancelled = 0 OR r.cancelled IS NULL)';
213  } else {
214  $sql .= ' AND (r.date_completed IS NOT NULL OR r.cancelled = 1 OR r.declined = 1)';
215  }
216 
217  if ($skipDeclined) {
218  $sql .= ' AND m.status <> ' . STATUS_DECLINED;
219  }
220 
221  if ($sortBy) {
222  $sql .= " ORDER BY $sortBy " . $this->getDirectionMapping($sortDirection);
223  }
224 
225  $params = array(
226  'title', $locale, // Monograph title
227  'title', $primaryLocale, // Series title
228  'title', $locale, // Series title
229  'abbrev', $primaryLocale, // Series abbreviation
230  'abbrev', $locale, // Series abbreviation
231  (int) $reviewerId
232  );
233  if ($pressId) $params[] = (int) $pressId;
234 
235  $result = $this->retrieveRange($sql, $params, $rangeInfo);
236  return new DAOResultFactory($result, $this, '_fromRow');
237  }
238 
245  function getSubmissionsCount($reviewerId, $pressId) {
246  $submissionsCount = array();
247  $submissionsCount[0] = 0;
248  $submissionsCount[1] = 0;
249 
250  $result = $this->retrieve(
251  'SELECT r.date_completed, r.declined, r.cancelled
252  FROM submissions m
253  LEFT JOIN review_assignments r ON (m.submission_id = r.submission_id)
254  LEFT JOIN series s ON (s.series_id = m.series_id)
255  LEFT JOIN users u ON (r.reviewer_id = u.user_id)
256  LEFT JOIN review_rounds r2 ON (r.submission_id = r2.submission_id AND r.stage_id = r2.stage_id AND r.round = r2.round)
257  WHERE m.context_id = ? AND
258  r.reviewer_id = ? AND
259  r.date_notified IS NOT NULL',
260  array((int) $pressId, (int) $reviewerId)
261  );
262 
263  while (!$result->EOF) {
264  if ($result->fields['date_completed'] == null && $result->fields['declined'] != 1 && $result->fields['cancelled'] != 1) {
265  $submissionsCount[0] += 1; // Active
266  } else {
267  $submissionsCount[1] += 1; // Complete
268  }
269  $result->MoveNext();
270  }
271 
272  $result->Close();
273  return $submissionsCount;
274  }
275 
281  function getSortMapping($heading) {
282  switch ($heading) {
283  case 'id': return 'm.submission_id';
284  case 'assignDate': return 'r.date_assigned';
285  case 'dueDate': return 'r.date_due';
286  case 'section': return 'section_abbrev';
287  case 'title': return 'submission_title';
288  case 'round': return 'r.round';
289  case 'review': return 'r.recommendation';
290  case 'decision': return 'editor_decision';
291  default: return null;
292  }
293  }
294 }
295 
296 ?>
static & getDAO($name, $dbconn=null)
updateReviewerSubmission($reviewerSubmission)
static getPrimaryLocale()
Operations for retrieving and modifying Monograph objects.
static getLocale()
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
ReviewerSubmission class.
getSubmissionsCount($reviewerId, $pressId)
Operations for retrieving and modifying ReviewerSubmission objects.
getReviewerSubmissionsByReviewerId($reviewerId, $pressId=null, $active=true, $skipDeclined=true, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)