• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/monograph/reviewRound/ReviewRoundDAO.inc.php

00001 <?php
00002 
00016 import('classes.monograph.reviewRound.ReviewRound');
00017 
00018 class ReviewRoundDAO extends DAO {
00022    function ReviewRoundDAO() {
00023       parent::DAO();
00024    }
00025 
00026    //
00027    // Public methods
00028    //
00037    function build($submissionId, $stageId, $round, $status = null) {
00038       // If one exists, fetch and return.
00039       $reviewRound = $this->getReviewRound($submissionId, $stageId, $round);
00040       if ($reviewRound) return $reviewRound;
00041 
00042       // Otherwise, check the args to build one.
00043       if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW ||
00044       $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW &&
00045       $round > 0) {
00046          unset($reviewRound);
00047          $reviewRound =& $this->newDataObject();
00048          $reviewRound->setSubmissionId($submissionId);
00049          $reviewRound->setRound($round);
00050          $reviewRound->setStageId($stageId);
00051          $reviewRound->setStatus($status);
00052          $this->insertObject($reviewRound);
00053          $reviewRound->setId($this->getInsertReviewRoundId());
00054 
00055          return $reviewRound;
00056       } else {
00057          assert(false);
00058          return null;
00059       }
00060    }
00061 
00066    function newDataObject() {
00067       return new ReviewRound();
00068    }
00069 
00075    function insertObject(&$reviewRound) {
00076       $this->update(
00077             'INSERT INTO review_rounds
00078             (submission_id, stage_id, round, status)
00079             VALUES
00080             (?, ?, ?, ?)',
00081             array(
00082                (int)$reviewRound->getSubmissionId(),
00083                (int)$reviewRound->getStageId(),
00084                (int)$reviewRound->getRound(),
00085                (int)$reviewRound->getStatus()
00086             )
00087       );
00088       return $reviewRound;
00089    }
00090 
00096    function updateObject(&$reviewRound) {
00097       $returner = $this->update(
00098          'UPDATE  review_rounds
00099          SET   status = ?
00100          WHERE submission_id = ? AND
00101             stage_id = ? AND
00102             round = ?',
00103          array(
00104             (int)$reviewRound->getStatus(),
00105             (int)$reviewRound->getSubmissionId(),
00106             (int)$reviewRound->getStageId(),
00107             (int)$reviewRound->getRound()
00108          )
00109       );
00110       return $returner;
00111    }
00112 
00119    function getReviewRound($submissionId, $stageId, $round) {
00120       $result =& $this->retrieve(
00121             'SELECT * FROM review_rounds WHERE submission_id = ? AND stage_id = ? AND round = ?',
00122             array((int)$submissionId, (int)$stageId, (int)$round));
00123 
00124       $returner = null;
00125       if ($result->RecordCount() != 0) {
00126          $returner = $this->_fromRow($result->GetRowAssoc(false));
00127       }
00128       $result->Close();
00129       return $returner;
00130    }
00131 
00137    function &getReviewRoundById($reviewRoundId) {
00138       $result =& $this->retrieve(
00139             'SELECT * FROM review_rounds WHERE review_round_id = ?',
00140             array((int)$reviewRoundId));
00141 
00142       $returner = null;
00143       if ($result->RecordCount() != 0) {
00144          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00145       }
00146       $result->Close();
00147       return $returner;
00148    }
00149 
00155    function &getByMonographFileId($monographFileId) {
00156       $result =& $this->retrieve(
00157             'SELECT * FROM review_rounds rr
00158             INNER JOIN review_round_files rrf
00159             ON rr.review_round_id = rrf.review_round_id
00160             WHERE rrf.file_id = ?',
00161             array((int) $monographFileId));
00162 
00163       $returner = null;
00164       if ($result->RecordCount() != 0) {
00165          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00166       }
00167       $result->Close();
00168       return $returner;
00169    }
00170 
00177    function reviewRoundExists($monographId, $stageId, $round) {
00178       $result =& $this->retrieve(
00179             'SELECT COUNT(*) FROM review_rounds WHERE submission_id = ? AND stage_id = ? AND round = ?',
00180             array((int)$monographId, (int)$stageId, (int)$round));
00181       $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00182 
00183       $result->Close();
00184       unset($result);
00185 
00186       return $returner;
00187    }
00188 
00195    function &getByMonographId($monographId, $stageId = null, $round = null) {
00196       $params = array($monographId);
00197       if ($stageId) $params[] = $stageId;
00198       if ($round) $params[] = $round;
00199 
00200       $result =& $this->retrieve(
00201             'SELECT * FROM review_rounds WHERE submission_id = ?' .
00202             ($stageId ? ' AND stage_id = ?' : '') .
00203             ($round ? ' AND round = ?' : '') .
00204             ' ORDER BY stage_id ASC, round ASC',
00205             $params
00206             );
00207 
00208       $returner = new DAOResultFactory($result, $this, '_fromRow');
00209       return $returner;
00210    }
00211 
00218    function getCurrentRoundByMonographId($monographId, $stageId = null) {
00219       $params = array((int)$monographId);
00220       if ($stageId) $params[] = (int) $stageId;
00221       $result =& $this->retrieve('SELECT MAX(stage_id) as stage_id, MAX(round) as round
00222                            FROM review_rounds
00223                            WHERE submission_id = ?' .
00224                            ($stageId ? ' AND stage_id = ?' : ''),
00225                            $params);
00226       $returner = isset($result->fields['round']) ? (int)$result->fields['round'] : 1;
00227       $result->Close();
00228       return $returner;
00229    }
00230 
00237    function &getLastReviewRoundByMonographId($monographId, $stageId = null) {
00238       $params = array((int)$monographId);
00239       if ($stageId) $params[] = (int) $stageId;
00240       $result =& $this->retrieve(
00241          'SELECT  *
00242          FROM  review_rounds
00243          WHERE submission_id = ?
00244          ' . ($stageId ? ' AND stage_id = ?' : '') . '
00245          ORDER BY stage_id DESC, round DESC
00246          LIMIT 1',
00247          $params
00248       );
00249 
00250       $returner = null;
00251       if ($result->RecordCount() != 0) {
00252          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00253       }
00254       $result->Close();
00255       return $returner;
00256    }
00257 
00262    function getInsertReviewRoundId() {
00263       return $this->getInsertId('review_rounds', 'user_id');
00264    }
00265 
00275    function updateStatus(&$reviewRound, $reviewAssignments = array(), $status = null) {
00276       assert(is_a($reviewRound, 'ReviewRound'));
00277       $currentStatus = $reviewRound->getStatus();
00278 
00279       if (is_null($status)) {
00280          assert(is_array($reviewAssignments));
00281 
00282          $viewsDao =& DAORegistry::getDAO('ViewsDAO'); /* @var $viewsDao ViewsDAO */
00283          $anyUnreadReview = false;
00284          $anyIncompletedReview = false;
00285 
00286          foreach ($reviewAssignments as $reviewAssignment) { /* @var $reviewAssignment ReviewAssignment */
00287             // Skip cancelled and declined reviews.
00288             if ($reviewAssignment->getCancelled() ||
00289             $reviewAssignment->getDeclined()) {
00290                continue;
00291             }
00292 
00293             // Check for an incomplete review.
00294             if (!$reviewAssignment->getDateCompleted()) {
00295                $anyIncompletedReview = true;
00296             }
00297 
00298             // Check for an unread or unconsidered review.
00299             if (!$viewsDao->getLastViewDate(ASSOC_TYPE_REVIEW_RESPONSE, $reviewAssignment->getId()) || $reviewAssignment->getUnconsidered() == REVIEW_ASSIGNMENT_UNCONSIDERED) {
00300                $anyUnreadReview = true;
00301 
00302             }
00303          }
00304 
00305          // Find the correct review round status based on the state of
00306          // the current review assignments. The check order matters: the
00307          // first conditions override the others.
00308          if (empty($reviewAssignments)) {
00309             $status = REVIEW_ROUND_STATUS_PENDING_REVIEWERS;
00310          } else if ($anyIncompletedReview) {
00311             $status = REVIEW_ROUND_STATUS_PENDING_REVIEWS;
00312          } else if ($anyUnreadReview) {
00313             $status = REVIEW_ROUND_STATUS_REVIEWS_READY;
00314          } else {
00315             $status = REVIEW_ROUND_STATUS_REVIEWS_COMPLETED;
00316          }
00317 
00318          // Check for special cases where we don't want to update the status.
00319          if (in_array($status, array(REVIEW_ROUND_STATUS_REVIEWS_COMPLETED,
00320          REVIEW_ROUND_STATUS_REVIEWS_READY))) {
00321             if (in_array($reviewRound->getStatus(), $this->getEditorDecisionRoundStatus())) {
00322                // We will skip changing the current review round status to
00323                // "reviews completed" or "reviews ready" if the current round
00324                // status is related with an editor decision.
00325                return;
00326             }
00327          }
00328 
00329          // Don't update the review round status if it isn't the
00330          // stage's current one.
00331          $lastReviewRound =& $this->getLastReviewRoundByMonographId($reviewRound->getSubmissionId(), $reviewRound->getStageId());
00332          if ($lastReviewRound->getId() != $reviewRound->getId()) {
00333             return;
00334          }
00335       }
00336 
00337       // Avoid unnecessary database access.
00338       if ($status != $currentStatus) {
00339          $params = array((int)$status, (int)$reviewRound->getId());
00340          $this->update('UPDATE review_rounds SET status = ? WHERE review_round_id = ?', $params);
00341          // Update the data in object too.
00342          $reviewRound->setStatus($status);
00343       }
00344    }
00345 
00351    function getEditorDecisionRoundStatus() {
00352       return array(
00353          REVIEW_ROUND_STATUS_REVISIONS_REQUESTED,
00354          REVIEW_ROUND_STATUS_RESUBMITTED,
00355          REVIEW_ROUND_STATUS_SENT_TO_EXTERNAL,
00356          REVIEW_ROUND_STATUS_ACCEPTED,
00357          REVIEW_ROUND_STATUS_DECLINED
00358       );
00359    }
00360 
00361 
00362    //
00363    // Private methods
00364    //
00370    function &_fromRow(&$row) {
00371       $reviewRound = $this->newDataObject();
00372 
00373       $reviewRound->setId((int)$row['review_round_id']);
00374       $reviewRound->setSubmissionId((int)$row['submission_id']);
00375       $reviewRound->setStageId((int)$row['stage_id']);
00376       $reviewRound->setRound((int)$row['round']);
00377       $reviewRound->setStatus((int)$row['status']);
00378 
00379       return $reviewRound;
00380    }
00381 }
00382 
00383 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1