00001 <?php
00002
00015 import('classes.handler.Handler');
00016
00017
00018 import('lib.pkp.classes.core.JSONMessage');
00019
00020
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
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
00055 $reviewRoundOps = $this->_getReviewRoundOps();
00056 import('classes.security.authorization.internal.ReviewRoundRequiredPolicy');
00057 $this->addPolicy(new ReviewRoundRequiredPolicy($request, $args, 'reviewRoundId', $reviewRoundOps));
00058
00059
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
00083
00090 function newReviewRound($args, &$request) {
00091 return $this->_initiateEditorDecision($args, $request, 'NewReviewRoundForm');
00092 }
00093
00100 function saveNewReviewRound($args, &$request) {
00101
00102 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00103
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
00260 $seriesEditorSubmission =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00261
00262
00263 $reviewRound =& $this->getAuthorizedContextObject(ASSOC_TYPE_REVIEW_ROUND);
00264
00265
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');
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
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
00319 $monographFile->setViewable(false);
00320 } else {
00321
00322
00323 $monographFile->setViewable(true);
00324
00325
00326 import('classes.log.MonographLog');
00327 import('classes.log.MonographEventLogEntry');
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
00340 import('classes.search.MonographSearchIndex');
00341 MonographSearchIndex::clearMonographFiles($monograph);
00342 MonographSearchIndex::indexMonographFiles($monograph);
00343
00344 return DAO::getDataChangedEvent($monographFile->getId());
00345 }
00346
00347
00348
00349
00357 function _initiateEditorDecision($args, &$request, $formName) {
00358
00359 $decision = (int)$request->getUserVar('decision');
00360
00361
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
00380 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00381
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
00395 $stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
00396 $notificationMgr->updatePendingRevisionsNotification($request, $monograph, $stageId, $decision);
00397
00398
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
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
00435 $monograph =& $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00436
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
00444
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
00464
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
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 ?>