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

controllers/modals/editorDecision/EditorDecisionHandler.inc.php

00001 <?php
00002 
00015 import('classes.handler.Handler');
00016 
00017 // import JSON class for use with all AJAX requests
00018 import('lib.pkp.classes.core.JSONMessage');
00019 
00020 // Access decision actions constants.
00021 import('classes.workflow.EditorDecisionActionsManager');
00022 
00023 class EditorDecisionHandler extends Handler {
00027    function EditorDecisionHandler() {
00028       parent::Handler();
00029 
00030       $this->addRoleAssignment(
00031          array(ROLE_ID_SERIES_EDITOR, ROLE_ID_PRESS_MANAGER),
00032          array_merge(array(
00033             'internalReview', 'saveInternalReview',
00034             'externalReview', 'saveExternalReview',
00035             'sendReviews', 'saveSendReviews',
00036             'promote', 'savePromote',
00037             'approveProofs', 'saveApproveProof'
00038          ), $this->_getReviewRoundOps())
00039       );
00040    }
00041 
00042 
00043    //
00044    // Implement template methods from PKPHandler
00045    //
00049    function authorize(&$request, $args, $roleAssignments) {
00050       $stageId = (int) $request->getUserVar('stageId');
00051       import('classes.security.authorization.OmpEditorDecisionAccessPolicy');
00052       $this->addPolicy(new OmpEditorDecisionAccessPolicy($request, $args, $roleAssignments, 'monographId', $stageId));
00053 
00054       // Some operations need a review round id in request.
00055       $reviewRoundOps = $this->_getReviewRoundOps();
00056       import('classes.security.authorization.internal.ReviewRoundRequiredPolicy');
00057       $this->addPolicy(new ReviewRoundRequiredPolicy($request, $args, 'reviewRoundId', $reviewRoundOps));
00058 
00059       // Approve proof need monograph access policy.
00060       $router =& $request->getRouter();
00061       if ($router->getRequestedOp($request) == 'saveApproveProof') {
00062          import('classes.security.authorization.OmpMonographFileAccessPolicy');
00063          $this->addPolicy(new OmpMonographFileAccessPolicy($request, $args, $roleAssignments, MONOGRAPH_FILE_ACCESS_MODIFY));
00064       }
00065 
00066       return parent::authorize($request, $args, $roleAssignments);
00067    }
00068 
00072    function initialize(&$request, $args) {
00073       AppLocale::requireComponents(
00074          LOCALE_COMPONENT_APPLICATION_COMMON,
00075          LOCALE_COMPONENT_OMP_EDITOR,
00076          LOCALE_COMPONENT_PKP_SUBMISSION
00077       );
00078    }
00079 
00080 
00081    //
00082    // Public handler actions
00083    //
00090    function newReviewRound($args, &$request) {
00091       return $this->_initiateEditorDecision($args, $request, 'NewReviewRoundForm');
00092    }
00093 
00100    function saveNewReviewRound($args, &$request) {
00101       // Retrieve the authorized monograph.
00102       $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00103       // FIXME: this can probably all be managed somewhere.
00104       $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00105       if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW) {
00106          $redirectOp = WORKFLOW_STAGE_PATH_INTERNAL_REVIEW;
00107       } elseif ($stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
00108          $redirectOp = WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW;
00109       } else {
00110          assert(false);
00111       }
00112 
00113       return $this->_saveEditorDecision($args, $request, 'NewReviewRoundForm', $redirectOp, SUBMISSION_EDITOR_DECISION_RESUBMIT);
00114    }
00115 
00122    function internalReview($args, &$request) {
00123       return $this->_initiateEditorDecision($args, $request, 'InitiateInternalReviewForm');
00124    }
00125 
00132    function saveInternalReview($args, &$request) {
00133       assert($this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE) == WORKFLOW_STAGE_ID_SUBMISSION);
00134       return $this->_saveEditorDecision(
00135          $args, $request, 'InitiateInternalReviewForm',
00136          WORKFLOW_STAGE_PATH_INTERNAL_REVIEW,
00137          SUBMISSION_EDITOR_DECISION_INTERNAL_REVIEW
00138       );
00139    }
00140 
00147    function externalReview($args, &$request) {
00148       return $this->_initiateEditorDecision($args, $request, 'InitiateExternalReviewForm');
00149    }
00150 
00157    function saveExternalReview($args, &$request) {
00158       assert($this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE) == WORKFLOW_STAGE_ID_SUBMISSION);
00159       return $this->_saveEditorDecision(
00160          $args, $request, 'InitiateExternalReviewForm',
00161          WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW,
00162          SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW
00163       );
00164    }
00165 
00172    function sendReviews($args, &$request) {
00173       return $this->_initiateEditorDecision($args, $request, 'SendReviewsForm');
00174    }
00175 
00185    function sendReviewsInReview($args, &$request) {
00186       return $this->_initiateEditorDecision($args, $request, 'SendReviewsForm');
00187    }
00188 
00195    function saveSendReviews($args, &$request) {
00196       return $this->_saveEditorDecision($args, $request, 'SendReviewsForm');
00197    }
00198 
00205    function saveSendReviewsInReview($args, &$request) {
00206       return $this->_saveEditorDecision($args, $request, 'SendReviewsForm');
00207    }
00208 
00215    function promote($args, &$request) {
00216       return $this->_initiateEditorDecision($args, $request, 'PromoteForm');
00217    }
00218 
00227    function promoteInReview($args, &$request) {
00228       return $this->_initiateEditorDecision($args, $request, 'PromoteForm');
00229    }
00230 
00237    function savePromote($args, &$request) {
00238       return $this->_saveGeneralPromote($args, $request);
00239    }
00240 
00248    function savePromoteInReview($args, &$request) {
00249       return $this->_saveGeneralPromote($args, $request);
00250    }
00251 
00258    function importPeerReviews($args, &$request) {
00259       // Retrieve the authorized submission.
00260       $seriesEditorSubmission =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00261 
00262       // Retrieve the current review round.
00263       $reviewRound =& $this->getAuthorizedContextObject(ASSOC_TYPE_REVIEW_ROUND);
00264 
00265       // Retrieve peer reviews.
00266       import('classes.submission.seriesEditor.SeriesEditorAction');
00267       $seriesEditorAction = new SeriesEditorAction();
00268       $peerReviews = $seriesEditorAction->getPeerReviews($seriesEditorSubmission, $reviewRound->getId());
00269 
00270       if(empty($peerReviews)) {
00271          $json = new JSONMessage(false, __('editor.review.noReviews'));
00272       } else {
00273          $json = new JSONMessage(true, $peerReviews);
00274       }
00275       return $json->getString();
00276    }
00277 
00284    function approveProofs($args, &$request) {
00285       $this->setupTemplate();
00286       $press =& $request->getPress();
00287       $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00288       $publicationFormatId = $request->getUserVar('publicationFormatId');
00289       $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO'); /* @var $publicationFormatDao PublicationFormatDAO */
00290 
00291       $publicationFormat = $publicationFormatDao->getById($publicationFormatId, $monograph->getId(), $press->getId());
00292       if (!is_a($publicationFormat, 'PublicationFormat')) {
00293          fatalError('Invalid publication format id!');
00294       }
00295 
00296       $templateMgr =& TemplateManager::getManager();
00297       $templateMgr->assign_by_ref('publicationFormat', $publicationFormat);
00298       $templateMgr->assign_by_ref('monograph', $monograph);
00299 
00300       return $templateMgr->fetchJson('controllers/modals/editorDecision/approveProofs.tpl');
00301    }
00302 
00308    function saveApproveProof($args, &$request) {
00309       $monographFile =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH_FILE);
00310       $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00311 
00312       // Make sure we only alter files associated with a publication format.
00313       if ($monographFile->getAssocType() !== ASSOC_TYPE_PUBLICATION_FORMAT) {
00314          fatalError('The requested file is not associated with any publication format.');
00315       }
00316       if ($monographFile->getViewable()) {
00317 
00318          // No longer expose the file to readers.
00319          $monographFile->setViewable(false);
00320       } else {
00321 
00322          // Expose the file to readers (e.g. via e-commerce).
00323          $monographFile->setViewable(true);
00324 
00325          // Log the approve proof event.
00326          import('classes.log.MonographLog');
00327          import('classes.log.MonographEventLogEntry'); // constants
00328          $user =& $request->getUser();
00329 
00330          $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
00331          $publicationFormat =& $publicationFormatDao->getById($monographFile->getAssocId(), $monograph->getId());
00332 
00333          MonographLog::logEvent($request, $monograph, MONOGRAPH_LOG_PROOFS_APPROVED, 'submission.event.proofsApproved', array('formatName' => $publicationFormat->getLocalizedName(),'name' => $user->getFullName(), 'username' => $user->getUsername()));
00334       }
00335 
00336       $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00337       $submissionFileDao->updateObject($monographFile);
00338 
00339       // update the monograph's file index
00340       import('classes.search.MonographSearchIndex');
00341       MonographSearchIndex::clearMonographFiles($monograph);
00342       MonographSearchIndex::indexMonographFiles($monograph);
00343 
00344       return DAO::getDataChangedEvent($monographFile->getId());
00345    }
00346 
00347    //
00348    // Private helper methods
00349    //
00357    function _initiateEditorDecision($args, &$request, $formName) {
00358       // Retrieve the decision
00359       $decision = (int)$request->getUserVar('decision');
00360 
00361       // Form handling
00362       $editorDecisionForm = $this->_getEditorDecisionForm($formName, $decision);
00363       $editorDecisionForm->initData($args, $request);
00364 
00365       $json = new JSONMessage(true, $editorDecisionForm->fetch($request));
00366       return $json->getString();
00367    }
00368 
00378    function _saveEditorDecision($args, &$request, $formName, $redirectOp = null, $decision = null) {
00379       // Retrieve the authorized monograph.
00380       $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00381       // Retrieve the decision
00382       if (is_null($decision)) {
00383          $decision = (int)$request->getUserVar('decision');
00384       }
00385 
00386       $editorDecisionForm = $this->_getEditorDecisionForm($formName, $decision);
00387       $editorDecisionForm->readInputData();
00388       if ($editorDecisionForm->validate()) {
00389          $editorDecisionForm->execute($args, $request);
00390 
00391          $notificationMgr = new NotificationManager();
00392          $notificationMgr->updateEditorDecisionNotification($monograph, $decision, $request);
00393 
00394          // Update pending revisions task notifications.
00395          $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00396          $notificationMgr->updatePendingRevisionsNotification($request, $monograph, $stageId, $decision);
00397 
00398          // Update "all reviews in" notification.
00399          $reviewRound =& $this->getAuthorizedContextObject(ASSOC_TYPE_REVIEW_ROUND);
00400          if ($reviewRound) {
00401             $notificationMgr->updateAllReviewsInNotification($request, $reviewRound);
00402             $notificationMgr->deleteAllRevisionsInNotification($request, $reviewRound);
00403          }
00404 
00405          if ($redirectOp) {
00406             $dispatcher =& $this->getDispatcher();
00407             $redirectUrl = $dispatcher->url($request, ROUTE_PAGE, null, 'workflow', $redirectOp, array($monograph->getId()));
00408             return $request->redirectUrlJson($redirectUrl);
00409          } else {
00410             // Needed to update review round status notifications.
00411             return DAO::getDataChangedEvent();
00412          }
00413       } else {
00414          $json = new JSONMessage(false);
00415       }
00416       return $json->getString();
00417    }
00418 
00423    function _getReviewRoundOps() {
00424       return array('promoteInReview', 'savePromoteInReview', 'newReviewRound', 'saveNewReviewRound', 'sendReviewsInReview', 'saveSendReviewsInReview', 'importPeerReviews');
00425    }
00426 
00433    function _getEditorDecisionForm($formName, $decision) {
00434       // Retrieve the authorized monograph.
00435       $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00436       // Retrieve the stage id
00437       $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00438 
00439       import("controllers.modals.editorDecision.form.$formName");
00440       if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
00441          $reviewRound =& $this->getAuthorizedContextObject(ASSOC_TYPE_REVIEW_ROUND);
00442          $editorDecisionForm = new $formName($monograph, $decision, $stageId, $reviewRound);
00443          // We need a different save operation in review stages to authorize
00444          // the review round object.
00445          if (is_a($editorDecisionForm, 'PromoteForm')) {
00446             $editorDecisionForm->setSaveFormOperation('savePromoteInReview');
00447          } else if (is_a($editorDecisionForm, 'SendReviewsForm')) {
00448             $editorDecisionForm->setSaveFormOperation('saveSendReviewsInReview');
00449          }
00450       } else {
00451          $editorDecisionForm = new $formName($monograph, $decision, $stageId);
00452       }
00453 
00454       if (is_a($editorDecisionForm, $formName)) {
00455          return $editorDecisionForm;
00456       } else {
00457          assert(false);
00458          return null;
00459       }
00460    }
00461 
00462    function _saveGeneralPromote($args, &$request) {
00463       // Redirect to the next workflow page after
00464       // promoting the submission.
00465       $decision = (int)$request->getUserVar('decision');
00466 
00467       $redirectOp = null;
00468 
00469       if ($decision == SUBMISSION_EDITOR_DECISION_ACCEPT) {
00470          $redirectOp = WORKFLOW_STAGE_PATH_EDITING;
00471       } elseif ($decision == SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW) {
00472          $redirectOp = WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW;
00473       } elseif ($decision == SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION) {
00474          $redirectOp = WORKFLOW_STAGE_PATH_PRODUCTION;
00475       }
00476 
00477       // Make sure user has access to the workflow stage.
00478       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00479       $redirectWorkflowStage = $userGroupDao->getIdFromPath($redirectOp);
00480       $userAccessibleWorkflowStages = $this->getAuthorizedContextObject(ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES);
00481       if (!array_key_exists($redirectWorkflowStage, $userAccessibleWorkflowStages)) {
00482          $redirectOp = null;
00483       }
00484 
00485       return $this->_saveEditorDecision($args, $request, 'PromoteForm', $redirectOp);
00486    }
00487 }
00488 
00489 ?>

Generated on Mon Sep 17 2012 13:00:01 for Open Monograph Press by  doxygen 1.7.1