classes/submission/trackDirector/TrackDirectorSubmissionDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00017 // $Id$
00018 
00019 
00020 import('submission.trackDirector.TrackDirectorSubmission');
00021 
00022 // Bring in director decision constants
00023 import('submission.common.Action');
00024 import('submission.author.AuthorSubmission');
00025 import('submission.reviewer.ReviewerSubmission');
00026 
00027 class TrackDirectorSubmissionDAO extends DAO {
00028    var $paperDao;
00029    var $authorDao;
00030    var $userDao;
00031    var $editAssignmentDao;
00032    var $reviewAssignmentDao;
00033    var $paperFileDao;
00034    var $suppFileDao;
00035    var $galleyDao;
00036    var $paperEmailLogDao;
00037    var $paperCommentDao;
00038 
00042    function TrackDirectorSubmissionDAO() {
00043       parent::DAO();
00044       $this->paperDao =& DAORegistry::getDAO('PaperDAO');
00045       $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
00046       $this->userDao =& DAORegistry::getDAO('UserDAO');
00047       $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00048       $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00049       $this->paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
00050       $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00051       $this->galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00052       $this->paperEmailLogDao =& DAORegistry::getDAO('PaperEmailLogDAO');
00053       $this->paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
00054    }
00055 
00061    function &getTrackDirectorSubmission($paperId) {
00062       $primaryLocale = AppLocale::getPrimaryLocale();
00063       $locale = AppLocale::getLocale();
00064       $result =& $this->retrieve(
00065          'SELECT  p.*,
00066             r2.review_revision,
00067             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00068             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00069          FROM  papers p
00070             LEFT JOIN tracks t ON (t.track_id = p.track_id)
00071             LEFT JOIN review_stages r2 ON (p.paper_id = r2.paper_id AND p.current_stage = r2.stage)
00072             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00073             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00074             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00075             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00076          WHERE p.paper_id = ?',
00077          array(
00078             'title',
00079             $primaryLocale,
00080             'title',
00081             $locale,
00082             'abbrev',
00083             $primaryLocale,
00084             'abbrev',
00085             $locale,
00086             $paperId
00087          )
00088       );
00089 
00090       $returner = null;
00091       if ($result->RecordCount() != 0) {
00092          $returner =& $this->_returnTrackDirectorSubmissionFromRow($result->GetRowAssoc(false));
00093       }
00094 
00095       $result->Close();
00096       unset($result);
00097 
00098       return $returner;
00099    }
00100 
00106    function &_returnTrackDirectorSubmissionFromRow(&$row) {
00107       $trackDirectorSubmission = new TrackDirectorSubmission();
00108 
00109       // Paper attributes
00110       $this->paperDao->_paperFromRow($trackDirectorSubmission, $row);
00111 
00112       // Director Assignment
00113       $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByPaperId($row['paper_id']);
00114       $trackDirectorSubmission->setEditAssignments($editAssignments->toArray());
00115 
00116       // Director Decisions
00117       for ($i = 1; $i <= $row['current_stage']; $i++) {
00118          $trackDirectorSubmission->setDecisions($this->getDirectorDecisions($row['paper_id'], $i), $i);
00119       }
00120 
00121       // Comments
00122       $trackDirectorSubmission->setMostRecentDirectorDecisionComment($this->paperCommentDao->getMostRecentPaperComment($row['paper_id'], COMMENT_TYPE_DIRECTOR_DECISION, $row['paper_id']));
00123 
00124       // Files
00125       $trackDirectorSubmission->setSubmissionFile($this->paperFileDao->getPaperFile($row['submission_file_id']));
00126       $trackDirectorSubmission->setRevisedFile($this->paperFileDao->getPaperFile($row['revised_file_id']));
00127       $trackDirectorSubmission->setReviewFile($this->paperFileDao->getPaperFile($row['review_file_id']));
00128       $trackDirectorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByPaper($row['paper_id']));
00129       $trackDirectorSubmission->setDirectorFile($this->paperFileDao->getPaperFile($row['director_file_id']));
00130       $trackDirectorSubmission->setLayoutFile($this->paperFileDao->getPaperFile($row['layout_file_id']));
00131 
00132       for ($i = 1; $i <= $row['current_stage']; $i++) {
00133          $trackDirectorSubmission->setDirectorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['director_file_id'], $i), $i);
00134          $trackDirectorSubmission->setAuthorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['revised_file_id'], $i), $i);
00135       }
00136 
00137       // Review Stages
00138       $trackDirectorSubmission->setReviewRevision($row['review_revision']);
00139 
00140       // Review Assignments
00141       for ($i = 1; $i <= $row['current_stage']; $i++)
00142          $trackDirectorSubmission->setReviewAssignments($this->reviewAssignmentDao->getReviewAssignmentsByPaperId($row['paper_id'], $i), $i);
00143 
00144       $trackDirectorSubmission->setGalleys($this->galleyDao->getGalleysByPaper($row['paper_id']));
00145 
00146       HookRegistry::call('TrackDirectorSubmissionDAO::_returnTrackDirectorSubmissionFromRow', array(&$trackDirectorSubmission, &$row));
00147 
00148       return $trackDirectorSubmission;
00149    }
00150 
00155    function updateTrackDirectorSubmission(&$trackDirectorSubmission) {
00156       // update edit assignment
00157       $editAssignments =& $trackDirectorSubmission->getEditAssignments();
00158       foreach ($editAssignments as $editAssignment) {
00159          if ($editAssignment->getEditId() > 0) {
00160             $this->editAssignmentDao->updateEditAssignment($editAssignment);
00161          } else {
00162             $this->editAssignmentDao->insertEditAssignment($editAssignment);
00163          }
00164       }
00165 
00166       // Update director decisions; hacked necessarily to iterate by reference.
00167       foreach (array(REVIEW_STAGE_ABSTRACT, REVIEW_STAGE_PRESENTATION) as $i) {
00168          $directorDecisions = $trackDirectorSubmission->getDecisions($i);
00169          $insertedDecision = false;
00170          if (is_array($directorDecisions)) {
00171             for ($j = 0; $j < count($directorDecisions); $j++) {
00172                $directorDecision =& $directorDecisions[$j];
00173                if ($directorDecision['editDecisionId'] == null) {
00174                   $this->update(
00175                      sprintf('INSERT INTO edit_decisions
00176                         (paper_id, stage, director_id, decision, date_decided)
00177                         VALUES (?, ?, ?, ?, %s)',
00178                            $this->datetimeToDB($directorDecision['dateDecided'])),
00179                      array($trackDirectorSubmission->getPaperId(),
00180                         $i,
00181                         $directorDecision['directorId'],
00182                         $directorDecision['decision']
00183                      )
00184                   );
00185                   $insertId = $this->getInsertId('edit_decisions', 'edit_decision_id');
00186                   $directorDecision['editDecisionId'] = $insertId;
00187                   $insertedDecision = true;
00188                }
00189                unset($directorDecision);
00190             }
00191          }
00192          if ($insertedDecision) {
00193             $trackDirectorSubmission->setDecisions($directorDecisions, $i);
00194          }
00195       }
00196       if ($this->reviewStageExists($trackDirectorSubmission->getPaperId(), $trackDirectorSubmission->getCurrentStage())) {
00197          $this->update(
00198             'UPDATE  review_stages
00199             SET   review_revision = ?
00200             WHERE paper_id = ? AND
00201                stage = ?',
00202             array(
00203                $trackDirectorSubmission->getReviewRevision(),
00204                $trackDirectorSubmission->getPaperId(),
00205                $trackDirectorSubmission->getCurrentStage()
00206             )
00207          );
00208       } elseif ($trackDirectorSubmission->getReviewRevision()!=null) {
00209          $this->createReviewStage(
00210             $trackDirectorSubmission->getPaperId(),
00211             $trackDirectorSubmission->getCurrentStage() === null ? 1 : $trackDirectorSubmission->getCurrentStage(),
00212             $trackDirectorSubmission->getReviewRevision()
00213          );
00214       }
00215 
00216       // update review assignments
00217       foreach ($trackDirectorSubmission->getReviewAssignments(null) as $stageReviewAssignments) {
00218          foreach ($stageReviewAssignments as $reviewAssignment) {
00219             if ($reviewAssignment->getId() > 0) {
00220                $this->reviewAssignmentDao->updateReviewAssignment($reviewAssignment);
00221             } else {
00222                $this->reviewAssignmentDao->insertReviewAssignment($reviewAssignment);
00223             }
00224          }
00225       }
00226 
00227       // Remove deleted review assignments
00228       $removedReviewAssignments = $trackDirectorSubmission->getRemovedReviewAssignments();
00229       for ($i=0, $count=count($removedReviewAssignments); $i < $count; $i++) {
00230          $this->reviewAssignmentDao->deleteReviewAssignmentById($removedReviewAssignments[$i]->getReviewId());
00231       }
00232 
00233       // Update paper
00234       if ($trackDirectorSubmission->getPaperId()) {
00235 
00236          $paper =& $this->paperDao->getPaper($trackDirectorSubmission->getPaperId());
00237 
00238          // Only update fields that can actually be edited.
00239          $paper->setTrackId($trackDirectorSubmission->getTrackId());
00240          $paper->setData('sessionType', $trackDirectorSubmission->getData('sessionType'));
00241          $paper->setTrackId($trackDirectorSubmission->getTrackId());
00242          $paper->setCurrentStage($trackDirectorSubmission->getCurrentStage());
00243          $paper->setReviewFileId($trackDirectorSubmission->getReviewFileId());
00244          $paper->setLayoutFileId($trackDirectorSubmission->getLayoutFileId());
00245          $paper->setDirectorFileId($trackDirectorSubmission->getDirectorFileId());
00246          $paper->setStatus($trackDirectorSubmission->getStatus());
00247          $paper->setDateStatusModified($trackDirectorSubmission->getDateStatusModified());
00248          $paper->setDateToPresentations($trackDirectorSubmission->getDateToPresentations());
00249          $paper->setDateToArchive($trackDirectorSubmission->getDateToArchive());
00250          $paper->setLastModified($trackDirectorSubmission->getLastModified());
00251          $paper->setCommentsStatus($trackDirectorSubmission->getCommentsStatus());
00252 
00253          $this->paperDao->updatePaper($paper);
00254       }
00255 
00256    }
00257 
00258    function createReviewStage($paperId, $stage, $reviewRevision) {
00259       $this->update(
00260          'INSERT INTO review_stages
00261             (paper_id, stage, review_revision)
00262          VALUES
00263             (?, ?, ?)',
00264          array($paperId, $stage, $reviewRevision)
00265       );
00266    }
00267 
00271    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) {
00272       $primaryLocale = AppLocale::getPrimaryLocale();
00273       $locale = AppLocale::getLocale();
00274 
00275       $params = array(
00276          'title', // Track title
00277          $primaryLocale,
00278          'title',
00279          $locale,
00280          'abbrev', // Track abbrev
00281          $primaryLocale,
00282          'abbrev',
00283          $locale,
00284          'cleanTitle', // Paper title
00285          'cleanTitle', // Paper title
00286          $primaryLocale,
00287          $schedConfId,
00288          $trackDirectorId
00289       );
00290 
00291       // set up the search filters based on what the user selected
00292       $searchSql = '';
00293       if (!empty($search)) switch ($searchField) {
00294          case SUBMISSION_FIELD_TITLE:
00295             if ($searchMatch === 'is') {
00296                $searchSql = ' AND LOWER(ptl.setting_value) = LOWER(?)';
00297             } elseif ($searchMatch === 'contains') {
00298                $searchSql = ' AND LOWER(ptl.setting_value) LIKE LOWER(?)';
00299                $search = '%' . $search . '%';
00300             } else { // $searchMatch === 'startsWith'
00301                $searchSql = ' AND LOWER(ptl.setting_value) LIKE LOWER(?)';
00302                $search = '%' . $search . '%';
00303             }
00304             $params[] = $search;
00305             break;
00306          case SUBMISSION_FIELD_AUTHOR:
00307             $first_last = $this->_dataSource->Concat('pa.first_name', '\' \'', 'pa.last_name');
00308             $first_middle_last = $this->_dataSource->Concat('pa.first_name', '\' \'', 'pa.middle_name', '\' \'', 'pa.last_name');
00309             $last_comma_first = $this->_dataSource->Concat('pa.last_name', '\', \'', 'pa.first_name');
00310             $last_comma_first_middle = $this->_dataSource->Concat('pa.last_name', '\', \'', 'pa.first_name', '\' \'', 'pa.middle_name');
00311 
00312             if ($searchMatch === 'is') {
00313                $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(?))";
00314             } elseif ($searchMatch === 'contains') {
00315                $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(?))";
00316                $search = '%' . $search . '%';
00317             } else { // $searchMatch === 'startsWith'
00318                $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(?))";
00319                $search = $search . '%';
00320             }
00321             $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00322             break;
00323          case SUBMISSION_FIELD_DIRECTOR:
00324             $first_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.last_name');
00325             $first_middle_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.middle_name', '\' \'', 'ed.last_name');
00326             $last_comma_first = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name');
00327             $last_comma_first_middle = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name', '\' \'', 'ed.middle_name');
00328             if ($searchMatch === 'is') {
00329                $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(?))";
00330             } elseif ($searchMatch === 'contains') {
00331                $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(?))";
00332                $search = '%' . $search . '%';
00333             } else { // $searchMatch === 'startsWith'
00334                $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(?))";
00335                $search = $search . '%';
00336             }
00337             $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00338             break;
00339       }
00340 
00341       // filter on date range, if requested
00342       if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
00343          case SUBMISSION_FIELD_DATE_SUBMITTED:
00344             if (!empty($dateFrom)) {
00345                $searchSql .= ' AND p.date_submitted >= ' . $this->datetimeToDB($dateFrom);
00346             }
00347             if (!empty($dateTo)) {
00348                $searchSql .= ' AND p.date_submitted <= ' . $this->datetimeToDB($dateTo);
00349             }
00350             break;
00351       }
00352 
00353       // filter for post from only one specific track, if requested
00354       if ($trackId) {
00355          $params[] = $trackId;
00356          $searchSql .= ' AND p.track_id = ?';
00357       }
00358 
00359       $sql = 'SELECT DISTINCT
00360             p.*,
00361             r2.review_revision,
00362             COALESCE(ptl.setting_value, pptl.setting_value) AS submission_title,
00363             pap.last_name AS author_name,
00364             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00365             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00366          FROM  papers p
00367             INNER JOIN paper_authors pa ON (pa.paper_id = p.paper_id)
00368             LEFT JOIN paper_authors pap ON (pap.paper_id = p.paper_id AND pap.primary_contact = 1)
00369             LEFT JOIN edit_assignments e ON (e.paper_id = p.paper_id)
00370             LEFT JOIN users ed ON (e.director_id = ed.user_id)
00371             LEFT JOIN tracks t ON (t.track_id = p.track_id)
00372             LEFT JOIN review_stages r2 ON (p.paper_id = r2.paper_id and p.current_stage = r2.stage)
00373             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00374             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00375             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00376             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00377             LEFT JOIN paper_settings ptl ON (p.paper_id = ptl.paper_id AND ptl.setting_name = ?)
00378             LEFT JOIN paper_settings pptl ON (p.paper_id = pptl.paper_id AND pptl.setting_name = ? AND pptl.locale = ?)
00379          WHERE p.sched_conf_id = ?
00380             ' . (!empty($additionalWhereSql)?" AND ($additionalWhereSql)":'') . '
00381             AND e.director_id = ? ' .
00382          $searchSql .
00383          ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
00384 
00385       $result =& $this->retrieveRange($sql,
00386          $params,
00387          $rangeInfo
00388       );
00389 
00390       return $result;
00391    }
00392 
00407    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) {
00408       $result = $this->_getUnfilteredTrackDirectorSubmissions(
00409          $trackDirectorId, $schedConfId, $trackId,
00410          $searchField, $searchMatch, $search,
00411          $dateField, $dateFrom, $dateTo,
00412          'p.status = ' . STATUS_QUEUED,
00413          $rangeInfo, $sortBy, $sortDirection
00414       );
00415 
00416       $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
00417       return $returner;
00418 
00419    }
00420 
00435    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) {
00436       $result = $this->_getUnfilteredTrackDirectorSubmissions(
00437          $trackDirectorId, $schedConfId, $trackId,
00438          $searchField, $searchMatch, $search,
00439          $dateField, $dateFrom, $dateTo,
00440          'p.status = ' . STATUS_PUBLISHED,
00441          $rangeInfo, $sortBy, $sortDirection
00442       );
00443 
00444       $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
00445       return $returner;
00446    }
00447 
00462    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) {
00463       $result = $this->_getUnfilteredTrackDirectorSubmissions(
00464          $trackDirectorId, $schedConfId, $trackId,
00465          $searchField, $searchMatch, $search,
00466          $dateField, $dateFrom, $dateTo,
00467          'p.status <> ' . STATUS_QUEUED . ' AND p.status <> ' . STATUS_PUBLISHED,
00468          $rangeInfo, $sortBy, $sortDirection
00469       );
00470 
00471       $returner = new DAOResultFactory($result, $this, '_returnTrackDirectorSubmissionFromRow');
00472       return $returner;
00473    }
00474 
00478    function &getTrackDirectorSubmissionsCount($trackDirectorId, $schedConfId) {
00479       $submissionsCount = array();
00480 
00481       // Fetch a count of submissions in review.
00482       // "d2" and "d" are used to fetch the single most recent
00483       // editor decision.
00484       $result =& $this->retrieve(
00485          'SELECT  COUNT(*) AS review_count
00486          FROM  papers p
00487             LEFT JOIN edit_assignments e ON (p.paper_id = e.paper_id)
00488          WHERE p.sched_conf_id = ?
00489             AND e.director_id = ?
00490             AND p.status = ' . STATUS_QUEUED,
00491          array((int) $schedConfId, (int) $trackDirectorId)
00492       );
00493       $submissionsCount[0] = $result->Fields('review_count');
00494       $result->Close();
00495 
00496       // Fetch a count of submissions in editing.
00497       // "d2" and "d" are used to fetch the single most recent
00498       // editor decision.
00499       $result =& $this->retrieve(
00500          'SELECT  COUNT(*) AS editing_count
00501          FROM  papers p
00502             LEFT JOIN edit_assignments e ON (p.paper_id = e.paper_id)
00503             LEFT JOIN edit_decisions d ON (p.paper_id = d.paper_id)
00504             LEFT JOIN edit_decisions d2 ON (p.paper_id = d2.paper_id AND d.edit_decision_id < d2.edit_decision_id)
00505          WHERE p.sched_conf_id = ?
00506             AND e.director_id = ?
00507             AND p.status = ' . STATUS_QUEUED . '
00508             AND d2.edit_decision_id IS NULL
00509             AND d.decision = ' . SUBMISSION_DIRECTOR_DECISION_ACCEPT,
00510          array((int) $schedConfId, (int) $trackDirectorId)
00511       );
00512       $submissionsCount[1] = $result->Fields('editing_count');
00513       $result->Close();
00514       return $submissionsCount;
00515    }
00516 
00517    //
00518    // Miscellaneous
00519    //
00520 
00525    function deleteDecisionsByPaper($paperId) {
00526       return $this->update(
00527          'DELETE FROM edit_decisions WHERE paper_id = ?',
00528          $paperId
00529       );
00530    }
00531 
00536    function deleteReviewStagesByPaper($paperId) {
00537       return $this->update(
00538          'DELETE FROM review_stages WHERE paper_id = ?',
00539          $paperId
00540       );
00541    }
00542 
00548    function getDirectorDecisions($paperId, $stage) {
00549       $decisions = array();
00550 
00551       $params = array($paperId);
00552       if($stage != null) $params[] = $stage;
00553 
00554       $result =& $this->retrieve('
00555          SELECT edit_decision_id, director_id, decision, date_decided
00556             FROM edit_decisions
00557             WHERE paper_id = ?'
00558                . ($stage == NULL ? '' : ' AND stage = ?')
00559             . ' ORDER BY edit_decision_id ASC',
00560             count($params) == 1 ? shift($params) : $params);
00561 
00562       while (!$result->EOF) {
00563          $decisions[] = array(
00564             'editDecisionId' => $result->fields['edit_decision_id'],
00565             'directorId' => $result->fields['director_id'],
00566             'decision' => $result->fields['decision'],
00567             'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
00568          );
00569          $result->moveNext();
00570       }
00571       $result->Close();
00572       unset($result);
00573 
00574       return $decisions;
00575    }
00576 
00582    function getMaxReviewStage($paperId) {
00583       $result =& $this->retrieve(
00584          'SELECT MAX(stage) FROM review_stages WHERE paper_id = ?', array($paperId)
00585       );
00586       $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
00587 
00588       $result->Close();
00589       unset($result);
00590 
00591       return $returner;
00592    }
00593 
00600    function reviewStageExists($paperId, $stage) {
00601       $result =& $this->retrieve(
00602          'SELECT COUNT(*) FROM review_stages WHERE paper_id = ? AND stage = ?', array($paperId, $stage)
00603       );
00604       $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00605 
00606       $result->Close();
00607       unset($result);
00608 
00609       return $returner;
00610    }
00611 
00618    function reviewerExists($paperId, $reviewerId, $stage) {
00619       $result =& $this->retrieve('
00620          SELECT COUNT(*)
00621          FROM review_assignments
00622          WHERE paper_id = ?
00623             AND reviewer_id = ?
00624             AND stage = ?
00625             AND cancelled = 0',
00626          array($paperId, $reviewerId, $stage)
00627       );
00628       $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00629 
00630       $result->Close();
00631       unset($result);
00632 
00633       return $returner;
00634    }
00635 
00642    function &getReviewersForPaper($schedConfId, $paperId, $stage, $searchType = null, $search = null, $searchMatch = null, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
00643       // Convert the field being searched for to a DB element to select on
00644       $searchTypeMap = array(
00645          USER_FIELD_FIRSTNAME => 'u.first_name',
00646          USER_FIELD_LASTNAME => 'u.last_name',
00647          USER_FIELD_USERNAME => 'u.username',
00648          USER_FIELD_EMAIL => 'u.email',
00649          USER_FIELD_INTERESTS => 's.setting_value'
00650       );
00651 
00652       // Add the "interests" parameter only if the user searched for reviwer interests
00653       $paramArray = array((int)$paperId, (int)$stage);
00654       $joinInterests = false;
00655       if($searchType == USER_FIELD_INTERESTS) {
00656          $paramArray[] = "interests";
00657          $joinInterests = true;
00658       }
00659 
00660       $paramArray[] = (int)$schedConfId;
00661       $paramArray[] = ROLE_ID_REVIEWER;
00662 
00663       // Generate the SQL used to filter the results based on what the user is searching for
00664       $searchSql = '';
00665       if (!empty($search) && isset($searchTypeMap[$searchType])) {
00666          $fieldName = $searchTypeMap[$searchType];
00667          switch ($searchMatch) {
00668             case 'is':
00669                $searchSql = "AND LOWER($fieldName) = LOWER(?)";
00670                $paramArray[] = $search;
00671                break;
00672             case 'contains':
00673                $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
00674                $paramArray[] = '%' . $search . '%';
00675                break;
00676             case 'startsWith':
00677                $searchSql = "AND LOWER($fieldName) LIKE LOWER(?)";
00678                $paramArray[] = $search . '%';
00679                break;
00680          }
00681       } elseif (!empty($search)) switch ($searchType) {
00682          case USER_FIELD_USERID:
00683             $searchSql = 'AND user_id=?';
00684             $paramArray[] = $search;
00685             break;
00686          case USER_FIELD_INITIAL:
00687             $searchSql = 'AND (LOWER(last_name) LIKE LOWER(?) OR LOWER(username) LIKE LOWER(?))';
00688             $paramArray[] = $search . '%';
00689             $paramArray[] = $search . '%';
00690             break;
00691       }
00692 
00693       // If we are sorting a column, we'll need to configure the additional join conditions
00694       $sortSelect = '';
00695       $joinComplete = $joinIncomplete = false;
00696       $selectQuality = $selectLatest = $selectComplete = $selectAverage = $selectIncomplete = false;
00697       if($sortBy) switch($sortBy) {
00698          case 'quality':
00699             $selectQuality = true;
00700             break;
00701          case 'latest':
00702             $selectLatest = $joinComplete = true;
00703             break;
00704          case 'done':
00705             $selectComplete = $joinComplete = true;
00706             break;
00707          case 'average':
00708             $selectAverage = $joinComplete = true;
00709             break;
00710          case 'active':
00711             $selectIncomplete = $joinIncomplete = true;
00712             break;
00713       }
00714 
00715       $sql = 'SELECT DISTINCT
00716                u.user_id,
00717                u.last_name,
00718                ar.review_id ' .
00719                ($selectQuality ? ', AVG(ar.quality) AS average_quality ' : '') .
00720                ($selectLatest ? ', MAX(ac.date_notified) AS latest ' : '') .
00721                ($selectComplete ? ', COUNT(ac.review_id) AS completed ' : '') .
00722                ($selectAverage ? ', AVG(ac.date_completed-ac.date_notified) AS average ' : '') .
00723                ($selectIncomplete ? ', COUNT(ai.review_id) AS incomplete ' : '') .
00724             'FROM roles r, users u
00725                LEFT JOIN review_assignments ar ON (ar.reviewer_id = u.user_id AND ar.cancelled = 0 AND ar.paper_id = ? AND ar.stage = ?) ' .
00726                ($joinComplete ? 'LEFT JOIN review_assignments ac ON (ac.reviewer_id = u.user_id AND ac.date_completed IS NOT NULL) ' : '') .
00727                ($joinIncomplete ? 'LEFT JOIN review_assignments ai ON (ai.reviewer_id = u.user_id AND ai.date_completed IS NULL) ' : '') .
00728                ($joinInterests ? 'LEFT JOIN user_settings s ON (u.user_id = s.user_id AND s.setting_name = ?) ' : '') . 
00729             'WHERE u.user_id = r.user_id AND
00730                r.sched_conf_id = ? AND
00731                r.role_id = ? ' . $searchSql . ' ' .
00732             'GROUP BY u.user_id, u.last_name, ar.review_id ' .
00733             ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : '');
00734 
00735       $result =& $this->retrieveRange(
00736          $sql,$paramArray, $rangeInfo
00737       );
00738 
00739       $returner = new DAOResultFactory($result, $this, '_returnReviewerUserFromRow');
00740       return $returner;
00741    }
00742 
00743    function &_returnReviewerUserFromRow(&$row) { // FIXME
00744       $user =& $this->userDao->getUser($row['user_id']);
00745       $user->review_id = $row['review_id'];
00746 
00747       HookRegistry::call('TrackDirectorSubmissionDAO::_returnReviewerUserFromRow', array(&$user, &$row));
00748 
00749       return $user;
00750    }
00751 
00758    function &getReviewersNotAssignedToPaper($schedConfId, $paperId) {
00759       $users = array();
00760 
00761       $result =& $this->retrieve(
00762          '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',
00763          array($paperId, $schedConfId, RoleDAO::getRoleIdFromPath('reviewer'))
00764       );
00765 
00766       while (!$result->EOF) {
00767          $users[] =& $this->userDao->_returnUserFromRowWithData($result->GetRowAssoc(false));
00768          $result->moveNext();
00769       }
00770 
00771       $result->Close();
00772       unset($result);
00773 
00774       return $users;
00775    }
00776 
00781    function getReviewerStatistics($schedConfId) {
00782       $statistics = Array();
00783 
00784       // Get latest review request date
00785       $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);
00786       while (!$result->EOF) {
00787          $row = $result->GetRowAssoc(false);
00788          if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
00789          $statistics[$row['reviewer_id']]['last_notified'] = $this->datetimeFromDB($row['last_notified']);
00790          $result->MoveNext();
00791       }
00792 
00793       $result->Close();
00794       unset($result);
00795 
00796       // Get completion status
00797       $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);
00798       while (!$result->EOF) {
00799          $row = $result->GetRowAssoc(false);
00800          if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
00801          $statistics[$row['reviewer_id']]['incomplete'] = $row['incomplete'];
00802          $result->MoveNext();
00803       }
00804 
00805       $result->Close();
00806       unset($result);
00807 
00808       // Calculate time taken for completed reviews
00809       $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);
00810       while (!$result->EOF) {
00811          $row = $result->GetRowAssoc(false);
00812          if (!isset($statistics[$row['reviewer_id']])) $statistics[$row['reviewer_id']] = array();
00813 
00814          $completed = strtotime($this->datetimeFromDB($row['date_completed']));
00815          $notified = strtotime($this->datetimeFromDB($row['date_notified']));
00816          if (isset($statistics[$row['reviewer_id']]['total_span'])) {
00817             $statistics[$row['reviewer_id']]['total_span'] += $completed - $notified;
00818             $statistics[$row['reviewer_id']]['completed_review_count'] += 1;
00819          } else {
00820             $statistics[$row['reviewer_id']]['total_span'] = $completed - $notified;
00821             $statistics[$row['reviewer_id']]['completed_review_count'] = 1;
00822          }
00823 
00824          // Calculate the average length of review in weeks.
00825          $statistics[$row['reviewer_id']]['average_span'] = (($statistics[$row['reviewer_id']]['total_span'] / $statistics[$row['reviewer_id']]['completed_review_count']) / 60 / 60 / 24 / 7);
00826          $result->MoveNext();
00827       }
00828 
00829       $result->Close();
00830       unset($result);
00831 
00832       return $statistics;
00833    }
00834    
00840    function getSortMapping($heading) {
00841       switch ($heading) {
00842          case 'id': return 'p.paper_id';
00843          case 'submitDate': return 'p.date_submitted';
00844          case 'track': return 'track_abbrev';
00845          case 'authors': return 'author_name';
00846          case 'title': return 'submission_title';
00847          case 'status': return 'p.status';
00848          case 'active': return 'incomplete';    
00849          case 'reviewerName': return 'u.last_name';
00850          case 'quality': return 'average_quality';
00851          case 'done': return 'completed';
00852          case 'latest': return 'latest';
00853          case 'average': return 'average';
00854          case 'name': return 'u.last_name';
00855          default: return null;
00856       }
00857    }
00858 }
00859 
00860 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7