PageRenderTime 43ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.2.3/classes/submission/layoutEditor/LayoutEditorAction.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 349 lines | 208 code | 55 blank | 86 comment | 53 complexity | a03dcc565073340ea7ba509604ae416f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @defgroup submission_layoutEditor_LayoutEditorAction
  4. */
  5. /**
  6. * @file classes/submission/layoutEditor/LayoutEditorAction.inc.php
  7. *
  8. * Copyright (c) 2003-2009 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class LayoutEditorAction
  12. * @ingroup submission_layoutEditor_LayoutEditorAction
  13. *
  14. * @brief LayoutEditorAction class.
  15. */
  16. // $Id: LayoutEditorAction.inc.php,v 1.38.2.1 2009/04/08 19:42:50 asmecher Exp $
  17. import('submission.common.Action');
  18. class LayoutEditorAction extends Action {
  19. //
  20. // Actions
  21. //
  22. /**
  23. * Change the sequence order of a galley.
  24. * @param $article object
  25. * @param $galleyId int
  26. * @param $direction char u = up, d = down
  27. */
  28. function orderGalley($article, $galleyId, $direction) {
  29. $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
  30. $galley = &$galleyDao->getGalley($galleyId, $article->getArticleId());
  31. if (isset($galley)) {
  32. $galley->setSequence($galley->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
  33. $galleyDao->updateGalley($galley);
  34. $galleyDao->resequenceGalleys($article->getArticleId());
  35. }
  36. }
  37. /**
  38. * Delete a galley.
  39. * @param $article object
  40. * @param $galleyId int
  41. */
  42. function deleteGalley($article, $galleyId) {
  43. import('file.ArticleFileManager');
  44. $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
  45. $galley = &$galleyDao->getGalley($galleyId, $article->getArticleId());
  46. if (isset($galley) && !HookRegistry::call('LayoutEditorAction::deleteGalley', array(&$article, &$galley))) {
  47. $articleFileManager = &new ArticleFileManager($article->getArticleId());
  48. if ($galley->getFileId()) {
  49. $articleFileManager->deleteFile($galley->getFileId());
  50. import('search.ArticleSearchIndex');
  51. ArticleSearchIndex::deleteTextIndex($article->getArticleId(), ARTICLE_SEARCH_GALLEY_FILE, $galley->getFileId());
  52. }
  53. if ($galley->isHTMLGalley()) {
  54. if ($galley->getStyleFileId()) {
  55. $articleFileManager->deleteFile($galley->getStyleFileId());
  56. }
  57. foreach ($galley->getImageFiles() as $image) {
  58. $articleFileManager->deleteFile($image->getFileId());
  59. }
  60. }
  61. $galleyDao->deleteGalley($galley);
  62. }
  63. }
  64. /**
  65. * Delete an image from an article galley.
  66. * @param $submission object
  67. * @param $fileId int
  68. * @param $revision int (optional)
  69. */
  70. function deleteArticleImage($submission, $fileId, $revision) {
  71. import('file.ArticleFileManager');
  72. $articleGalleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
  73. if (HookRegistry::call('LayoutEditorAction::deleteArticleImage', array(&$submission, &$fileId, &$revision))) return;
  74. foreach ($submission->getGalleys() as $galley) {
  75. $images =& $articleGalleyDao->getGalleyImages($galley->getGalleyId());
  76. foreach ($images as $imageFile) {
  77. if ($imageFile->getArticleId() == $submission->getArticleId() && $fileId == $imageFile->getFileId() && $imageFile->getRevision() == $revision) {
  78. $articleFileManager = &new ArticleFileManager($submission->getArticleId());
  79. $articleFileManager->deleteFile($imageFile->getFileId(), $imageFile->getRevision());
  80. }
  81. }
  82. unset($images);
  83. }
  84. }
  85. /**
  86. * Change the sequence order of a supplementary file.
  87. * @param $article object
  88. * @param $suppFileId int
  89. * @param $direction char u = up, d = down
  90. */
  91. function orderSuppFile($article, $suppFileId, $direction) {
  92. $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
  93. $suppFile = &$suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
  94. if (isset($suppFile)) {
  95. $suppFile->setSequence($suppFile->getSequence() + ($direction == 'u' ? -1.5 : 1.5));
  96. $suppFileDao->updateSuppFile($suppFile);
  97. $suppFileDao->resequenceSuppFiles($article->getArticleId());
  98. }
  99. }
  100. /**
  101. * Delete a supplementary file.
  102. * @param $article object
  103. * @param $suppFileId int
  104. */
  105. function deleteSuppFile($article, $suppFileId) {
  106. import('file.ArticleFileManager');
  107. $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
  108. $suppFile = &$suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
  109. if (isset($suppFile) && !HookRegistry::call('LayoutEditorAction::deleteSuppFile', array(&$article, &$suppFile))) {
  110. if ($suppFile->getFileId()) {
  111. $articleFileManager = &new ArticleFileManager($article->getArticleId());
  112. $articleFileManager->deleteFile($suppFile->getFileId());
  113. import('search.ArticleSearchIndex');
  114. ArticleSearchIndex::deleteTextIndex($article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId());
  115. }
  116. $suppFileDao->deleteSuppFile($suppFile);
  117. }
  118. }
  119. /**
  120. * Marks layout assignment as completed.
  121. * @param $submission object
  122. * @param $send boolean
  123. */
  124. function completeLayoutEditing($submission, $send = false) {
  125. $submissionDao = &DAORegistry::getDAO('LayoutEditorSubmissionDAO');
  126. $userDao = &DAORegistry::getDAO('UserDAO');
  127. $journal = &Request::getJournal();
  128. $layoutAssignment = &$submission->getLayoutAssignment();
  129. if ($layoutAssignment->getDateCompleted() != null) {
  130. return true;
  131. }
  132. import('mail.ArticleMailTemplate');
  133. $email = &new ArticleMailTemplate($submission, 'LAYOUT_COMPLETE');
  134. $editAssignments = &$submission->getEditAssignments();
  135. if (empty($editAssignments)) return;
  136. if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
  137. HookRegistry::call('LayoutEditorAction::completeLayoutEditing', array(&$submission, &$layoutAssignment, &$editAssignments, &$email));
  138. if ($email->isEnabled()) {
  139. $email->setAssoc(ARTICLE_EMAIL_LAYOUT_NOTIFY_COMPLETE, ARTICLE_EMAIL_TYPE_LAYOUT, $layoutAssignment->getLayoutId());
  140. $email->send();
  141. }
  142. $layoutAssignment->setDateCompleted(Core::getCurrentDate());
  143. $submissionDao->updateSubmission($submission);
  144. // Add log entry
  145. $user = &Request::getUser();
  146. import('article.log.ArticleLog');
  147. import('article.log.ArticleEventLogEntry');
  148. ArticleLog::logEvent($submission->getArticleId(), ARTICLE_LOG_LAYOUT_COMPLETE, ARTICLE_LOG_TYPE_LAYOUT, $user->getUserId(), 'log.layout.layoutEditComplete', Array('editorName' => $user->getFullName(), 'articleId' => $submission->getArticleId()));
  149. return true;
  150. } else {
  151. $user = &Request::getUser();
  152. if (!Request::getUserVar('continued')) {
  153. $assignedSectionEditors = $email->toAssignedEditingSectionEditors($submission->getArticleId());
  154. $assignedEditors = $email->ccAssignedEditors($submission->getArticleId());
  155. if (empty($assignedSectionEditors) && empty($assignedEditors)) {
  156. $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
  157. $editorialContactName = $journal->getSetting('contactName');
  158. } else {
  159. $editorialContact = array_shift($assignedSectionEditors);
  160. if (!$editorialContact) $editorialContact = array_shift($assignedEditors);
  161. $editorialContactName = $editorialContact->getEditorFullName();
  162. }
  163. $paramArray = array(
  164. 'editorialContactName' => $editorialContactName,
  165. 'layoutEditorName' => $user->getFullName()
  166. );
  167. $email->assignParams($paramArray);
  168. }
  169. $email->displayEditForm(Request::url(null, 'layoutEditor', 'completeAssignment', 'send'), array('articleId' => $submission->getArticleId()));
  170. return false;
  171. }
  172. }
  173. /**
  174. * Upload the layout version of an article.
  175. * @param $submission object
  176. */
  177. function uploadLayoutVersion($submission) {
  178. import('file.ArticleFileManager');
  179. $articleFileManager = &new ArticleFileManager($submission->getArticleId());
  180. $layoutEditorSubmissionDao = &DAORegistry::getDAO('LayoutEditorSubmissionDAO');
  181. $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
  182. $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($submission->getArticleId());
  183. $fileName = 'layoutFile';
  184. if ($articleFileManager->uploadedFileExists($fileName) && !HookRegistry::call('LayoutEditorAction::uploadLayoutVersion', array(&$submission, &$layoutAssignment))) {
  185. $layoutFileId = $articleFileManager->uploadLayoutFile($fileName, $layoutAssignment->getLayoutFileId());
  186. $layoutAssignment->setLayoutFileId($layoutFileId);
  187. $layoutDao->updateLayoutAssignment($layoutAssignment);
  188. }
  189. }
  190. //
  191. // Comments
  192. //
  193. /**
  194. * View layout comments.
  195. * @param $article object
  196. */
  197. function viewLayoutComments($article) {
  198. if (!HookRegistry::call('LayoutEditorAction::viewLayoutComments', array(&$article))) {
  199. import("submission.form.comment.LayoutCommentForm");
  200. $commentForm = &new LayoutCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
  201. $commentForm->initData();
  202. $commentForm->display();
  203. }
  204. }
  205. /**
  206. * Post layout comment.
  207. * @param $article object
  208. */
  209. function postLayoutComment($article, $emailComment) {
  210. if (!HookRegistry::call('LayoutEditorAction::postLayoutComment', array(&$article, &$emailComment))) {
  211. import("submission.form.comment.LayoutCommentForm");
  212. $commentForm = &new LayoutCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
  213. $commentForm->readInputData();
  214. if ($commentForm->validate()) {
  215. $commentForm->execute();
  216. if ($emailComment) {
  217. $commentForm->email();
  218. }
  219. } else {
  220. $commentForm->display();
  221. return false;
  222. }
  223. return true;
  224. }
  225. }
  226. /**
  227. * View proofread comments.
  228. * @param $article object
  229. */
  230. function viewProofreadComments($article) {
  231. if (!HookRegistry::call('LayoutEditorAction::viewProofreadComments', array(&$article))) {
  232. import("submission.form.comment.ProofreadCommentForm");
  233. $commentForm = &new ProofreadCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
  234. $commentForm->initData();
  235. $commentForm->display();
  236. }
  237. }
  238. /**
  239. * Post proofread comment.
  240. * @param $article object
  241. */
  242. function postProofreadComment($article, $emailComment) {
  243. if (!HookRegistry::call('LayoutEditorAction::postProofreadComment', array(&$article, &$emailComment))) {
  244. import('submission.form.comment.ProofreadCommentForm');
  245. $commentForm = &new ProofreadCommentForm($article, ROLE_ID_LAYOUT_EDITOR);
  246. $commentForm->readInputData();
  247. if ($commentForm->validate()) {
  248. $commentForm->execute();
  249. if ($emailComment) {
  250. $commentForm->email();
  251. }
  252. } else {
  253. $commentForm->display();
  254. return false;
  255. }
  256. return true;
  257. }
  258. }
  259. //
  260. // Misc
  261. //
  262. /**
  263. * Download a file a layout editor has access to.
  264. * This includes: The layout editor submission file, supplementary files, and galley files.
  265. * @param $article object
  266. * @parma $fileId int
  267. * @param $revision int optional
  268. * @return boolean
  269. */
  270. function downloadFile($article, $fileId, $revision = null) {
  271. $canDownload = false;
  272. $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
  273. $galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
  274. $suppDao = &DAORegistry::getDAO('SuppFileDAO');
  275. $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($article->getArticleId());
  276. if ($layoutAssignment->getLayoutFileId() == $fileId) {
  277. $canDownload = true;
  278. } else if($galleyDao->galleyExistsByFileId($article->getArticleId(), $fileId)) {
  279. $canDownload = true;
  280. } else if($suppDao->suppFileExistsByFileId($article->getArticleId(), $fileId)) {
  281. $canDownload = true;
  282. }
  283. $result = false;
  284. if (!HookRegistry::call('LayoutEditorAction::downloadFile', array(&$article, &$fileId, &$revision, &$canDownload, &$result))) {
  285. if ($canDownload) {
  286. return parent::downloadFile($article->getArticleId(), $fileId, $revision);
  287. } else {
  288. return false;
  289. }
  290. }
  291. return $result;
  292. }
  293. }
  294. ?>