ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

TrackDirectorSubmissionDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
17 // $Id$
18 
19 
20 import('submission.trackDirector.TrackDirectorSubmission');
21 
22 // Bring in director decision constants
23 import('submission.common.Action');
24 import('submission.author.AuthorSubmission');
25 import('submission.reviewer.ReviewerSubmission');
26 
28  var $paperDao;
30  var $userDao;
38 
43  parent::DAO();
44  $this->paperDao =& DAORegistry::getDAO('PaperDAO');
45  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
46  $this->userDao =& DAORegistry::getDAO('UserDAO');
47  $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
48  $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
49  $this->paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
50  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
51  $this->galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
52  $this->paperEmailLogDao =& DAORegistry::getDAO('PaperEmailLogDAO');
53  $this->paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
54  }
55 
61  function &getTrackDirectorSubmission($paperId) {
62  $primaryLocale = AppLocale::getPrimaryLocale();
63  $locale = AppLocale::getLocale();
64  $result =& $this->retrieve(
65  'SELECT p.*,
66  r2.review_revision,
67  COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
68  COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
69  FROM papers p
70  LEFT JOIN tracks t ON (t.track_id = p.track_id)
71  LEFT JOIN review_stages r2 ON (p.paper_id = r2.paper_id AND p.current_stage = r2.stage)
72  LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
73  LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
74  LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
75  LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
76  LEFT JOIN paper_settings sts ON (p.paper_id = sts.paper_id AND sts.setting_name = \'sessionType\')
77  WHERE p.paper_id = ?',
78  array(
79  'title',
80  $primaryLocale,
81  'title',
82  $locale,
83  'abbrev',
84  $primaryLocale,
85  'abbrev',
86  $locale,
87  $paperId
88  )
89  );
90 
91  $returner = null;
92  if ($result->RecordCount() != 0) {
93  $returner =& $this->_returnTrackDirectorSubmissionFromRow($result->GetRowAssoc(false));
94  }
95 
96  $result->Close();
97  unset($result);
98 
99  return $returner;
100  }
101 
108  $trackDirectorSubmission = new TrackDirectorSubmission();
109 
110  // Paper attributes
111  $this->paperDao->_paperFromRow($trackDirectorSubmission, $row);
112 
113  // Director Assignment
114  $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByPaperId($row['paper_id']);
115  $trackDirectorSubmission->setEditAssignments($editAssignments->toArray());
116 
117  // Director Decisions
118  for ($i = 1; $i <= $row['current_stage']; $i++) {
119  $trackDirectorSubmission->setDecisions($this->getDirectorDecisions($row['paper_id'], $i), $i);
120  }
121 
122  // Comments
123  $trackDirectorSubmission->setMostRecentDirectorDecisionComment($this->paperCommentDao->getMostRecentPaperComment($row['paper_id'], COMMENT_TYPE_DIRECTOR_DECISION, $row['paper_id']));
124 
125  // Files
126  $trackDirectorSubmission->setSubmissionFile($this->paperFileDao->getPaperFile($row['submission_file_id']));
127  $trackDirectorSubmission->setRevisedFile($this->paperFileDao->getPaperFile($row['revised_file_id']));
128  $trackDirectorSubmission->setReviewFile($this->paperFileDao->getPaperFile($row['review_file_id']));
129  $trackDirectorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByPaper($row['paper_id']));
130  $trackDirectorSubmission->setDirectorFile($this->paperFileDao->getPaperFile($row['director_file_id']));
131  $trackDirectorSubmission->setLayoutFile($this->paperFileDao->getPaperFile($row['layout_file_id']));
132 
133  for ($i = 1; $i <= $row['current_stage']; $i++) {
134  $trackDirectorSubmission->setDirectorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['director_file_id'], $i), $i);
135  $trackDirectorSubmission->setAuthorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['revised_file_id'], $i), $i);
136  }
137 
138  // Review Stages
139  $trackDirectorSubmission->setReviewRevision($row['review_revision']);
140 
141  // Review Assignments
142  for ($i = 1; $i <= $row['current_stage']; $i++)
143  $trackDirectorSubmission->setReviewAssignments($this->reviewAssignmentDao->getReviewAssignmentsByPaperId($row['paper_id'], $i), $i);
144 
145  $trackDirectorSubmission->setGalleys($this->galleyDao->getGalleysByPaper($row['paper_id']));
146 
147  HookRegistry::call('TrackDirectorSubmissionDAO::_returnTrackDirectorSubmissionFromRow', array(&$trackDirectorSubmission, &$row));
148 
149  return $trackDirectorSubmission;
150  }
151 
156  function updateTrackDirectorSubmission(&$trackDirectorSubmission) {
157  // update edit assignment
158  $editAssignments =& $trackDirectorSubmission->getEditAssignments();
159  foreach ($editAssignments as $editAssignment) {
160  if ($editAssignment->getEditId() > 0) {
161  $this->editAssignmentDao->updateEditAssignment($editAssignment);
162  } else {
163  $this->editAssignmentDao->insertEditAssignment($editAssignment);
164  }
165  }
166 
167  // Update director decisions; hacked necessarily to iterate by reference.
168  foreach (array(REVIEW_STAGE_ABSTRACT, REVIEW_STAGE_PRESENTATION) as $i) {
169  $directorDecisions = $trackDirectorSubmission->getDecisions($i);
170  $insertedDecision = false;
171  if (is_array($directorDecisions)) {
172  for ($j = 0; $j < count($directorDecisions); $j++) {
173  $directorDecision =& $directorDecisions[$j];
174  if ($directorDecision['editDecisionId'] == null) {
175  $this->update(
176  sprintf('INSERT INTO edit_decisions
177  (paper_id, stage, director_id, decision, date_decided)
178  VALUES (?, ?, ?, ?, %s)',
179  $this->datetimeToDB($directorDecision['dateDecided'])),
180  array($trackDirectorSubmission->getPaperId(),
181  $i,
182  $directorDecision['directorId'],
183  $directorDecision['decision']
184  )
185  );
186  $insertId = $this->getInsertId('edit_decisions', 'edit_decision_id');
187  $directorDecision['editDecisionId'] = $insertId;
188  $insertedDecision = true;
189  }
190  unset($directorDecision);
191  }
192  }
193  if ($insertedDecision) {
194  $trackDirectorSubmission->setDecisions($directorDecisions, $i);
195  }
196  }
197  if ($this->reviewStageExists($trackDirectorSubmission->getPaperId(), $trackDirectorSubmission->getCurrentStage())) {
198  $this->update(
199  'UPDATE review_stages
200  SET review_revision = ?
201  WHERE paper_id = ? AND
202  stage = ?',
203  array(
204  $trackDirectorSubmission->getReviewRevision(),
205  $trackDirectorSubmission->getPaperId(),
206  $trackDirectorSubmission->getCurrentStage()
207  )
208  );
209  } elseif ($trackDirectorSubmission->getReviewRevision()!=null) {
210  $this->createReviewStage(
211  $trackDirectorSubmission->getPaperId(),
212  $trackDirectorSubmission->getCurrentStage() === null ? 1 : $trackDirectorSubmission->getCurrentStage(),
213  $trackDirectorSubmission->getReviewRevision()
214  );
215  }
216 
217  // update review assignments
218  foreach ($trackDirectorSubmission->getReviewAssignments(null) as $stageReviewAssignments) {
219  foreach ($stageReviewAssignments as $reviewAssignment) {
220  if ($reviewAssignment->getId() > 0) {
221  $this->reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
222  } else {
223  $this->reviewAssignmentDao->insertReviewAssignment($reviewAssignment);
224  }
225  }
226  }
227 
228  // Remove deleted review assignments
229  $removedReviewAssignments = $trackDirectorSubmission->getRemovedReviewAssignments();
230  for ($i=0, $count=count($removedReviewAssignments); $i < $count; $i++) {
231  $this->reviewAssignmentDao->deleteReviewAssignmentById($removedReviewAssignments[$i]->getReviewId());
232  }
233 
234  // Update paper
235  if ($trackDirectorSubmission->getPaperId()) {
236 
237  $paper =& $this->paperDao->getPaper($trackDirectorSubmission->getPaperId());
238 
239  // Only update fields that can actually be edited.
240  $paper->setTrackId($trackDirectorSubmission->getTrackId());
241  $paper->setData('sessionType', $trackDirectorSubmission->getData('sessionType'));
242  $paper->setTrackId($trackDirectorSubmission->getTrackId());
243  $paper->setCurrentStage($trackDirectorSubmission->getCurrentStage());
244  $paper->setReviewFileId($trackDirectorSubmission->getReviewFileId());
245  $paper->setLayoutFileId($trackDirectorSubmission->getLayoutFileId());
246  $paper->setDirectorFileId($trackDirectorSubmission->getDirectorFileId());
247  $paper->setStatus($trackDirectorSubmission->getStatus());
248  $paper->setDateStatusModified($trackDirectorSubmission->getDateStatusModified());
249  $paper->setDateToPresentations($trackDirectorSubmission->getDateToPresentations());
250  $paper->setDateToArchive($trackDirectorSubmission->getDateToArchive());
251  $paper->setLastModified($trackDirectorSubmission->getLastModified());
252  $paper->setCommentsStatus($trackDirectorSubmission->getCommentsStatus());
253 
254  $this->paperDao->updatePaper($paper);
255  }
256 
257  }
258 
259  function createReviewStage($paperId, $stage, $reviewRevision) {
260  $this->update(
261  'INSERT INTO review_stages
262  (paper_id, stage, review_revision)
263  VALUES
264  (?, ?, ?)',
265  array($paperId, $stage, $reviewRevision)
266  );
267  }
268 
272  function &_getUnfilteredTrackDirectorSubmissions($trackDirectorId, $schedConfId, $trackId = 0, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $additionalWhereSql = '', $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
273  $primaryLocale = AppLocale::getPrimaryLocale();
274  $locale = AppLocale::getLocale();
275 
276  $params = array(
277  'title', // Track title
278  $primaryLocale,
279  'title',
280  $locale,
281  'abbrev', // Track abbrev
282  $primaryLocale,
283  'abbrev',
284  $locale,
285  'cleanTitle', // Paper title
286  'cleanTitle', // Paper title
287  $primaryLocale,
288  $schedConfId,
289  $trackDirectorId
290  );
291 
292  // set up the search filters based on what the user selected
293  $searchSql = '';
294  if (!empty($search)) switch ($searchField) {
296  if ($searchMatch === 'is') {
297  $searchSql = ' AND LOWER(ptl.setting_value) = LOWER(?)';
298  } elseif ($searchMatch === 'contains') {
299  $searchSql = ' AND LOWER(ptl.setting_value) LIKE LOWER(?)';
300  $search = '%' . $search . '%';
301  } else { // $searchMatch === 'startsWith'
302  $searchSql = ' AND LOWER(ptl.setting_value) LIKE LOWER(?)';
303  $search = '%' . $search . '%';
304  }
305  $params[] = $search;
306  break;
308  $first_last = $this->_dataSource->Concat('pa.first_name', '\' \'', 'pa.last_name');
309  $first_middle_last = $this->_dataSource->Concat('pa.first_name', '\' \'', 'pa.middle_name', '\' \'', 'pa.last_name');
310  $last_comma_first = $this->_dataSource->Concat('pa.last_name', '\', \'', 'pa.first_name');
311  $last_comma_first_middle = $this->_dataSource->Concat('pa.last_name', '\', \'', 'pa.first_name', '\' \'', 'pa.middle_name');
312 
313  if ($searchMatch === 'is') {
314  $searchSql = " AND (LOWER(pa.last_name) = LOWER(?) OR LOWER($first_last) = LOWER(?) OR LOWER($first_middle_last) = LOWER(?) OR LOWER($last_comma_first) = LOWER(?) OR LOWER($last_comma_first_middle) = LOWER(?))";
315  } elseif ($searchMatch === 'contains') {
316  $searchSql = " AND (LOWER(pa.last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
317  $search = '%' . $search . '%';
318  } else { // $searchMatch === 'startsWith'
319  $searchSql = " AND (LOWER(pa.last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
320  $search = $search . '%';
321  }
322  $params[] = $params[] = $params[] = $params[] = $params[] = $search;
323  break;
325  $first_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.last_name');
326  $first_middle_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.middle_name', '\' \'', 'ed.last_name');
327  $last_comma_first = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name');
328  $last_comma_first_middle = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name', '\' \'', 'ed.middle_name');
329  if ($searchMatch === 'is') {
330  $searchSql = " AND (LOWER(ed.last_name) = LOWER(?) OR LOWER($first_last) = LOWER(?) OR LOWER($first_middle_last) = LOWER(?) OR LOWER($last_comma_first) = LOWER(?) OR LOWER($last_comma_first_middle) = LOWER(?))";
331  } elseif ($searchMatch === 'contains') {
332  $searchSql = " AND (LOWER(ed.last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
333  $search = '%' . $search . '%';
334  } else { // $searchMatch === 'startsWith'
335  $searchSql = " AND (LOWER(ed.last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
336  $search = $search . '%';
337  }
338  $params[] = $params[] = $params[] = $params[] = $params[] = $search;
339  break;
340  }
341 
342  // filter on date range, if requested
343  if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
345  if (!empty($dateFrom)) {
346  $searchSql .= ' AND p.date_submitted >= ' . $this->datetimeToDB($dateFrom);
347  }
348  if (!empty($dateTo)) {
349  $searchSql .= ' AND p.date_submitted <= ' . $this->datetimeToDB($dateTo);
350  }
351  break;
352  }
353 
354  // filter for post from only one specific track, if requested
355  if ($trackId) {
356  $params[] = $trackId;
357  $searchSql .= ' AND p.track_id = ?';
358  }
359 
360  $sql = 'SELECT DISTINCT
361  p.*,
362  r2.review_revision,
363  COALESCE(ptl.setting_value, pptl.setting_value) AS submission_title,
364  pap.last_name AS author_name,
365  COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
366  COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
367  FROM papers p
368  INNER JOIN paper_authors pa ON (pa.paper_id = p.paper_id)
369  LEFT JOIN paper_authors pap ON (pap.paper_id = p.paper_id AND pap.primary_contact = 1)
370  LEFT JOIN edit_assignments e ON (e.paper_id = p.paper_id)
371  LEFT JOIN users ed ON (e.director_id = ed.user_id)
372  LEFT JOIN tracks t ON (t.track_id = p.track_id)
373  LEFT JOIN review_stages r2 ON (p.paper_id = r2.paper_id and p.current_stage = r2.stage)
374  LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
375  LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
376  LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
377  LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
378  LEFT JOIN paper_settings ptl ON (p.paper_id = ptl.paper_id AND ptl.setting_name = ?)
379  LEFT JOIN paper_settings pptl ON (p.paper_id = pptl.paper_id AND pptl.setting_name = ? AND pptl.locale = ?)
380  LEFT JOIN paper_settings sts ON (p.paper_id = sts.paper_id AND sts.setting_name = \'sessionType\')
381  WHERE p.sched_conf_id = ?
382  ' . (!empty($additionalWhereSql)?" AND ($additionalWhereSql)":'') . '
383  AND e.director_id = ? ' .
384  $searchSql .
385  ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
386 
387  $result =& $this->retrieveRange($sql,
388  $params,
389  $rangeInfo
390  );
391 
392  return $result;
393  }
394 
409  function &getTrackDirectorSubmissionsInReview($trackDirectorId, $schedConfId, $trackId, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
411  $trackDirectorId, $schedConfId, $trackId,
412  $searchField, $searchMatch, $search,
413  $dateField, $dateFrom, $dateTo,
414  'p.status = ' . STATUS_QUEUED,
415  $rangeInfo, $sortBy, $sortDirection
416  );
417 
418  $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
419  return $returner;
420 
421  }
422 
437  function &getTrackDirectorSubmissionsAccepted($trackDirectorId, $schedConfId, $trackId, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
439  $trackDirectorId, $schedConfId, $trackId,
440  $searchField, $searchMatch, $search,
441  $dateField, $dateFrom, $dateTo,
442  'p.status = ' . STATUS_PUBLISHED,
443  $rangeInfo, $sortBy, $sortDirection
444  );
445 
446  $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
447  return $returner;
448  }
449 
464  function &getTrackDirectorSubmissionsArchives($trackDirectorId, $schedConfId, $trackId, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
466  $trackDirectorId, $schedConfId, $trackId,
467  $searchField, $searchMatch, $search,
468  $dateField, $dateFrom, $dateTo,
469  'p.status <> ' . STATUS_QUEUED . ' AND p.status <> ' . STATUS_PUBLISHED,
470  $rangeInfo, $sortBy, $sortDirection
471  );
472 
473  $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
474  return $returner;
475  }
476 
480  function &getTrackDirectorSubmissionsCount($trackDirectorId, $schedConfId) {
481  $submissionsCount = array();
482 
483  // Fetch a count of submissions in review.
484  // "d2" and "d" are used to fetch the single most recent
485  // editor decision.
486  $result =& $this->retrieve(
487  'SELECT COUNT(*) AS review_count
488  FROM papers p
489  LEFT JOIN edit_assignments e ON (p.paper_id = e.paper_id)
490  WHERE p.sched_conf_id = ?
491  AND e.director_id = ?
492  AND p.status = ' . STATUS_QUEUED,
493  array((int) $schedConfId, (int) $trackDirectorId)
494  );
495  $submissionsCount[0] = $result->Fields('review_count');
496  $result->Close();
497 
498  // Fetch a count of submissions in editing.
499  // "d2" and "d" are used to fetch the single most recent
500  // editor decision.
501  $result =& $this->retrieve(
502  'SELECT COUNT(*) AS editing_count
503  FROM papers p
504  LEFT JOIN edit_assignments e ON (p.paper_id = e.paper_id)
505  LEFT JOIN edit_decisions d ON (p.paper_id = d.paper_id)
506  LEFT JOIN edit_decisions d2 ON (p.paper_id = d2.paper_id AND d.edit_decision_id < d2.edit_decision_id)
507  WHERE p.sched_conf_id = ?
508  AND e.director_id = ?
509  AND p.status = ' . STATUS_QUEUED . '
510  AND d2.edit_decision_id IS NULL
511  AND d.decision = ' . SUBMISSION_DIRECTOR_DECISION_ACCEPT,
512  array((int) $schedConfId, (int) $trackDirectorId)
513  );
514  $submissionsCount[1] = $result->Fields('editing_count');
515  $result->Close();
516  return $submissionsCount;
517  }
518 
519  //
520  // Miscellaneous
521  //
522 
527  function deleteDecisionsByPaper($paperId) {
528  return $this->update(
529  'DELETE FROM edit_decisions WHERE paper_id = ?',
530  $paperId
531  );
532  }
533 
538  function deleteReviewStagesByPaper($paperId) {
539  return $this->update(
540  'DELETE FROM review_stages WHERE paper_id = ?',
541  $paperId
542  );
543  }
544 
550  function getDirectorDecisions($paperId, $stage) {
551  $decisions = array();
552 
553  $params = array($paperId);
554  if($stage != null) $params[] = $stage;
555 
556  $result =& $this->retrieve('
557  SELECT edit_decision_id, director_id, decision, date_decided
558  FROM edit_decisions
559  WHERE paper_id = ?'
560  . ($stage == NULL ? '' : ' AND stage = ?')
561  . ' ORDER BY edit_decision_id ASC',
562  count($params) == 1 ? shift($params) : $params);
563 
564  while (!$result->EOF) {
565  $decisions[] = array(
566  'editDecisionId' => $result->fields['edit_decision_id'],
567  'directorId' => $result->fields['director_id'],
568  'decision' => $result->fields['decision'],
569  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
570  );
571  $result->moveNext();
572  }
573  $result->Close();
574  unset($result);
575 
576  return $decisions;
577  }
578 
584  function getMaxReviewStage($paperId) {
585  $result =& $this->retrieve(
586  'SELECT MAX(stage) FROM review_stages WHERE paper_id = ?', array($paperId)
587  );
588  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
589 
590  $result->Close();
591  unset($result);
592 
593  return $returner;
594  }
595 
602  function reviewStageExists($paperId, $stage) {
603  $result =& $this->retrieve(
604  'SELECT COUNT(*) FROM review_stages WHERE paper_id = ? AND stage = ?', array($paperId, $stage)
605  );
606  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
607 
608  $result->Close();
609  unset($result);
610 
611  return $returner;
612  }
613 
620  function reviewerExists($paperId, $reviewerId, $stage) {
621  $result =& $this->retrieve('
622  SELECT COUNT(*)
623  FROM review_assignments
624  WHERE paper_id = ?
625  AND reviewer_id = ?
626  AND stage = ?
627  AND cancelled = 0',
628  array($paperId, $reviewerId, $stage)
629  );
630  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
631 
632  $result->Close();
633  unset($result);
634 
635  return $returner;
636  }
637 
644  function &getReviewersForPaper($schedConfId, $paperId, $stage, $searchType = null, $search = null, $searchMatch = null, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
645  // Convert the field being searched for to a DB element to select on
646  $searchTypeMap = array(
647  USER_FIELD_FIRSTNAME => 'u.first_name',
648  USER_FIELD_LASTNAME => 'u.last_name',
649  USER_FIELD_USERNAME => 'u.username',
650  USER_FIELD_EMAIL => 'u.email',
651  USER_FIELD_INTERESTS => 's.setting_value'
652  );
653 
654  // Add the "interests" parameter only if the user searched for reviwer interests
655  $paramArray = array((int)$paperId, (int)$stage);
656  $joinInterests = false;
657  if($searchType == USER_FIELD_INTERESTS) {
658  $paramArray[] = "interests";
659  $joinInterests = true;
660  }
661 
662  $paramArray[] = (int)$schedConfId;
663  $paramArray[] = ROLE_ID_REVIEWER;
664 
665  // Generate the SQL used to filter the results based on what the user is searching for
666  $searchSql = '';
667  if (!empty($search) && isset($searchTypeMap[$searchType])) {
668  $fieldName = $searchTypeMap[$searchType];
669  switch ($searchMatch) {
670  case 'is':
671  $searchSql = "AND LOWER($fieldName) = LOWER(?)";
672  $paramArray[] = $search;
673  break;
674  case 'contains':
675  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
676  $paramArray[] = '%' . $search . '%';
677  break;
678  case 'startsWith':
679  $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
680  $paramArray[] = $search . '%';
681  break;
682  }
683  } elseif (!empty($search)) switch ($searchType) {
684  case USER_FIELD_USERID:
685  $searchSql = 'AND user_id=?';
686  $paramArray[] = $search;
687  break;
688  case USER_FIELD_INITIAL:
689  $searchSql = 'AND (LOWER(last_name) LIKE LOWER(?) OR LOWER(username) LIKE LOWER(?))';
690  $paramArray[] = $search . '%';
691  $paramArray[] = $search . '%';
692  break;
693  }
694 
695  // If we are sorting a column, we'll need to configure the additional join conditions
696  $sortSelect = '';
697  $joinComplete = $joinIncomplete = false;
698  $selectQuality = $selectLatest = $selectComplete = $selectAverage = $selectIncomplete = false;
699  if($sortBy) switch($sortBy) {
700  case 'quality':
701  $selectQuality = true;
702  break;
703  case 'latest':
704  $selectLatest = $joinComplete = true;
705  break;
706  case 'done':
707  $selectComplete = $joinComplete = true;
708  break;
709  case 'average':
710  $selectAverage = $joinComplete = true;
711  break;
712  case 'active':
713  $selectIncomplete = $joinIncomplete = true;
714  break;
715  }
716 
717  $sql = 'SELECT DISTINCT
718  u.user_id,
719  u.last_name,
720  ar.review_id ' .
721  ($selectQuality ? ', AVG(ar.quality) AS average_quality ' : '') .
722  ($selectLatest ? ', MAX(ac.date_notified) AS latest ' : '') .
723  ($selectComplete ? ', COUNT(ac.review_id) AS completed ' : '') .
724  ($selectAverage ? ', AVG(ac.date_completed-ac.date_notified) AS average ' : '') .
725  ($selectIncomplete ? ', COUNT(ai.review_id) AS incomplete ' : '') .
726  'FROM roles r, users u
727  LEFT JOIN review_assignments ar ON (ar.reviewer_id = u.user_id AND ar.cancelled = 0 AND ar.paper_id = ? AND ar.stage = ?) ' .
728  ($joinComplete ? 'LEFT JOIN review_assignments ac ON (ac.reviewer_id = u.user_id AND ac.date_completed IS NOT NULL) ' : '') .
729  ($joinIncomplete ? 'LEFT JOIN review_assignments ai ON (ai.reviewer_id = u.user_id AND ai.date_completed IS NULL) ' : '') .
730  ($joinInterests ? 'LEFT JOIN user_settings s ON (u.user_id = s.user_id AND s.setting_name = ?) ' : '') .
731  'WHERE u.user_id = r.user_id AND
732  r.sched_conf_id = ? AND
733  r.role_id = ? ' . $searchSql . ' ' .
734  'GROUP BY u.user_id, u.last_name, ar.review_id ' .
735  ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
736 
737  $result =& $this->retrieveRange(
738  $sql,$paramArray, $rangeInfo
739  );
740 
741  $returner = new DAOResultFactory($result, $this, '_returnReviewerUserFromRow');
742  return $returner;
743  }
744 
745  function &_returnReviewerUserFromRow(&$row) { // FIXME
746  $user =& $this->userDao->getUser($row['user_id']);
747  $user->review_id = $row['review_id'];
748 
749  HookRegistry::call('TrackDirectorSubmissionDAO::_returnReviewerUserFromRow', array(&$user, &$row));
750 
751  return $user;
752  }
753 
760  function &getReviewersNotAssignedToPaper($schedConfId, $paperId) {
761  $users = array();
762 
763  $result =& $this->retrieve(
764  'SELECT u.* FROM users u NATURAL JOIN roles r LEFT JOIN review_assignments a ON (a.reviewer_id = u.user_id AND a.paper_id = ?) WHERE r.sched_conf_id = ? AND r.role_id = ? AND a.paper_id IS NULL ORDER BY last_name, first_name',
765  array($paperId, $schedConfId, RoleDAO::getRoleIdFromPath('reviewer'))
766  );
767 
768  while (!$result->EOF) {
769  $users[] =& $this->userDao->_returnUserFromRowWithData($result->GetRowAssoc(false));
770  $result->moveNext();
771  }
772 
773  $result->Close();
774  unset($result);
775 
776  return $users;
777  }
778 
783  function getReviewerStatistics($schedConfId) {
784  $statistics = Array();
785 
786  // Get latest review request date
787  $result =& $this->retrieve('SELECT ra.reviewer_id AS reviewer_id, MAX(ra.date_notified) AS last_notified FROM review_assignments ra, papers p WHERE ra.paper_id = p.paper_id AND p.sched_conf_id = ? GROUP BY ra.reviewer_id', $schedConfId);
788  while (!$result->EOF) {
789  $row = $result->GetRowAssoc(false);
790  if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
791  $statistics[$row['reviewer_id']]['last_notified'] = $this->datetimeFromDB($row['last_notified']);
792  $result->MoveNext();
793  }
794 
795  $result->Close();
796  unset($result);
797 
798  // Get completion status
799  $result =& $this->retrieve('SELECT r.reviewer_id AS reviewer_id, COUNT(*) AS incomplete FROM review_assignments r, papers p WHERE r.paper_id = p.paper_id AND r.date_notified IS NOT NULL AND r.date_completed IS NULL AND r.cancelled = 0 AND p.sched_conf_id = ? GROUP BY r.reviewer_id', $schedConfId);
800  while (!$result->EOF) {
801  $row = $result->GetRowAssoc(false);
802  if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
803  $statistics[$row['reviewer_id']]['incomplete'] = $row['incomplete'];
804  $result->MoveNext();
805  }
806 
807  $result->Close();
808  unset($result);
809 
810  // Calculate time taken for completed reviews
811  $result =& $this->retrieve('SELECT r.reviewer_id, r.date_notified, r.date_completed FROM review_assignments r, papers p WHERE r.paper_id = p.paper_id AND r.date_notified IS NOT NULL AND r.date_completed IS NOT NULL AND p.sched_conf_id = ?', $schedConfId);
812  while (!$result->EOF) {
813  $row = $result->GetRowAssoc(false);
814  if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
815 
816  $completed = strtotime($this->datetimeFromDB($row['date_completed']));
817  $notified = strtotime($this->datetimeFromDB($row['date_notified']));
818  if (isset($statistics[$row['reviewer_id']]['total_span'])) {
819  $statistics[$row['reviewer_id']]['total_span'] += $completed - $notified;
820  $statistics[$row['reviewer_id']]['completed_review_count'] += 1;
821  } else {
822  $statistics[$row['reviewer_id']]['total_span'] = $completed - $notified;
823  $statistics[$row['reviewer_id']]['completed_review_count'] = 1;
824  }
825 
826  // Calculate the average length of review in weeks.
827  $statistics[$row['reviewer_id']]['average_span'] = (($statistics[$row['reviewer_id']]['total_span'] / $statistics[$row['reviewer_id']]['completed_review_count']) / 60 / 60 / 24 / 7);
828  $result->MoveNext();
829  }
830 
831  $result->Close();
832  unset($result);
833 
834  return $statistics;
835  }
836 
842  function getSortMapping($heading) {
843  switch ($heading) {
844  case 'id': return 'p.paper_id';
845  case 'submitDate': return 'p.date_submitted';
846  case 'track': return 'track_abbrev';
847  case 'sessionType': return 'sts.setting_value';
848  case 'authors': return 'author_name';
849  case 'title': return 'submission_title';
850  case 'status': return 'p.status';
851  case 'active': return 'incomplete';
852  case 'reviewerName': return 'u.last_name';
853  case 'quality': return 'average_quality';
854  case 'done': return 'completed';
855  case 'latest': return 'latest';
856  case 'average': return 'average';
857  case 'name': return 'u.last_name';
858  default: return null;
859  }
860  }
861 }
862 
863 ?>
const STATUS_QUEUED
Definition: Paper.inc.php:26
const REVIEW_STAGE_ABSTRACT
Definition: Paper.inc.php:36
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying TrackDirectorSubmission objects.
const USER_FIELD_INTERESTS
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
const USER_FIELD_FIRSTNAME
TrackDirectorSubmission class.
const USER_FIELD_LASTNAME
const USER_FIELD_USERNAME
& _getUnfilteredTrackDirectorSubmissions($trackDirectorId, $schedConfId, $trackId=0, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $additionalWhereSql='', $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
& getTrackDirectorSubmissionsArchives($trackDirectorId, $schedConfId, $trackId, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
& getReviewersNotAssignedToPaper($schedConfId, $paperId)
const REVIEW_STAGE_PRESENTATION
Definition: Paper.inc.php:37
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
getRoleIdFromPath($rolePath)
const USER_FIELD_INITIAL
const COMMENT_TYPE_DIRECTOR_DECISION
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:152
const SUBMISSION_FIELD_TITLE
Definition: Paper.inc.php:42
const SUBMISSION_DIRECTOR_DECISION_ACCEPT
Definition: Action.inc.php:23
datetimeFromDB($dt)
Definition: DAO.inc.php:276
const USER_FIELD_USERID
& getTrackDirectorSubmissionsAccepted($trackDirectorId, $schedConfId, $trackId, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
& getTrackDirectorSubmissionsCount($trackDirectorId, $schedConfId)
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
& getDAO($name, $dbconn=null)
reviewerExists($paperId, $reviewerId, $stage)
call($hookName, $args=null)
const SUBMISSION_FIELD_DATE_SUBMITTED
Definition: Paper.inc.php:45
const SUBMISSION_FIELD_DIRECTOR
Definition: Paper.inc.php:41
const ROLE_ID_REVIEWER
Definition: Role.inc.php:31
createReviewStage($paperId, $stage, $reviewRevision)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
const USER_FIELD_EMAIL
getDirectionMapping($direction)
Definition: DAO.inc.php:541
const SUBMISSION_FIELD_AUTHOR
Definition: Paper.inc.php:40
updateTrackDirectorSubmission(&$trackDirectorSubmission)
& getReviewersForPaper($schedConfId, $paperId, $stage, $searchType=null, $search=null, $searchMatch=null, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
const SORT_DIRECTION_ASC
Definition: DAO.inc.php:27
& getTrackDirectorSubmissionsInReview($trackDirectorId, $schedConfId, $trackId, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
const STATUS_PUBLISHED
Definition: Paper.inc.php:27