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

classes/submission/seriesEditor/SeriesEditorAction.inc.php

00001 <?php
00002 
00016 // Access decision actions constants.
00017 import('classes.workflow.EditorDecisionActionsManager');
00018 import('classes.submission.common.Action');
00019 
00020 class SeriesEditorAction extends Action {
00021 
00025    function SeriesEditorAction() {
00026       parent::Action();
00027    }
00028 
00029    //
00030    // Actions.
00031    //
00041    function recordDecision($request, $seriesEditorSubmission, $decision, $decisionLabels, $reviewRound = null, $stageId = null) {
00042       $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00043 
00044       // Define the stage and round data.
00045       if (!is_null($reviewRound)) {
00046          $stageId = $reviewRound->getStageId();
00047          $round = $reviewRound->getRound();
00048       } else {
00049          $round = REVIEW_ROUND_NONE;
00050          if ($stageId == null) {
00051             // We consider that the decision is being made for the current
00052             // submission stage.
00053             $stageId = $seriesEditorSubmission->getStageId();
00054          }
00055       }
00056 
00057       $editorAssigned = $stageAssignmentDao->editorAssignedToStage(
00058          $seriesEditorSubmission->getId(),
00059          $stageId
00060       );
00061 
00062       // Sanity checks
00063       if (!$editorAssigned || !isset($decisionLabels[$decision])) return false;
00064 
00065       $seriesEditorSubmissionDao =& DAORegistry::getDAO('SeriesEditorSubmissionDAO');
00066       $user =& $request->getUser();
00067       $editorDecision = array(
00068          'editDecisionId' => null,
00069          'editorId' => $user->getId(),
00070          'decision' => $decision,
00071          'dateDecided' => date(Core::getCurrentDate())
00072       );
00073 
00074       $result = true;
00075       if (!HookRegistry::call('SeriesEditorAction::recordDecision', array(&$seriesEditorSubmission, &$editorDecision, &$result))) {
00076          $seriesEditorSubmission->setStatus(STATUS_QUEUED);
00077          $seriesEditorSubmission->stampStatusModified();
00078          $seriesEditorSubmission->addDecision(
00079             $editorDecision,
00080             $stageId,
00081             $round
00082          );
00083 
00084          $seriesEditorSubmissionDao->updateSeriesEditorSubmission($seriesEditorSubmission);
00085 
00086          // Add log.
00087          import('classes.log.MonographLog');
00088          import('classes.log.MonographEventLogEntry');
00089          AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON, LOCALE_COMPONENT_OMP_EDITOR);
00090          MonographLog::logEvent($request, $seriesEditorSubmission, MONOGRAPH_LOG_EDITOR_DECISION, 'log.editor.decision', array('editorName' => $user->getFullName(), 'monographId' => $seriesEditorSubmission->getId(), 'decision' => __($decisionLabels[$decision])));
00091       }
00092       return $result;
00093    }
00094 
00101    function assignDefaultStageParticipants(&$monograph, $stageId, &$request) {
00102       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00103 
00104       // Managerial roles are skipped -- They have access by default and
00105       //  are assigned for informational purposes only
00106 
00107       // Series editor roles are skipped -- They are assigned by PM roles
00108       //  or by other series editors
00109 
00110       // Press roles -- For each press role user group assigned to this
00111       //  stage in setup, iff there is only one user for the group,
00112       //  automatically assign the user to the stage
00113       // But skip authors and reviewers, since these are very monograph specific
00114       $stageAssignmentDao =& DAORegistry::getDAO('StageAssignmentDAO');
00115       $submissionStageGroups =& $userGroupDao->getUserGroupsByStage($monograph->getPressId(), $stageId, true, true);
00116       while ($userGroup =& $submissionStageGroups->next()) {
00117          $users =& $userGroupDao->getUsersById($userGroup->getId());
00118          if($users->getCount() == 1) {
00119             $user =& $users->next();
00120             $stageAssignmentDao->build($monograph->getId(), $userGroup->getId(), $user->getId());
00121          }
00122       }
00123 
00124       // Update NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_...
00125       $notificationMgr = new NotificationManager();
00126       $notificationMgr->updateEditorAssignmentNotification($monograph, $stageId, $request);
00127 
00128       // Reviewer roles -- Do nothing. Reviewers are not included in the stage participant list, they
00129       // are administered via review assignments.
00130 
00131       // Author roles
00132       // Assign only the submitter in whatever ROLE_ID_AUTHOR capacity they were assigned previously
00133       $submitterAssignments =& $stageAssignmentDao->getBySubmissionAndStageId($monograph->getId(), null, null, $monograph->getUserId());
00134       while ($assignment =& $submitterAssignments->next()) {
00135          $userGroup =& $userGroupDao->getById($assignment->getUserGroupId());
00136          if ($userGroup->getRoleId() == ROLE_ID_AUTHOR) {
00137             $stageAssignmentDao->build($monograph->getId(), $userGroup->getId(), $assignment->getUserId());
00138             // Only assign them once, since otherwise we'll one assignment for each previous stage.
00139             // And as long as they are assigned once, they will get access to their monograph.
00140             break;
00141          }
00142          unset($assignment, $userGroup);
00143       }
00144    }
00145 
00152    function incrementWorkflowStage(&$monograph, $newStage, &$request) {
00153       // Change the monograph's workflow stage.
00154       $monograph->setStageId($newStage);
00155       $monographDao =& DAORegistry::getDAO('MonographDAO'); /* @var $monographDao MonographDAO */
00156       $monographDao->updateMonograph($monograph);
00157 
00158       // Assign the default users to the next workflow stage.
00159       $this->assignDefaultStageParticipants($monograph, $newStage, $request);
00160    }
00161 
00171    function addReviewer($request, $seriesEditorSubmission, $reviewerId, &$reviewRound, $reviewDueDate = null, $responseDueDate = null, $reviewMethod = null) {
00172       $seriesEditorSubmissionDao =& DAORegistry::getDAO('SeriesEditorSubmissionDAO');
00173       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00174       $userDao =& DAORegistry::getDAO('UserDAO');
00175 
00176       $reviewer =& $userDao->getById($reviewerId);
00177 
00178       // Check to see if the requested reviewer is not already
00179       // assigned to review this monograph.
00180       $assigned = $seriesEditorSubmissionDao->reviewerExists($reviewRound->getId(), $reviewerId);
00181 
00182       // Only add the reviewer if he has not already
00183       // been assigned to review this monograph.
00184       $stageId = $reviewRound->getStageId();
00185       $round = $reviewRound->getRound();
00186       if (!$assigned && isset($reviewer) && !HookRegistry::call('SeriesEditorAction::addReviewer', array(&$seriesEditorSubmission, $reviewerId))) {
00187          $reviewAssignment = new ReviewAssignment();
00188          $reviewAssignment->setSubmissionId($seriesEditorSubmission->getId());
00189          $reviewAssignment->setReviewerId($reviewerId);
00190          $reviewAssignment->setDateAssigned(Core::getCurrentDate());
00191          $reviewAssignment->setStageId($stageId);
00192          $reviewAssignment->setRound($round);
00193          $reviewAssignment->setReviewRoundId($reviewRound->getId());
00194          if (isset($reviewMethod)) {
00195             $reviewAssignment->setReviewMethod($reviewMethod);
00196          }
00197          $reviewAssignmentDao->insertObject($reviewAssignment);
00198 
00199          $seriesEditorSubmission->addReviewAssignment($reviewAssignment);
00200          $seriesEditorSubmissionDao->updateSeriesEditorSubmission($seriesEditorSubmission);
00201 
00202          $this->setDueDates($request, $seriesEditorSubmission, $reviewAssignment, $reviewDueDate, $responseDueDate);
00203 
00204          // Add notification
00205          $notificationMgr = new NotificationManager();
00206          $notificationMgr->createNotification(
00207             $request,
00208             $reviewerId,
00209             NOTIFICATION_TYPE_REVIEW_ASSIGNMENT,
00210             $seriesEditorSubmission->getPressId(),
00211             ASSOC_TYPE_REVIEW_ASSIGNMENT,
00212             $reviewAssignment->getId(),
00213             NOTIFICATION_LEVEL_TASK
00214          );
00215 
00216          // Insert a trivial notification to indicate the reviewer was added successfully.
00217          $currentUser =& $request->getUser();
00218          $notificationMgr = new NotificationManager();
00219          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedReviewer')));
00220 
00221          // Update the review round status.
00222          $reviewRoundDao =& DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
00223          $reviewAssignments = $seriesEditorSubmission->getReviewAssignments($stageId, $round);
00224          $reviewRoundDao->updateStatus($reviewRound, $reviewAssignments);
00225 
00226          // Update "all reviews in" notification.
00227          $notificationMgr->updateAllReviewsInNotification($request, $reviewRound);
00228 
00229          // Add log
00230          import('classes.log.MonographLog');
00231          import('classes.log.MonographEventLogEntry');
00232          MonographLog::logEvent($request, $seriesEditorSubmission, MONOGRAPH_LOG_REVIEW_ASSIGN, 'log.review.reviewerAssigned', array('reviewerName' => $reviewer->getFullName(), 'monographId' => $seriesEditorSubmission->getId(), 'stageId' => $stageId, 'round' => $round));
00233       }
00234    }
00235 
00241    function clearReview($request, $submissionId, $reviewId) {
00242       $seriesEditorSubmissionDao =& DAORegistry::getDAO('SeriesEditorSubmissionDAO'); /* @var $seriesEditorSubmissionDao SeriesEditorSubmissionDAO */
00243       $seriesEditorSubmission =& $seriesEditorSubmissionDao->getById($submissionId);
00244       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00245       $userDao =& DAORegistry::getDAO('UserDAO');
00246 
00247       $reviewAssignment =& $reviewAssignmentDao->getById($reviewId);
00248 
00249       if (isset($reviewAssignment) && $reviewAssignment->getSubmissionId() == $seriesEditorSubmission->getId() && !HookRegistry::call('SeriesEditorAction::clearReview', array(&$seriesEditorSubmission, $reviewAssignment))) {
00250          $reviewer =& $userDao->getById($reviewAssignment->getReviewerId());
00251          if (!isset($reviewer)) return false;
00252          $seriesEditorSubmission->removeReviewAssignment($reviewId);
00253          $seriesEditorSubmissionDao->updateSeriesEditorSubmission($seriesEditorSubmission);
00254 
00255          $notificationDao =& DAORegistry::getDAO('NotificationDAO');
00256          $notificationDao->deleteByAssoc(
00257             ASSOC_TYPE_REVIEW_ASSIGNMENT,
00258             $reviewAssignment->getId(),
00259             $reviewAssignment->getReviewerId(),
00260             NOTIFICATION_TYPE_REVIEW_ASSIGNMENT
00261          );
00262 
00263          // Insert a trivial notification to indicate the reviewer was removed successfully.
00264          $currentUser =& $request->getUser();
00265          $notificationMgr = new NotificationManager();
00266          $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedReviewer')));
00267 
00268          // Update the review round status, if needed.
00269          $reviewRoundDao =& DAORegistry::getDAO('ReviewRoundDAO');
00270          $reviewRound =& $reviewRoundDao->getReviewRoundById($reviewAssignment->getReviewRoundId());
00271          $reviewAssignments = $seriesEditorSubmission->getReviewAssignments($reviewRound->getStageId(), $reviewRound->getRound());
00272          $reviewRoundDao->updateStatus($reviewRound, $reviewAssignments);
00273 
00274          // Update "all reviews in" notification.
00275          $notificationMgr->updateAllReviewsInNotification($request, $reviewRound);
00276 
00277          // Add log
00278          import('classes.log.MonographLog');
00279          import('classes.log.MonographEventLogEntry');
00280          MonographLog::logEvent($request, $seriesEditorSubmission, MONOGRAPH_LOG_REVIEW_CLEAR, 'log.review.reviewCleared', array('reviewerName' => $reviewer->getFullName(), 'monographId' => $seriesEditorSubmission->getId(), 'stageId' => $reviewAssignment->getStageId(), 'round' => $reviewAssignment->getRound()));
00281 
00282          return true;
00283       } else return false;
00284    }
00285 
00295    function setDueDates($request, $monograph, $reviewAssignment, $reviewDueDate = null, $responseDueDate = null, $logEntry = false) {
00296       $userDao =& DAORegistry::getDAO('UserDAO');
00297       $press =& $request->getContext();
00298 
00299       $reviewer =& $userDao->getById($reviewAssignment->getReviewerId());
00300       if (!isset($reviewer)) return false;
00301 
00302       if ($reviewAssignment->getSubmissionId() == $monograph->getId() && !HookRegistry::call('SeriesEditorAction::setDueDates', array(&$reviewAssignment, &$reviewer, &$reviewDueDate, &$responseDueDate))) {
00303 
00304          // Set the review due date
00305          $defaultNumWeeks = $press->getSetting('numWeeksPerReview');
00306          $reviewAssignment->setDateDue(DAO::formatDateToDB($reviewDueDate, $defaultNumWeeks, false));
00307 
00308          // Set the response due date
00309          $defaultNumWeeks = $press->getSetting('numWeeksPerReponse');
00310          $reviewAssignment->setDateResponseDue(DAO::formatDateToDB($responseDueDate, $defaultNumWeeks, false));
00311 
00312          // update the assignment (with both the new dates)
00313          $reviewAssignment->stampModified();
00314          $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
00315          $reviewAssignmentDao->updateObject($reviewAssignment);
00316 
00317          // N.B. Only logging Date Due
00318          if ($logEntry) {
00319             // Add log
00320             import('classes.log.MonographLog');
00321             import('classes.log.MonographEventLogEntry');
00322             MonographLog::logEvent(
00323                $request,
00324                $monograph,
00325                MONOGRAPH_LOG_REVIEW_SET_DUE_DATE,
00326                'log.review.reviewDueDateSet',
00327                array(
00328                   'reviewerName' => $reviewer->getFullName(),
00329                   'dueDate' => strftime(
00330                      Config::getVar('general', 'date_format_short'),
00331                      strtotime($reviewAssignment->getDateDue())
00332                   ),
00333                   'monographId' => $monograph->getId(),
00334                   'stageId' => $reviewAssignment->getStageId(),
00335                   'round' => $reviewAssignment->getRound()
00336                )
00337             );
00338          }
00339       }
00340    }
00341 
00348    function getPeerReviews($seriesEditorSubmission, $reviewRoundId) {
00349       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00350       $monographCommentDao =& DAORegistry::getDAO('MonographCommentDAO');
00351       $reviewFormResponseDao =& DAORegistry::getDAO('ReviewFormResponseDAO');
00352       $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00353 
00354       $reviewAssignments =& $reviewAssignmentDao->getBySubmissionId($seriesEditorSubmission->getId(), $reviewRoundId);
00355       $reviewIndexes =& $reviewAssignmentDao->getReviewIndexesForRound($seriesEditorSubmission->getId(), $reviewRoundId);
00356       AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION);
00357 
00358       $body = '';
00359       $textSeparator = "------------------------------------------------------";
00360       foreach ($reviewAssignments as $reviewAssignment) {
00361          // If the reviewer has completed the assignment, then import the review.
00362          if ($reviewAssignment->getDateCompleted() != null && !$reviewAssignment->getCancelled()) {
00363             // Get the comments associated with this review assignment
00364             $monographComments =& $monographCommentDao->getMonographComments($seriesEditorSubmission->getId(), COMMENT_TYPE_PEER_REVIEW, $reviewAssignment->getId());
00365 
00366             $body .= "\n\n$textSeparator\n";
00367             // If it is not a double blind review, show reviewer's name.
00368             if ($reviewAssignment->getReviewMethod() != SUBMISSION_REVIEW_METHOD_DOUBLEBLIND) {
00369                $body .= $reviewAssignment->getReviewerFullName() . "\n";
00370             } else {
00371                $body .= __('submission.comments.importPeerReviews.reviewerLetter', array('reviewerLetter' => String::enumerateAlphabetically($reviewIndexes[$reviewAssignment->getId()]))) . "\n";
00372             }
00373 
00374             while ($comment =& $monographComments->next()) {
00375                // If the comment is viewable by the author, then add the comment.
00376                if ($comment->getViewable()) {
00377                   $body .= String::html2text($comment->getComments()) . "\n\n";
00378                }
00379                unset($comment);
00380             }
00381             $body .= "$textSeparator\n\n";
00382 
00383             if ($reviewFormId = $reviewAssignment->getReviewFormId()) {
00384                $reviewId = $reviewAssignment->getId();
00385 
00386 
00387                $reviewFormElements =& $reviewFormElementDao->getReviewFormElements($reviewFormId);
00388                if(!$monographComments) {
00389                   $body .= "$textSeparator\n";
00390 
00391                   $body .= __('submission.comments.importPeerReviews.reviewerLetter', array('reviewerLetter' => String::enumerateAlphabetically($reviewIndexes[$reviewAssignment->getId()]))) . "\n\n";
00392                }
00393                foreach ($reviewFormElements as $reviewFormElement) {
00394                   $body .= String::html2text($reviewFormElement->getLocalizedQuestion()) . ": \n";
00395                   $reviewFormResponse = $reviewFormResponseDao->getReviewFormResponse($reviewId, $reviewFormElement->getId());
00396 
00397                   if ($reviewFormResponse) {
00398                      $possibleResponses = $reviewFormElement->getLocalizedPossibleResponses();
00399                      if (in_array($reviewFormElement->getElementType(), $reviewFormElement->getMultipleResponsesElementTypes())) {
00400                         if ($reviewFormElement->getElementType() == REVIEW_FORM_ELEMENT_TYPE_CHECKBOXES) {
00401                            foreach ($reviewFormResponse->getValue() as $value) {
00402                               $body .= "\t" . String::htmltext($possibleResponses[$value-1]['content']) . "\n";
00403                            }
00404                         } else {
00405                            $body .= "\t" . String::html2text($possibleResponses[$reviewFormResponse->getValue()-1]['content']) . "\n";
00406                         }
00407                         $body .= "\n";
00408                      } else {
00409                         $body .= "\t" . String::html2text($reviewFormResponse->getValue()) . "\n\n";
00410                      }
00411                   }
00412 
00413                }
00414                $body .= "$textSeparator\n\n";
00415 
00416             }
00417 
00418 
00419          }
00420       }
00421 
00422       return $body;
00423    }
00424 }
00425 
00426 ?>

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