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
00036
00041 function getSaveFormOperation() {
00042 return $this->_saveFormOperation;
00043 }
00044
00049 function setSaveFormOperation($saveFormOperation) {
00050 $this->_saveFormOperation = $saveFormOperation;
00051 }
00052
00053
00054
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
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
00124
00125 $reviewRound =& $this->getReviewRound();
00126
00127
00128 if (is_a($reviewRound, 'ReviewRound')) {
00129
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
00148
00149
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
00161
00167 function _updateReviewRoundStatus($seriesEditorSubmission, $status, $reviewRound = null) {
00168 $reviewRoundDao =& DAORegistry::getDAO('ReviewRoundDAO');
00169 if (!$reviewRound) {
00170 $reviewRound =& $reviewRoundDao->getLastReviewRoundByMonographId($seriesEditorSubmission->getId());
00171 }
00172
00173
00174
00175
00176 if (is_a($reviewRound, 'ReviewRound')) {
00177 $reviewRoundDao->updateStatus($reviewRound, null, $status);
00178 }
00179 }
00180
00189 function _sendReviewMailToAuthor(&$seriesEditorSubmission, $emailKey, $request) {
00190
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
00209 $reviewRound =& $this->getReviewRound();
00210
00211 if(is_a($reviewRound, 'ReviewRound')) {
00212
00213 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00214 $reviewIndexes =& $reviewAssignmentDao->getReviewIndexesForRound($seriesEditorSubmission->getId(), $reviewRound->getId());
00215 assert(is_array($reviewIndexes));
00216
00217
00218
00219 $lastIndex = end($reviewIndexes);
00220 $reviewIndexes[-1] = $lastIndex + 1;
00221
00222
00223 $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00224 $selectedAttachments = $this->getData('selectedAttachments');
00225 if(is_array($selectedAttachments)) {
00226 foreach ($selectedAttachments as $attachmentId) {
00227
00228 $attachment = explode('-', $attachmentId);
00229 assert(count($attachment) == 2);
00230
00231
00232 $monographFile =& $submissionFileDao->getRevision($attachment[0], $attachment[1]);
00233 assert(is_a($monographFile, 'MonographFile'));
00234
00235
00236 if($monographFile->getAssocType() == ASSOC_TYPE_REVIEW_ASSIGNMENT) {
00237
00238 $reviewAssignmentId = $monographFile->getAssocId();
00239 assert(is_numeric($reviewAssignmentId));
00240 } else {
00241
00242 $reviewAssignmentId = -1;
00243 }
00244
00245
00246 assert(isset($reviewIndexes[$reviewAssignmentId]));
00247 $reviewIndex = $reviewIndexes[$reviewAssignmentId];
00248 assert(!is_null($reviewIndex));
00249
00250
00251 $email->addAttachment(
00252 $monographFile->getFilePath(),
00253 String::enumerateAlphabetically($reviewIndex).'-'.$monographFile->getOriginalFileName()
00254 );
00255
00256
00257
00258 $monographFile->setViewable(true);
00259 $submissionFileDao->updateObject($monographFile);
00260 }
00261 }
00262 }
00263
00264
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 ?>