Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
CopyeditorAction.inc.php
1 <?php
2 
18 import('classes.submission.common.Action');
19 
20 class CopyeditorAction extends Action {
21 
25  function CopyeditorAction() {
26 
27  }
28 
39  function completeCopyedit($copyeditorSubmission, $send, $request) {
40  $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
41  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
42  $userDao =& DAORegistry::getDAO('UserDAO');
43  $journal =& $request->getJournal();
44 
45  $initialSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
46  if ($initialSignoff->getDateCompleted() != null) {
47  return true;
48  }
49 
50  $user =& $request->getUser();
51  import('classes.mail.ArticleMailTemplate');
52  $email = new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_COMPLETE');
53 
54  $editAssignments = $copyeditorSubmission->getEditAssignments();
55 
56  $author = $copyeditorSubmission->getUser();
57 
58  if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
59  HookRegistry::call('CopyeditorAction::completeCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$author, &$email));
60  if ($email->isEnabled()) {
61  $email->send($request);
62  }
63 
64  $initialSignoff->setDateCompleted(Core::getCurrentDate());
65 
66  $authorSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_AUTHOR', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
67  $authorSignoff->setUserId($author->getId());
68  $authorSignoff->setDateNotified(Core::getCurrentDate());
69  $signoffDao->updateObject($initialSignoff);
70  $signoffDao->updateObject($authorSignoff);
71 
72 
73  // Add log entry
74  import('classes.article.log.ArticleLog');
75  ArticleLog::logEvent($request, $copyeditorSubmission, ARTICLE_LOG_COPYEDIT_INITIAL, 'log.copyedit.initialEditComplete', array('copyeditorName' => $user->getFullName()));
76 
77  return true;
78 
79  } else {
80  if (!$request->getUserVar('continued')) {
81  $email->addRecipient($author->getEmail(), $author->getFullName());
82  $email->ccAssignedEditingSectionEditors($copyeditorSubmission->getId());
83  $email->ccAssignedEditors($copyeditorSubmission->getId());
84 
85  $paramArray = array(
86  'editorialContactName' => $author->getFullName(),
87  'copyeditorName' => $user->getFullName(),
88  'authorUsername' => $author->getUsername(),
89  'submissionEditingUrl' => $request->url(null, 'author', 'submissionEditing', array($copyeditorSubmission->getId()))
90  );
91  $email->assignParams($paramArray);
92  }
93  $email->displayEditForm($request->url(null, 'copyeditor', 'completeCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getId()));
94 
95  return false;
96  }
97  }
98 
105  function completeFinalCopyedit($copyeditorSubmission, $send, $request) {
106  $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
107  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
108  $userDao =& DAORegistry::getDAO('UserDAO');
109  $journal =& $request->getJournal();
110 
111  $finalSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
112  if ($finalSignoff->getDateCompleted() != null) {
113  return true;
114  }
115 
116  $user =& $request->getUser();
117  import('classes.mail.ArticleMailTemplate');
118  $email = new ArticleMailTemplate($copyeditorSubmission, 'COPYEDIT_FINAL_COMPLETE');
119 
120  $editAssignments = $copyeditorSubmission->getEditAssignments();
121 
122  if (!$email->isEnabled() || ($send && !$email->hasErrors())) {
123  HookRegistry::call('CopyeditorAction::completeFinalCopyedit', array(&$copyeditorSubmission, &$editAssignments, &$email));
124  if ($email->isEnabled()) {
125  $email->send($request);
126  }
127 
128  $finalSignoff->setDateCompleted(Core::getCurrentDate());
129  $signoffDao->updateObject($finalSignoff);
130 
131  if ($copyEdFile = $copyeditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_FINAL')) {
132  // Set initial layout version to final copyedit version
133  $layoutSignoff = $signoffDao->build('SIGNOFF_LAYOUT', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
134 
135  if (!$layoutSignoff->getFileId()) {
136  import('classes.file.ArticleFileManager');
137  $articleFileManager = new ArticleFileManager($copyeditorSubmission->getId());
138  if ($layoutFileId = $articleFileManager->copyToLayoutFile($copyEdFile->getFileId(), $copyEdFile->getRevision())) {
139  $layoutSignoff->setFileId($layoutFileId);
140  $signoffDao->updateObject($layoutSignoff);
141  }
142  }
143  }
144 
145  // Add log entry
146  import('classes.article.log.ArticleLog');
147  import('classes.article.log.ArticleEventLogEntry');
148  ArticleLog::logEvent($request, $copyeditorSubmission, ARTICLE_LOG_COPYEDIT_FINAL, 'log.copyedit.finalEditComplete', Array('copyeditorName' => $user->getFullName()));
149 
150  return true;
151 
152  } else {
153  if (!$request->getUserVar('continued')) {
154  $assignedSectionEditors = $email->toAssignedEditingSectionEditors($copyeditorSubmission->getId());
155  $assignedEditors = $email->ccAssignedEditors($copyeditorSubmission->getId());
156  if (empty($assignedSectionEditors) && empty($assignedEditors)) {
157  $email->addRecipient($journal->getSetting('contactEmail'), $journal->getSetting('contactName'));
158  $paramArray = array(
159  'editorialContactName' => $journal->getSetting('contactName'),
160  'copyeditorName' => $user->getFullName()
161  );
162  } else {
163  $editorialContact = array_shift($assignedSectionEditors);
164  if (!$editorialContact) $editorialContact = array_shift($assignedEditors);
165 
166  $paramArray = array(
167  'editorialContactName' => $editorialContact->getEditorFullName(),
168  'copyeditorName' => $user->getFullName()
169  );
170  }
171  $email->assignParams($paramArray);
172  }
173  $email->displayEditForm($request->url(null, 'copyeditor', 'completeFinalCopyedit', 'send'), array('articleId' => $copyeditorSubmission->getId()));
174 
175  return false;
176  }
177  }
178 
182  function copyeditUnderway(&$copyeditorSubmission, $request) {
183  if (!HookRegistry::call('CopyeditorAction::copyeditUnderway', array(&$copyeditorSubmission))) {
184  $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
185  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
186 
187  $initialSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
188  $finalSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
189 
190  if ($initialSignoff->getDateNotified() != null && $initialSignoff->getDateUnderway() == null) {
191  $initialSignoff->setDateUnderway(Core::getCurrentDate());
192  $signoffDao->updateObject($initialSignoff);
193  $update = true;
194 
195  } elseif ($finalSignoff->getDateNotified() != null && $finalSignoff->getDateUnderway() == null) {
196  $finalSignoff->setDateUnderway(Core::getCurrentDate());
197  $signoffDao->updateObject($finalSignoff);
198  $update = true;
199  }
200 
201  if (isset($update)) {
202  // Add log entry
203  $user =& $request->getUser();
204  import('classes.article.log.ArticleLog');
205  ArticleLog::logEvent($request, $copyeditorSubmission, ARTICLE_LOG_COPYEDIT_INITIATE, 'log.copyedit.initiate', array('copyeditorName' => $user->getFullName()));
206  }
207  }
208  }
209 
216  function uploadCopyeditVersion($copyeditorSubmission, $copyeditStage, $request) {
217  import('classes.file.ArticleFileManager');
218  $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
219  $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
220  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
221 
222  if($copyeditStage == 'initial') {
223  $signoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
224  } else if($copyeditStage == 'final') {
225  $signoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
226  }
227 
228  // Only allow an upload if they're in the initial or final copyediting
229  // stages.
230  if ($copyeditStage == 'initial' && ($signoff->getDateNotified() == null || $signoff->getDateCompleted() != null)) return;
231  else if ($copyeditStage == 'final' && ($signoff->getDateNotified() == null || $signoff->getDateCompleted() != null)) return;
232  else if ($copyeditStage != 'initial' && $copyeditStage != 'final') return;
233 
234  $articleFileManager = new ArticleFileManager($copyeditorSubmission->getId());
235  $user =& $request->getUser();
236 
237  $fileName = 'upload';
238  if ($articleFileManager->uploadedFileExists($fileName)) {
239  HookRegistry::call('CopyeditorAction::uploadCopyeditVersion', array(&$copyeditorSubmission));
240  if ($signoff->getFileId() != null) {
241  $fileId = $articleFileManager->uploadCopyeditFile($fileName, $copyeditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_INITIAL', true));
242  } else {
243  $fileId = $articleFileManager->uploadCopyeditFile($fileName);
244  }
245  }
246 
247  if (isset($fileId) && $fileId != 0) {
248  $signoff->setFileId($fileId);
249  $signoff->setFileRevision($articleFileDao->getRevisionNumber($fileId));
250  $signoffDao->updateObject($signoff);
251 
252  // Add log
253  import('classes.article.log.ArticleLog');
254  ArticleLog::logEvent($request, $copyeditorSubmission, ARTICLE_LOG_COPYEDITOR_FILE, 'log.copyedit.copyeditorFile', array('copyeditorName' => $user->getFullName(), 'fileId' => $fileId));
255  }
256  }
257 
258  //
259  // Comments
260  //
261 
266  function viewLayoutComments($article) {
267  if (!HookRegistry::call('CopyeditorAction::viewLayoutComments', array(&$article))) {
268  import('classes.submission.form.comment.LayoutCommentForm');
269 
270  $commentForm = new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
271  $commentForm->initData();
272  $commentForm->display();
273  }
274  }
275 
282  function postLayoutComment($article, $emailComment, $request) {
283  if (!HookRegistry::call('CopyeditorAction::postLayoutComment', array(&$article, &$emailComment))) {
284  import('classes.submission.form.comment.LayoutCommentForm');
285 
286  $commentForm = new LayoutCommentForm($article, ROLE_ID_COPYEDITOR);
287  $commentForm->readInputData();
288 
289  if ($commentForm->validate()) {
290  $commentForm->execute();
291 
292  // Send a notification to associated users
293  import('classes.notification.NotificationManager');
294  $notificationManager = new NotificationManager();
295  $notificationUsers = $article->getAssociatedUserIds(true, false);
296  foreach ($notificationUsers as $userRole) {
297  $notificationManager->createNotification(
298  $request, $userRole['id'], NOTIFICATION_TYPE_LAYOUT_COMMENT,
299  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
300  );
301  }
302 
303  if ($emailComment) {
304  $commentForm->email($request);
305  }
306 
307  } else {
308  $commentForm->display();
309  return false;
310  }
311  return true;
312  }
313  }
314 
319  function viewCopyeditComments($article) {
320  if (!HookRegistry::call('CopyeditorAction::viewCopyeditComments', array(&$article))) {
321  import('classes.submission.form.comment.CopyeditCommentForm');
322 
323  $commentForm = new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
324  $commentForm->initData();
325  $commentForm->display();
326  }
327  }
328 
333  function postCopyeditComment($article, $emailComment, $request) {
334  if (!HookRegistry::call('CopyeditorAction::postCopyeditComment', array(&$article, &$emailComment))) {
335  import('classes.submission.form.comment.CopyeditCommentForm');
336 
337  $commentForm = new CopyeditCommentForm($article, ROLE_ID_COPYEDITOR);
338  $commentForm->readInputData();
339 
340  if ($commentForm->validate()) {
341  $commentForm->execute();
342 
343  // Send a notification to associated users
344  import('classes.notification.NotificationManager');
345  $notificationManager = new NotificationManager();
346  $notificationUsers = $article->getAssociatedUserIds(true, false);
347  foreach ($notificationUsers as $userRole) {
348  $notificationManager->createNotification(
349  $request, $userRole['id'], NOTIFICATION_TYPE_COPYEDIT_COMMENT,
350  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
351  );
352  }
353 
354  if ($emailComment) {
355  $commentForm->email($request);
356  }
357 
358  } else {
359  $commentForm->display();
360  return false;
361  }
362  return true;
363  }
364  }
365 
366  //
367  // Misc
368  //
369 
376  function downloadCopyeditorFile($copyeditorSubmission, $fileId, $revision = null) {
377  $copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
378 
379  $canDownload = false;
380 
381  // Copyeditors have access to:
382  // 1) The first revision of the copyedit file
383  // 2) The initial copyedit revision
384  // 3) The author copyedit revision, after the author copyedit has been completed
385  // 4) The final copyedit revision
386  // 5) Layout galleys
387  if ($copyeditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_INITIAL', true) == $fileId) {
388  $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
389  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
390  $currentRevision =& $articleFileDao->getRevisionNumber($fileId);
391 
392  if ($revision == null) {
393  $revision = $currentRevision;
394  }
395 
396  $initialSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_INITIAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
397  $authorSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_AUTHOR', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
398  $finalSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
399 
400  if ($revision == 1) {
401  $canDownload = true;
402  } else if ($initialSignoff->getFileRevision() == $revision) {
403  $canDownload = true;
404  } else if ($finalSignoff->getFileRevision() == $revision) {
405  $canDownload = true;
406  }
407  } else if ($copyeditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_AUTHOR', true) == $fileId) {
408  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
409  $authorSignoff = $signoffDao->build('SIGNOFF_COPYEDITING_AUTHOR', ASSOC_TYPE_ARTICLE, $copyeditorSubmission->getId());
410  if($authorSignoff->getDateCompleted() != null) {
411  $canDownload = true;
412  }
413  } else if ($copyeditorSubmission->getFileBySignoffType('SIGNOFF_COPYEDITING_FINAL', true) == $fileId) {
414  $canDownload = true;
415  }
416  else {
417  // Check galley files
418  foreach ($copyeditorSubmission->getGalleys() as $galleyFile) {
419  if ($galleyFile->getFileId() == $fileId) {
420  $canDownload = true;
421  }
422  }
423  // Check supp files
424  foreach ($copyeditorSubmission->getSuppFiles() as $suppFile) {
425  if ($suppFile->getFileId() == $fileId) {
426  $canDownload = true;
427  }
428  }
429  }
430 
431  $result = false;
432  if (!HookRegistry::call('CopyeditorAction::downloadCopyeditorFile', array(&$copyeditorSubmission, &$fileId, &$revision, &$result))) {
433  if ($canDownload) {
434  return Action::downloadFile($copyeditorSubmission->getId(), $fileId, $revision);
435  } else {
436  return false;
437  }
438  }
439 
440  return $result;
441  }
442 }
443 
444 ?>
copyeditUnderway(&$copyeditorSubmission, $request)
downloadCopyeditorFile($copyeditorSubmission, $fileId, $revision=null)
logEvent(&$request, &$article, $eventType, $messageKey, $params=array())
downloadFile($articleId, $fileId, $revision=null)
Definition: Action.inc.php:180
Subclass of MailTemplate for sending emails related to articles.
getCurrentDate($ts=null)
Definition: Core.inc.php:94
uploadCopyeditVersion($copyeditorSubmission, $copyeditStage, $request)
CopyeditorAction class.
Application-specific submission actions.
Definition: Action.inc.php:44
postCopyeditComment($article, $emailComment, $request)
completeCopyedit($copyeditorSubmission, $send, $request)
completeFinalCopyedit($copyeditorSubmission, $send, $request)
LayoutComment form.
& getDAO($name, $dbconn=null)
postLayoutComment($article, $emailComment, $request)
Class defining operations for article file management.
call($hookName, $args=null)
CopyeditComment form.