00001 <?php
00002
00016
00017
00018
00019 import('submission.common.Action');
00020
00021 class CopyeditorAction extends Action {
00022
00026 function CopyeditorAction() {
00027
00028 }
00029
00038 function completeCopyedit($copyeditorSubmission, $send = false) {
00039 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00040 $userDao = &DAORegistry::getDAO('UserDAO');
00041 $journal = &Request::getJournal();
00042
00043 if ($copyeditorSubmission->getDateCompleted() != null) {
00044 return true;
00045 }
00046
00047 $user = &Request::getUser();
00048 import('mail.ArticleMailTemplate');
00049 $email = &new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_COMPLETE');
00050
00051 $editAssignments = $copyeditorSubmission->getEditAssignments();
00052
00053 $author = $copyeditorSubmission->getUser();
00054
00055 if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
00056 HookRegistry::call('CopyeditorAction::completeCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$author, &$email));
00057 if ($email->isEnabled()) {
00058 $email->setAssoc(ARTICLE_EMAIL_COPYEDIT_NOTIFY_COMPLETE, ARTICLE_EMAIL_TYPE_COPYEDIT, $copyeditorSubmission->getArticleId());
00059 $email->send();
00060 }
00061
00062 $copyeditorSubmission->setDateCompleted(Core::getCurrentDate());
00063 $copyeditorSubmission->setDateAuthorNotified(Core::getCurrentDate());
00064 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00065
00066
00067 import('article.log.ArticleLog');
00068 import('article.log.ArticleEventLogEntry');
00069 ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_INITIAL, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.initialEditComplete', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
00070
00071 return true;
00072
00073 } else {
00074 if (!Request::getUserVar('continued')) {
00075 $email->addRecipient($author->getEmail(), $author->getFullName());
00076 $email->ccAssignedEditingSectionEditors($copyeditorSubmission->getArticleId());
00077 $email->ccAssignedEditors($copyeditorSubmission->getArticleId());
00078
00079 $paramArray = array(
00080 'editorialContactName' => $author->getFullName(),
00081 'copyeditorName' => $user->getFullName(),
00082 'authorUsername' => $author->getUsername(),
00083 'submissionEditingUrl' => Request::url(null, 'author', 'submissionEditing', array($copyeditorSubmission->getArticleId()))
00084 );
00085 $email->assignParams($paramArray);
00086 }
00087 $email->displayEditForm(Request::url(null, 'copyeditor', 'completeCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getArticleId()));
00088
00089 return false;
00090 }
00091 }
00092
00097 function completeFinalCopyedit($copyeditorSubmission, $send = false) {
00098 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00099 $userDao = &DAORegistry::getDAO('UserDAO');
00100 $journal = &Request::getJournal();
00101
00102 if ($copyeditorSubmission->getDateFinalCompleted() != null) {
00103 return true;
00104 }
00105
00106 $user = &Request::getUser();
00107 import('mail.ArticleMailTemplate');
00108 $email = &new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_FINAL_COMPLETE');
00109
00110 $editAssignments = $copyeditorSubmission->getEditAssignments();
00111
00112 if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
00113 HookRegistry::call('CopyeditorAction::completeFinalCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$email));
00114 if ($email->isEnabled()) {
00115 $email->setAssoc(ARTICLE_EMAIL_COPYEDIT_NOTIFY_FINAL_COMPLETE, ARTICLE_EMAIL_TYPE_COPYEDIT, $copyeditorSubmission->getArticleId());
00116 $email->send();
00117 }
00118
00119 $copyeditorSubmission->setDateFinalCompleted(Core::getCurrentDate());
00120 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00121
00122 if ($copyEdFile =& $copyeditorSubmission->getFinalCopyeditFile()) {
00123
00124 $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00125 $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($copyeditorSubmission->getArticleId());
00126
00127 if (isset($layoutAssignment) && !$layoutAssignment->getLayoutFileId()) {
00128 import('file.ArticleFileManager');
00129 $articleFileManager = &new ArticleFileManager($copyeditorSubmission->getArticleId());
00130 if ($layoutFileId = $articleFileManager->copyToLayoutFile($copyEdFile->getFileId(), $copyEdFile->getRevision())) {
00131 $layoutAssignment->setLayoutFileId($layoutFileId);
00132 $layoutDao->updateLayoutAssignment($layoutAssignment);
00133 }
00134 }
00135 }
00136
00137
00138 import('article.log.ArticleLog');
00139 import('article.log.ArticleEventLogEntry');
00140 ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_FINAL, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.finalEditComplete', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
00141
00142 return true;
00143
00144 } else {
00145 if (!Request::getUserVar('continued')) {
00146 $assignedSectionEditors = $email->toAssignedEditingSectionEditors($copyeditorSubmission->getArticleId());
00147 $assignedEditors = $email->ccAssignedEditors($copyeditorSubmission->getArticleId());
00148 if (empty($assignedSectionEditors) && empty($assignedEditors)) {
00149 $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
00150 $paramArray = array(
00151 'editorialContactName' => $journal->getSetting('contactName'),
00152 'copyeditorName' => $user->getFullName()
00153 );
00154 } else {
00155 $editorialContact = array_shift($assignedSectionEditors);
00156 if (!$editorialContact) $editorialContact = array_shift($assignedEditors);
00157
00158 $paramArray = array(
00159 'editorialContactName' => $editorialContact->getEditorFullName(),
00160 'copyeditorName' => $user->getFullName()
00161 );
00162 }
00163 $email->assignParams($paramArray);
00164 }
00165 $email->displayEditForm(Request::url(null, 'copyeditor', 'completeFinalCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getArticleId()));
00166
00167 return false;
00168 }
00169 }
00170
00174 function copyeditUnderway(&$copyeditorSubmission) {
00175 if (!HookRegistry::call('CopyeditorAction::copyeditUnderway', array(&$copyeditorSubmission))) {
00176 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00177
00178 if ($copyeditorSubmission->getDateNotified() != null && $copyeditorSubmission->getDateUnderway() == null) {
00179 $copyeditorSubmission->setDateUnderway(Core::getCurrentDate());
00180 $update = true;
00181
00182 } elseif ($copyeditorSubmission->getDateFinalNotified() != null && $copyeditorSubmission->getDateFinalUnderway() == null) {
00183 $copyeditorSubmission->setDateFinalUnderway(Core::getCurrentDate());
00184 $update = true;
00185 }
00186
00187 if (isset($update)) {
00188 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00189
00190
00191 $user = &Request::getUser();
00192 import('article.log.ArticleLog');
00193 import('article.log.ArticleEventLogEntry');
00194 ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_INITIATE, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.initiate', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
00195 }
00196 }
00197 }
00198
00203 function uploadCopyeditVersion($copyeditorSubmission, $copyeditStage) {
00204 import("file.ArticleFileManager");
00205 $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00206 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00207
00208
00209
00210 if ($copyeditStage == 'initial' && ($copyeditorSubmission->getDateNotified() == null || $copyeditorSubmission->getDateCompleted() != null)) return;
00211 else if ($copyeditStage == 'final' && ($copyeditorSubmission->getDateFinalNotified() == null || $copyeditorSubmission->getDateFinalCompleted() != null)) return;
00212 else if ($copyeditStage != 'initial' && $copyeditStage != 'final') return;
00213
00214 $articleFileManager = &new ArticleFileManager($copyeditorSubmission->getArticleId());
00215 $user = &Request::getUser();
00216
00217 $fileName = 'upload';
00218 if ($articleFileManager->uploadedFileExists($fileName)) {
00219 HookRegistry::call('CopyeditorAction::uploadCopyeditVersion', array(&$copyeditorSubmission));
00220 if ($copyeditorSubmission->getCopyeditFileId() != null) {
00221 $fileId = $articleFileManager->uploadCopyeditFile($fileName, $copyeditorSubmission->getCopyeditFileId());
00222 } else {
00223 $fileId = $articleFileManager->uploadCopyeditFile($fileName);
00224 }
00225 }
00226
00227 if (isset($fileId) && $fileId != 0) {
00228 $copyeditorSubmission->setCopyeditFileId($fileId);
00229
00230 if ($copyeditStage == 'initial') {
00231 $copyeditorSubmission->setInitialRevision($articleFileDao->getRevisionNumber($fileId));
00232 } elseif ($copyeditStage == 'final') {
00233 $copyeditorSubmission->setFinalRevision($articleFileDao->getRevisionNumber($fileId));
00234 }
00235
00236 $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00237
00238
00239 import('article.log.ArticleLog');
00240 import('article.log.ArticleEventLogEntry');
00241
00242 $entry = &new ArticleEventLogEntry();
00243 $entry->setArticleId($copyeditorSubmission->getArticleId());
00244 $entry->setUserId($user->getUserId());
00245 $entry->setDateLogged(Core::getCurrentDate());
00246 $entry->setEventType(ARTICLE_LOG_COPYEDIT_COPYEDITOR_FILE);
00247 $entry->setLogMessage('log.copyedit.copyeditorFile');
00248 $entry->setAssocType(ARTICLE_LOG_TYPE_COPYEDIT);
00249 $entry->setAssocId($fileId);
00250
00251 ArticleLog::logEventEntry($copyeditorSubmission->getArticleId(), $entry);
00252 }
00253 }
00254
00255
00256
00257
00258
00263 function viewLayoutComments($article) {
00264 if (!HookRegistry::call('CopyeditorAction::viewLayoutComments', array(&$article))) {
00265 import("submission.form.comment.LayoutCommentForm");
00266
00267 $commentForm = &new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
00268 $commentForm->initData();
00269 $commentForm->display();
00270 }
00271 }
00272
00277 function postLayoutComment($article, $emailComment) {
00278 if (!HookRegistry::call('CopyeditorAction::postLayoutComment', array(&$article, &$emailComment))) {
00279 import("submission.form.comment.LayoutCommentForm");
00280
00281 $commentForm = &new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
00282 $commentForm->readInputData();
00283
00284 if ($commentForm->validate()) {
00285 $commentForm->execute();
00286
00287 if ($emailComment) {
00288 $commentForm->email();
00289 }
00290
00291 } else {
00292 $commentForm->display();
00293 return false;
00294 }
00295 return true;
00296 }
00297 }
00298
00303 function viewCopyeditComments($article) {
00304 if (!HookRegistry::call('CopyeditorAction::viewCopyeditComments', array(&$article))) {
00305 import("submission.form.comment.CopyeditCommentForm");
00306
00307 $commentForm = &new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
00308 $commentForm->initData();
00309 $commentForm->display();
00310 }
00311 }
00312
00317 function postCopyeditComment($article, $emailComment) {
00318 if (!HookRegistry::call('CopyeditorAction::postCopyeditComment', array(&$article, &$emailComment))) {
00319 import("submission.form.comment.CopyeditCommentForm");
00320
00321 $commentForm = &new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
00322 $commentForm->readInputData();
00323
00324 if ($commentForm->validate()) {
00325 $commentForm->execute();
00326
00327 if ($emailComment) {
00328 $commentForm->email();
00329 }
00330
00331 } else {
00332 $commentForm->display();
00333 return false;
00334 }
00335 return true;
00336 }
00337 }
00338
00339
00340
00341
00342
00349 function downloadCopyeditorFile($submission, $fileId, $revision = null) {
00350 $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00351
00352 $canDownload = false;
00353
00354
00355
00356
00357
00358
00359
00360 if ($submission->getCopyeditFileId() == $fileId) {
00361 $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00362 $currentRevision = &$articleFileDao->getRevisionNumber($fileId);
00363
00364 if ($revision == null) {
00365 $revision = $currentRevision;
00366 }
00367
00368 if ($revision == 1) {
00369 $canDownload = true;
00370 } else if ($submission->getInitialRevision() == $revision) {
00371 $canDownload = true;
00372 } else if ($submission->getEditorAuthorRevision() == $revision && $submission->getDateAuthorCompleted() != null) {
00373 $canDownload = true;
00374 } else if ($submission->getFinalRevision() == $revision) {
00375 $canDownload = true;
00376 }
00377 }
00378 else {
00379
00380 foreach ($submission->getGalleys() as $galleyFile) {
00381 if ($galleyFile->getFileId() == $fileId) {
00382 $canDownload = true;
00383 }
00384 }
00385
00386 foreach ($submission->getSuppFiles() as $suppFile) {
00387 if ($suppFile->getFileId() == $fileId) {
00388 $canDownload = true;
00389 }
00390 }
00391 }
00392
00393 $result = false;
00394 if (!HookRegistry::call('CopyeditorAction::downloadCopyeditorFile', array(&$submission, &$fileId, &$revision, &$result))) {
00395 if ($canDownload) {
00396 return Action::downloadFile($submission->getArticleId(), $fileId, $revision);
00397 } else {
00398 return false;
00399 }
00400 }
00401
00402 return $result;
00403 }
00404 }
00405
00406 ?>