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

controllers/modals/editorDecision/form/EditorDecisionWithEmailForm.inc.php

00001 <?php
00002 
00015 import('controllers.modals.editorDecision.form.EditorDecisionForm');
00016 
00017 class EditorDecisionWithEmailForm extends EditorDecisionForm {
00018 
00020    var $_saveFormOperation;
00021 
00030    function EditorDecisionWithEmailForm(&$seriesEditorSubmission, $decision, $stageId, $template, $reviewRound = null) {
00031       parent::EditorDecisionForm($seriesEditorSubmission, $decision, $stageId, $template, $reviewRound);
00032    }
00033 
00034    //
00035    // Getters and Setters
00036    //
00041    function getSaveFormOperation() {
00042       return $this->_saveFormOperation;
00043    }
00044 
00049    function setSaveFormOperation($saveFormOperation) {
00050       $this->_saveFormOperation = $saveFormOperation;
00051    }
00052 
00053    //
00054    // Implement protected template methods from Form
00055    //
00060    function initData($args, &$request, $actionLabels) {
00061       $press =& $request->getPress();
00062       $router =& $request->getRouter();
00063       $dispatcher =& $router->getDispatcher();
00064 
00065       $seriesEditorSubmission =& $this->getSeriesEditorSubmission();
00066       $submitter = $seriesEditorSubmission->getUser();
00067       $user =& $request->getUser();
00068 
00069       import('classes.mail.MonographMailTemplate');
00070       $emailKeys = array(
00071             SUBMISSION_EDITOR_DECISION_ACCEPT => 'EDITOR_DECISION_ACCEPT',
00072             SUBMISSION_EDITOR_DECISION_DECLINE => 'EDITOR_DECISION_DECLINE',
00073             SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW => 'EDITOR_DECISION_SEND_TO_EXTERNAL',
00074             SUBMISSION_EDITOR_DECISION_RESUBMIT => 'EDITOR_DECISION_RESUBMIT',
00075             SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS => 'EDITOR_DECISION_REVISIONS',
00076             SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION => 'EDITOR_DECISION_SEND_TO_PRODUCTION',
00077          );
00078 
00079       $email = new MonographMailTemplate($seriesEditorSubmission, $emailKeys[$this->getDecision()]);
00080 
00081       $paramArray = array(
00082          'authorName' => $submitter->getFullName(),
00083          'pressName' => $press->getLocalizedName(),
00084          'monographTitle' => $seriesEditorSubmission->getLocalizedTitle(),
00085          'editorialContactSignature' => $user->getContactSignature(),
00086          'authorUsername' => $submitter->getUsername(),
00087          'submissionUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'authorDashboard', 'submission', $seriesEditorSubmission->getId()),
00088       );
00089       $email->assignParams($paramArray);
00090 
00091       // If we are in review stage we need a review round.
00092       $reviewRound =& $this->getReviewRound();
00093       if (is_a($reviewRound, 'ReviewRound')) {
00094          $this->setData('reviewRoundId', $reviewRound->getId());
00095       }
00096 
00097       $data = array(
00098          'monographId' => $seriesEditorSubmission->getId(),
00099          'decision' => $this->getDecision(),
00100          'authorName' => $seriesEditorSubmission->getAuthorString(),
00101          'personalMessage' => $email->getBody() . "\n" . $press->getSetting('emailSignature'),
00102          'actionLabel' => $actionLabels[$this->getDecision()]
00103       );
00104       foreach($data as $key => $value) {
00105          $this->setData($key, $value);
00106       }
00107 
00108       return parent::initData($args, $request);
00109    }
00110 
00114    function readInputData() {
00115       $this->readUserVars(array('personalMessage', 'selectedAttachments', 'skipEmail'));
00116       parent::readInputData();
00117    }
00118 
00122    function fetch(&$request) {
00123       // No all decision forms need a review round.
00124       // Try to get a review round.
00125       $reviewRound =& $this->getReviewRound();
00126 
00127       // If we have a review round, then we are in a review stage.
00128       if (is_a($reviewRound, 'ReviewRound')) {
00129          // URL to retrieve peer reviews:
00130          $router =& $request->getRouter();
00131          $submission =& $this->getSeriesEditorSubmission();
00132          $stageId = $reviewRound->getStageId();
00133          $this->setData(
00134             'peerReviewUrl',
00135             $router->url(
00136                $request, null, null,
00137                'importPeerReviews', null,
00138                array(
00139                   'monographId' => $submission->getId(),
00140                   'stageId' => $stageId,
00141                   'reviewRoundId' => $reviewRound->getId()
00142                )
00143             )
00144          );
00145       }
00146 
00147       // When this form is being used in review stages, we need a different
00148       // save operation to allow the EditorDecisionHandler authorize the review
00149       // round object.
00150       if ($this->getSaveFormOperation()) {
00151          $templateMgr =& TemplateManager::getManager();
00152          $templateMgr->assign('saveFormOperation', $this->getSaveFormOperation());
00153       }
00154 
00155       return parent::fetch($request);
00156    }
00157 
00158 
00159    //
00160    // Private helper methods
00161    //
00167    function _updateReviewRoundStatus($seriesEditorSubmission, $status, $reviewRound = null) {
00168       $reviewRoundDao =& DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
00169       if (!$reviewRound) {
00170          $reviewRound =& $reviewRoundDao->getLastReviewRoundByMonographId($seriesEditorSubmission->getId());
00171       }
00172 
00173       // If we don't have a review round, it's because the monograph is being
00174       // accepted without starting any of the review stages. In that case we
00175       // do nothing.
00176       if (is_a($reviewRound, 'ReviewRound')) {
00177          $reviewRoundDao->updateStatus($reviewRound, null, $status);
00178       }
00179    }
00180 
00189    function _sendReviewMailToAuthor(&$seriesEditorSubmission, $emailKey, $request) {
00190       // Send personal message to author.
00191       $submitter =& $seriesEditorSubmission->getUser();
00192       import('classes.mail.MonographMailTemplate');
00193       $email = new MonographMailTemplate($seriesEditorSubmission, $emailKey, null, null, null, false);
00194       $email->setBody($this->getData('personalMessage'));
00195       $email->addRecipient($submitter->getEmail(), $submitter->getFullName());
00196       $email->setEventType(MONOGRAPH_EMAIL_EDITOR_NOTIFY_AUTHOR);
00197 
00198       $userStageAssignmentDao =& DAORegistry::getDAO('UserStageAssignmentDAO');
00199       $authorStageParticipants = $userStageAssignmentDao->getUsersBySubmissionAndStageId($seriesEditorSubmission->getId(), $seriesEditorSubmission->getStageId(), null, ROLE_ID_AUTHOR);
00200       while ($author =& $authorStageParticipants->next()) {
00201          if (preg_match('{^' . quotemeta($submitter->getEmail()) . '$}', $author->getEmail())) {
00202             $email->addRecipient($author->getEmail(), $author->getFullName());
00203          } else {
00204             $email->addCc($author->getEmail(), $author->getFullName());
00205          }
00206       }
00207 
00208       // Get review round.
00209       $reviewRound =& $this->getReviewRound();
00210 
00211       if(is_a($reviewRound, 'ReviewRound')) {
00212          // Retrieve review indexes.
00213          $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
00214          $reviewIndexes =& $reviewAssignmentDao->getReviewIndexesForRound($seriesEditorSubmission->getId(), $reviewRound->getId());
00215          assert(is_array($reviewIndexes));
00216 
00217          // Add a review index for review attachments not associated with
00218          // a review assignment (i.e. attachments uploaded by the editor).
00219          $lastIndex = end($reviewIndexes);
00220          $reviewIndexes[-1] = $lastIndex + 1;
00221 
00222          // Attach the selected reviewer attachments to the email.
00223          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00224          $selectedAttachments = $this->getData('selectedAttachments');
00225          if(is_array($selectedAttachments)) {
00226             foreach ($selectedAttachments as $attachmentId) {
00227                // Split the attachment into file id and file revision.
00228                $attachment = explode('-', $attachmentId);
00229                assert(count($attachment) == 2);
00230 
00231                // Retrieve the monograph file.
00232                $monographFile =& $submissionFileDao->getRevision($attachment[0], $attachment[1]);
00233                assert(is_a($monographFile, 'MonographFile'));
00234 
00235                // Check the association information.
00236                if($monographFile->getAssocType() == ASSOC_TYPE_REVIEW_ASSIGNMENT) {
00237                   // The review attachment has been uploaded by a reviewer.
00238                   $reviewAssignmentId = $monographFile->getAssocId();
00239                   assert(is_numeric($reviewAssignmentId));
00240                } else {
00241                   // The review attachment has been uploaded by the editor.
00242                   $reviewAssignmentId = -1;
00243                }
00244 
00245                // Identify the corresponding review index.
00246                assert(isset($reviewIndexes[$reviewAssignmentId]));
00247                $reviewIndex = $reviewIndexes[$reviewAssignmentId];
00248                assert(!is_null($reviewIndex));
00249 
00250                // Add the attachment to the email.
00251                $email->addAttachment(
00252                   $monographFile->getFilePath(),
00253                   String::enumerateAlphabetically($reviewIndex).'-'.$monographFile->getOriginalFileName()
00254                );
00255 
00256                // Update monograph file to set viewable as true, so author
00257                // can view the file on their submission summary page.
00258                $monographFile->setViewable(true);
00259                $submissionFileDao->updateObject($monographFile);
00260             }
00261          }
00262       }
00263 
00264       // Send the email.
00265       if (!$this->getData('skipEmail')) {
00266          $router =& $request->getRouter();
00267          $dispatcher =& $router->getDispatcher();
00268          $paramArray = array(
00269             'authorUsername' => $submitter->getUsername(),
00270             'submissionUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'authorDashboard', 'submission', $seriesEditorSubmission->getId()),
00271          );
00272          $email->assignParams($paramArray);
00273          $email->send($request);
00274       }
00275    }
00276 }
00277 
00278 ?>

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