PageRenderTime 44ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.2/classes/submission/copyeditor/CopyeditorAction.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 404 lines | 257 code | 70 blank | 77 comment | 96 complexity | c9bd024e89308fa11abb0de7b73440b5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @file CopyeditorAction.inc.php
  4. *
  5. * Copyright (c) 2003-2007 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @package submission
  9. * @class CopyeditorAction
  10. *
  11. * CopyeditorAction class.
  12. *
  13. * $Id: CopyeditorAction.inc.php,v 1.51 2007/09/19 00:04:34 asmecher Exp $
  14. */
  15. import('submission.common.Action');
  16. class CopyeditorAction extends Action {
  17. /**
  18. * Constructor.
  19. */
  20. function CopyeditorAction() {
  21. }
  22. /**
  23. * Actions.
  24. */
  25. /**
  26. * Copyeditor completes initial copyedit.
  27. * @param $copyeditorSubmission object
  28. */
  29. function completeCopyedit($copyeditorSubmission, $send = false) {
  30. $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
  31. $userDao = &DAORegistry::getDAO('UserDAO');
  32. $journal = &Request::getJournal();
  33. if ($copyeditorSubmission->getDateCompleted() != null) {
  34. return true;
  35. }
  36. $user = &Request::getUser();
  37. import('mail.ArticleMailTemplate');
  38. $email = &new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_COMPLETE');
  39. $editAssignments = $copyeditorSubmission->getEditAssignments();
  40. $author = $copyeditorSubmission->getUser();
  41. if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
  42. HookRegistry::call('CopyeditorAction::completeCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$author, &$email));
  43. if ($email->isEnabled()) {
  44. $email->setAssoc(ARTICLE_EMAIL_COPYEDIT_NOTIFY_COMPLETE, ARTICLE_EMAIL_TYPE_COPYEDIT, $copyeditorSubmission->getArticleId());
  45. $email->send();
  46. }
  47. $copyeditorSubmission->setDateCompleted(Core::getCurrentDate());
  48. $copyeditorSubmission->setDateAuthorNotified(Core::getCurrentDate());
  49. $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
  50. // Add log entry
  51. import('article.log.ArticleLog');
  52. import('article.log.ArticleEventLogEntry');
  53. ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_INITIAL, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.initialEditComplete', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
  54. return true;
  55. } else {
  56. if (!Request::getUserVar('continued')) {
  57. $email->addRecipient($author->getEmail(), $author->getFullName());
  58. $email->ccAssignedEditingSectionEditors($copyeditorSubmission->getArticleId());
  59. $email->ccAssignedEditors($copyeditorSubmission->getArticleId());
  60. $paramArray = array(
  61. 'editorialContactName' => $author->getFullName(),
  62. 'copyeditorName' => $user->getFullName(),
  63. 'authorUsername' => $author->getUsername(),
  64. 'submissionEditingUrl' => Request::url(null, 'author', 'submissionEditing', array($copyeditorSubmission->getArticleId()))
  65. );
  66. $email->assignParams($paramArray);
  67. }
  68. $email->displayEditForm(Request::url(null, 'copyeditor', 'completeCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getArticleId()));
  69. return false;
  70. }
  71. }
  72. /**
  73. * Copyeditor completes final copyedit.
  74. * @param $copyeditorSubmission object
  75. */
  76. function completeFinalCopyedit($copyeditorSubmission, $send = false) {
  77. $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
  78. $userDao = &DAORegistry::getDAO('UserDAO');
  79. $journal = &Request::getJournal();
  80. if ($copyeditorSubmission->getDateFinalCompleted() != null) {
  81. return true;
  82. }
  83. $user = &Request::getUser();
  84. import('mail.ArticleMailTemplate');
  85. $email = &new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_FINAL_COMPLETE');
  86. $editAssignments = $copyeditorSubmission->getEditAssignments();
  87. if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
  88. HookRegistry::call('CopyeditorAction::completeFinalCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$email));
  89. if ($email->isEnabled()) {
  90. $email->setAssoc(ARTICLE_EMAIL_COPYEDIT_NOTIFY_FINAL_COMPLETE, ARTICLE_EMAIL_TYPE_COPYEDIT, $copyeditorSubmission->getArticleId());
  91. $email->send();
  92. }
  93. $copyeditorSubmission->setDateFinalCompleted(Core::getCurrentDate());
  94. $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
  95. if ($copyEdFile =& $copyeditorSubmission->getFinalCopyeditFile()) {
  96. // Set initial layout version to final copyedit version
  97. $layoutDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
  98. $layoutAssignment = &$layoutDao->getLayoutAssignmentByArticleId($copyeditorSubmission->getArticleId());
  99. if (isset($layoutAssignment) && !$layoutAssignment->getLayoutFileId()) {
  100. import('file.ArticleFileManager');
  101. $articleFileManager = &new ArticleFileManager($copyeditorSubmission->getArticleId());
  102. if ($layoutFileId = $articleFileManager->copyToLayoutFile($copyEdFile->getFileId(), $copyEdFile->getRevision())) {
  103. $layoutAssignment->setLayoutFileId($layoutFileId);
  104. $layoutDao->updateLayoutAssignment($layoutAssignment);
  105. }
  106. }
  107. }
  108. // Add log entry
  109. import('article.log.ArticleLog');
  110. import('article.log.ArticleEventLogEntry');
  111. ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_FINAL, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.finalEditComplete', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
  112. return true;
  113. } else {
  114. if (!Request::getUserVar('continued')) {
  115. $assignedSectionEditors = $email->toAssignedEditingSectionEditors($copyeditorSubmission->getArticleId());
  116. $assignedEditors = $email->ccAssignedEditors($copyeditorSubmission->getArticleId());
  117. if (empty($assignedSectionEditors) && empty($assignedEditors)) {
  118. $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
  119. $paramArray = array(
  120. 'editorialContactName' => $journal->getSetting('contactName'),
  121. 'copyeditorName' => $user->getFullName()
  122. );
  123. } else {
  124. $editorialContact = array_shift($assignedSectionEditors);
  125. if (!$editorialContact) $editorialContact = array_shift($assignedEditors);
  126. $paramArray = array(
  127. 'editorialContactName' => $editorialContact->getEditorFullName(),
  128. 'copyeditorName' => $user->getFullName()
  129. );
  130. }
  131. $email->assignParams($paramArray);
  132. }
  133. $email->displayEditForm(Request::url(null, 'copyeditor', 'completeFinalCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getArticleId()));
  134. return false;
  135. }
  136. }
  137. /**
  138. * Set that the copyedit is underway.
  139. */
  140. function copyeditUnderway(&$copyeditorSubmission) {
  141. if (!HookRegistry::call('CopyeditorAction::copyeditUnderway', array(&$copyeditorSubmission))) {
  142. $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
  143. if ($copyeditorSubmission->getDateNotified() != null && $copyeditorSubmission->getDateUnderway() == null) {
  144. $copyeditorSubmission->setDateUnderway(Core::getCurrentDate());
  145. $update = true;
  146. } elseif ($copyeditorSubmission->getDateFinalNotified() != null && $copyeditorSubmission->getDateFinalUnderway() == null) {
  147. $copyeditorSubmission->setDateFinalUnderway(Core::getCurrentDate());
  148. $update = true;
  149. }
  150. if (isset($update)) {
  151. $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
  152. // Add log entry
  153. $user = &Request::getUser();
  154. import('article.log.ArticleLog');
  155. import('article.log.ArticleEventLogEntry');
  156. ArticleLog::logEvent($copyeditorSubmission->getArticleId(), ARTICLE_LOG_COPYEDIT_INITIATE, ARTICLE_LOG_TYPE_COPYEDIT, $user->getUserId(), 'log.copyedit.initiate', Array('copyeditorName' => $user->getFullName(), 'articleId' => $copyeditorSubmission->getArticleId()));
  157. }
  158. }
  159. }
  160. /**
  161. * Upload the copyedited version of an article.
  162. * @param $copyeditorSubmission object
  163. */
  164. function uploadCopyeditVersion($copyeditorSubmission, $copyeditStage) {
  165. import("file.ArticleFileManager");
  166. $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
  167. $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
  168. // Only allow an upload if they're in the initial or final copyediting
  169. // stages.
  170. if ($copyeditStage == 'initial' && ($copyeditorSubmission->getDateNotified() == null || $copyeditorSubmission->getDateCompleted() != null)) return;
  171. else if ($copyeditStage == 'final' && ($copyeditorSubmission->getDateFinalNotified() == null || $copyeditorSubmission->getDateFinalCompleted() != null)) return;
  172. else if ($copyeditStage != 'initial' && $copyeditStage != 'final') return;
  173. $articleFileManager = &new ArticleFileManager($copyeditorSubmission->getArticleId());
  174. $user = &Request::getUser();
  175. $fileName = 'upload';
  176. if ($articleFileManager->uploadedFileExists($fileName)) {
  177. HookRegistry::call('CopyeditorAction::uploadCopyeditVersion', array(&$copyeditorSubmission));
  178. if ($copyeditorSubmission->getCopyeditFileId() != null) {
  179. $fileId = $articleFileManager->uploadCopyeditFile($fileName, $copyeditorSubmission->getCopyeditFileId());
  180. } else {
  181. $fileId = $articleFileManager->uploadCopyeditFile($fileName);
  182. }
  183. }
  184. if (isset($fileId) && $fileId != 0) {
  185. $copyeditorSubmission->setCopyeditFileId($fileId);
  186. if ($copyeditStage == 'initial') {
  187. $copyeditorSubmission->setInitialRevision($articleFileDao->getRevisionNumber($fileId));
  188. } elseif ($copyeditStage == 'final') {
  189. $copyeditorSubmission->setFinalRevision($articleFileDao->getRevisionNumber($fileId));
  190. }
  191. $copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
  192. // Add log
  193. import('article.log.ArticleLog');
  194. import('article.log.ArticleEventLogEntry');
  195. $entry = &new ArticleEventLogEntry();
  196. $entry->setArticleId($copyeditorSubmission->getArticleId());
  197. $entry->setUserId($user->getUserId());
  198. $entry->setDateLogged(Core::getCurrentDate());
  199. $entry->setEventType(ARTICLE_LOG_COPYEDIT_COPYEDITOR_FILE);
  200. $entry->setLogMessage('log.copyedit.copyeditorFile');
  201. $entry->setAssocType(ARTICLE_LOG_TYPE_COPYEDIT);
  202. $entry->setAssocId($fileId);
  203. ArticleLog::logEventEntry($copyeditorSubmission->getArticleId(), $entry);
  204. }
  205. }
  206. //
  207. // Comments
  208. //
  209. /**
  210. * View layout comments.
  211. * @param $article object
  212. */
  213. function viewLayoutComments($article) {
  214. if (!HookRegistry::call('CopyeditorAction::viewLayoutComments', array(&$article))) {
  215. import("submission.form.comment.LayoutCommentForm");
  216. $commentForm = &new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
  217. $commentForm->initData();
  218. $commentForm->display();
  219. }
  220. }
  221. /**
  222. * Post layout comment.
  223. * @param $article object
  224. */
  225. function postLayoutComment($article, $emailComment) {
  226. if (!HookRegistry::call('CopyeditorAction::postLayoutComment', array(&$article, &$emailComment))) {
  227. import("submission.form.comment.LayoutCommentForm");
  228. $commentForm = &new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
  229. $commentForm->readInputData();
  230. if ($commentForm->validate()) {
  231. $commentForm->execute();
  232. if ($emailComment) {
  233. $commentForm->email();
  234. }
  235. } else {
  236. $commentForm->display();
  237. return false;
  238. }
  239. return true;
  240. }
  241. }
  242. /**
  243. * View copyedit comments.
  244. * @param $article object
  245. */
  246. function viewCopyeditComments($article) {
  247. if (!HookRegistry::call('CopyeditorAction::viewCopyeditComments', array(&$article))) {
  248. import("submission.form.comment.CopyeditCommentForm");
  249. $commentForm = &new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
  250. $commentForm->initData();
  251. $commentForm->display();
  252. }
  253. }
  254. /**
  255. * Post copyedit comment.
  256. * @param $article object
  257. */
  258. function postCopyeditComment($article, $emailComment) {
  259. if (!HookRegistry::call('CopyeditorAction::postCopyeditComment', array(&$article, &$emailComment))) {
  260. import("submission.form.comment.CopyeditCommentForm");
  261. $commentForm = &new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
  262. $commentForm->readInputData();
  263. if ($commentForm->validate()) {
  264. $commentForm->execute();
  265. if ($emailComment) {
  266. $commentForm->email();
  267. }
  268. } else {
  269. $commentForm->display();
  270. return false;
  271. }
  272. return true;
  273. }
  274. }
  275. //
  276. // Misc
  277. //
  278. /**
  279. * Download a file a copyeditor has access to.
  280. * @param $submission object
  281. * @param $fileId int
  282. * @param $revision int
  283. */
  284. function downloadCopyeditorFile($submission, $fileId, $revision = null) {
  285. $copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
  286. $canDownload = false;
  287. // Copyeditors have access to:
  288. // 1) The first revision of the copyedit file
  289. // 2) The initial copyedit revision
  290. // 3) The author copyedit revision, after the author copyedit has been completed
  291. // 4) The final copyedit revision
  292. // 5) Layout galleys
  293. if ($submission->getCopyeditFileId() == $fileId) {
  294. $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
  295. $currentRevision = &$articleFileDao->getRevisionNumber($fileId);
  296. if ($revision == null) {
  297. $revision = $currentRevision;
  298. }
  299. if ($revision == 1) {
  300. $canDownload = true;
  301. } else if ($submission->getInitialRevision() == $revision) {
  302. $canDownload = true;
  303. } else if ($submission->getEditorAuthorRevision() == $revision && $submission->getDateAuthorCompleted() != null) {
  304. $canDownload = true;
  305. } else if ($submission->getFinalRevision() == $revision) {
  306. $canDownload = true;
  307. }
  308. }
  309. else {
  310. // Check galley files
  311. foreach ($submission->getGalleys() as $galleyFile) {
  312. if ($galleyFile->getFileId() == $fileId) {
  313. $canDownload = true;
  314. }
  315. }
  316. // Check supp files
  317. foreach ($submission->getSuppFiles() as $suppFile) {
  318. if ($suppFile->getFileId() == $fileId) {
  319. $canDownload = true;
  320. }
  321. }
  322. }
  323. $result = false;
  324. if (!HookRegistry::call('CopyeditorAction::downloadCopyeditorFile', array(&$submission, &$fileId, &$revision, &$result))) {
  325. if ($canDownload) {
  326. return Action::downloadFile($submission->getArticleId(), $fileId, $revision);
  327. } else {
  328. return false;
  329. }
  330. }
  331. return $result;
  332. }
  333. }
  334. ?>