00001 <?php
00002
00019
00020
00021
00022 import('submission.common.Action');
00023
00024 class LayoutEditorAction extends Action {
00025
00026
00027
00028
00029
00036 function orderGalley($article, $galleyId, $direction) {
00037 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00038 $galley = &$galleyDao->getGalley($galleyId, $article->getArticleId());
00039
00040 if (isset($galley)) {
00041 $galley->setSequence($galley->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
00042 $galleyDao->updateGalley($galley);
00043 $galleyDao->resequenceGalleys($article->getArticleId());
00044 }
00045 }
00046
00052 function deleteGalley($article, $galleyId) {
00053 import('file.ArticleFileManager');
00054
00055 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00056 $galley = &$galleyDao->getGalley($galleyId, $article->getArticleId());
00057
00058 if (isset($galley) && !HookRegistry::call('LayoutEditorAction::deleteGalley', array(&$article, &$galley))) {
00059 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00060
00061 if ($galley->getFileId()) {
00062 $articleFileManager->deleteFile($galley->getFileId());
00063 import('search.ArticleSearchIndex');
00064 ArticleSearchIndex::deleteTextIndex($article->getArticleId(), ARTICLE_SEARCH_GALLEY_FILE, $galley->getFileId());
00065 }
00066 if ($galley->isHTMLGalley()) {
00067 if ($galley->getStyleFileId()) {
00068 $articleFileManager->deleteFile($galley->getStyleFileId());
00069 }
00070 foreach ($galley->getImageFiles() as $image) {
00071 $articleFileManager->deleteFile($image->getFileId());
00072 }
00073 }
00074 $galleyDao->deleteGalley($galley);
00075 }
00076 }
00077
00084 function deleteArticleImage($submission, $fileId, $revision) {
00085 import('file.ArticleFileManager');
00086 $articleGalleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
00087 if (HookRegistry::call('LayoutEditorAction::deleteArticleImage', array(&$submission, &$fileId, &$revision))) return;
00088 foreach ($submission->getGalleys() as $galley) {
00089 $images =& $articleGalleyDao->getGalleyImages($galley->getGalleyId());
00090 foreach ($images as $imageFile) {
00091 if ($imageFile->getArticleId() == $submission->getArticleId() && $fileId == $imageFile->getFileId() && $imageFile->getRevision() == $revision) {
00092 $articleFileManager = &new ArticleFileManager($submission->getArticleId());
00093 $articleFileManager->deleteFile($imageFile->getFileId(), $imageFile->getRevision());
00094 }
00095 }
00096 unset($images);
00097 }
00098 }
00099
00106 function orderSuppFile($article, $suppFileId, $direction) {
00107 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00108 $suppFile = &$suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
00109
00110 if (isset($suppFile)) {
00111 $suppFile->setSequence($suppFile->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
00112 $suppFileDao->updateSuppFile($suppFile);
00113 $suppFileDao->resequenceSuppFiles($article->getArticleId());
00114 }
00115 }
00116
00122 function deleteSuppFile($article, $suppFileId) {
00123 import('file.ArticleFileManager');
00124
00125 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00126
00127 $suppFile = &$suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
00128 if (isset($suppFile) && !HookRegistry::call('LayoutEditorAction::deleteSuppFile', array(&$article, &$suppFile))) {
00129 if ($suppFile->getFileId()) {
00130 $articleFileManager = &new ArticleFileManager($article->getArticleId());
00131 $articleFileManager->deleteFile($suppFile->getFileId());
00132 import('search.ArticleSearchIndex');
00133 ArticleSearchIndex::deleteTextIndex($article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId());
00134 }
00135 $suppFileDao->deleteSuppFile($suppFile);
00136 }
00137 }
00138
00144 function completeLayoutEditing($submission, $send = false) {
00145 $submissionDao = &DAORegistry::getDAO('LayoutEditorSubmissionDAO');
00146 $userDao = &DAORegistry::getDAO('UserDAO');
00147 $journal = &Request::getJournal();
00148
00149 $layoutAssignment = &$submission->getLayoutAssignment();
00150 if ($layoutAssignment->getDateCompleted() != null) {
00151 return true;
00152 }
00153
00154 import('mail.ArticleMailTemplate');
00155 $email = &new ArticleMailTemplate($submission, 'LAYOUT_COMPLETE');
00156
00157 $editAssignments = &$submission->getEditAssignments();
00158 if (empty($editAssignments)) return;
00159
00160 if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
00161 HookRegistry::call('LayoutEditorAction::completeLayoutEditing', array(&$submission, &$layoutAssignment, &$editAssignments, &$email));
00162 if ($email->isEnabled()) {
00163 $email->setAssoc(ARTICLE_EMAIL_LAYOUT_NOTIFY_COMPLETE, ARTICLE_EMAIL_TYPE_LAYOUT, $layoutAssignment->getLayoutId());
00164 $email->send();
00165 }
00166
00167 $layoutAssignment->setDateCompleted(Core::getCurrentDate());
00168 $submissionDao->updateSubmission($submission);
00169
00170
00171 $user = &Request::getUser();
00172 import('article.log.ArticleLog');
00173 import('article.log.ArticleEventLogEntry');
00174 ArticleLog::logEvent($submission->getArticleId(), ARTICLE_LOG_LAYOUT_COMPLETE, ARTICLE_LOG_TYPE_LAYOUT, $user->getUserId(), 'log.layout.layoutEditComplete', Array('editorName' => $user->getFullName(), 'articleId' => $submission->getArticleId()));
00175
00176 return true;
00177 } else {
00178 $user = &Request::getUser();
00179 if (!Request::getUserVar('continued')) {
00180 $assignedSectionEditors = $email->toAssignedEditingSectionEditors($submission->getArticleId());
00181 $assignedEditors = $email->ccAssignedEditors($submission->getArticleId());
00182 if (empty($assignedSectionEditors) && empty($assignedEditors)) {
00183 $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
00184 $editorialContactName = $journal->getSetting('contactName');
00185 } else {
00186 $editorialContact = array_shift($assignedSectionEditors);
00187 if (!$editorialContact) $editorialContact = array_shift($assignedEditors);
00188 $editorialContactName = $editorialContact->getEditorFullName();
00189 }
00190 $paramArray = array(
00191 'editorialContactName' => $editorialContactName,
00192 'layoutEditorName' => $user->getFullName()
00193 );
00194 $email->assignParams($paramArray);
00195 }
00196 $email->displayEditForm(Request::url(null, 'layoutEditor', 'completeAssignment', 'send'), array('articleId' => $submission->getArticleId()));
00197
00198 return false;
00199 }
00200 }
00201
00206 function uploadLayoutVersion($submission) {
00207 import('file.ArticleFileManager');
00208 $articleFileManager = &new ArticleFileManager($submission->getArticleId());
00209 $layoutEditorSubmissionDao = &DAORegistry::getDAO('LayoutEditorSubmissionDAO');
00210
00211 $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00212 $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($submission->getArticleId());
00213
00214 $fileName = 'layoutFile';
00215 if ($articleFileManager->uploadedFileExists($fileName) && !HookRegistry::call('LayoutEditorAction::uploadLayoutVersion', array(&$submission, &$layoutAssignment))) {
00216 $layoutFileId = $articleFileManager->uploadLayoutFile($fileName, $layoutAssignment->getLayoutFileId());
00217 $layoutAssignment->setLayoutFileId($layoutFileId);
00218 $layoutDao->updateLayoutAssignment($layoutAssignment);
00219 }
00220 }
00221
00222
00223
00224
00225
00230 function viewLayoutComments($article) {
00231 if (!HookRegistry::call('LayoutEditorAction::viewLayoutComments', array(&$article))) {
00232 import("submission.form.comment.LayoutCommentForm");
00233
00234 $commentForm = &new LayoutCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
00235 $commentForm->initData();
00236 $commentForm->display();
00237 }
00238 }
00239
00244 function postLayoutComment($article, $emailComment) {
00245 if (!HookRegistry::call('LayoutEditorAction::postLayoutComment', array(&$article, &$emailComment))) {
00246 import("submission.form.comment.LayoutCommentForm");
00247
00248 $commentForm = &new LayoutCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
00249 $commentForm->readInputData();
00250
00251 if ($commentForm->validate()) {
00252 $commentForm->execute();
00253
00254 if ($emailComment) {
00255 $commentForm->email();
00256 }
00257
00258 } else {
00259 $commentForm->display();
00260 return false;
00261 }
00262 return true;
00263 }
00264 }
00265
00270 function viewProofreadComments($article) {
00271 if (!HookRegistry::call('LayoutEditorAction::viewProofreadComments', array(&$article))) {
00272 import("submission.form.comment.ProofreadCommentForm");
00273
00274 $commentForm = &new ProofreadCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
00275 $commentForm->initData();
00276 $commentForm->display();
00277 }
00278 }
00279
00284 function postProofreadComment($article, $emailComment) {
00285 if (!HookRegistry::call('LayoutEditorAction::postProofreadComment', array(&$article, &$emailComment))) {
00286 import('submission.form.comment.ProofreadCommentForm');
00287
00288 $commentForm = &new ProofreadCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
00289 $commentForm->readInputData();
00290
00291 if ($commentForm->validate()) {
00292 $commentForm->execute();
00293
00294 if ($emailComment) {
00295 $commentForm->email();
00296 }
00297
00298 } else {
00299 $commentForm->display();
00300 return false;
00301 }
00302 return true;
00303 }
00304 }
00305
00306
00307
00308
00309
00318 function downloadFile($article, $fileId, $revision = null) {
00319 $canDownload = false;
00320
00321 $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00322 $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00323 $suppDao = &DAORegistry::getDAO('SuppFileDAO');
00324
00325 $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($article->getArticleId());
00326
00327 if ($layoutAssignment->getLayoutFileId() == $fileId) {
00328 $canDownload = true;
00329
00330 } else if($galleyDao->galleyExistsByFileId($article->getArticleId(), $fileId)) {
00331 $canDownload = true;
00332
00333 } else if($suppDao->suppFileExistsByFileId($article->getArticleId(), $fileId)) {
00334 $canDownload = true;
00335 }
00336
00337 $result = false;
00338 if (!HookRegistry::call('LayoutEditorAction::downloadFile', array(&$article, &$fileId, &$revision, &$canDownload, &$result))) {
00339 if ($canDownload) {
00340 return parent::downloadFile($article->getArticleId(), $fileId, $revision);
00341 } else {
00342 return false;
00343 }
00344 }
00345 return $result;
00346 }
00347 }
00348
00349 ?>