Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
ProofreaderAction.inc.php
1 <?php
2 
20 import('classes.submission.common.Action');
21 
22 class ProofreaderAction extends Action {
23 
27  function selectProofreader($userId, $article, $request) {
28  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
29  $proofSignoff = $signoffDao->build('SIGNOFF_PROOFREADING_PROOFREADER', ASSOC_TYPE_ARTICLE, $article->getId());
30 
31  if (!HookRegistry::call('ProofreaderAction::selectProofreader', array(&$userId, &$article))) {
32  $proofSignoff->setUserId($userId);
33  $signoffDao->updateObject($proofSignoff);
34 
35  // Add log entry
36  $user =& Request::getUser();
37  $userDao =& DAORegistry::getDAO('UserDAO');
38  $proofreader =& $userDao->getUser($userId);
39  if (!isset($proofreader)) return;
40  import('classes.article.log.ArticleLog');
41  import('classes.article.log.ArticleEventLogEntry');
42  ArticleLog::logEvent($request, $article, ARTICLE_LOG_PROOFREAD_ASSIGN, 'log.proofread.assign', array('assignerName' => $user->getFullName(), 'proofreaderName' => $proofreader->getFullName()));
43  }
44  }
45 
54  function proofreadEmail($articleId, $mailType, $request, $actionPath = '') {
55  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
56  $sectionEditorSubmissionDao =& DAORegistry::getDAO('SectionEditorSubmissionDAO');
57  $sectionEditorSubmission =& $sectionEditorSubmissionDao->getSectionEditorSubmission($articleId);
58  $userDao =& DAORegistry::getDAO('UserDAO');
59  $journal =& Request::getJournal();
60  $user =& Request::getUser();
61  $ccs = array();
62 
63  import('classes.mail.ArticleMailTemplate');
64  $email = new ArticleMailTemplate($sectionEditorSubmission, $mailType);
65 
66  switch($mailType) {
67  case 'PROOFREAD_AUTHOR_REQUEST':
68  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_AUTHOR;
69  $signoffType = 'SIGNOFF_PROOFREADING_AUTHOR';
70  $setDateField = 'setDateNotified';
71  $nullifyDateFields = array('setDateUnderway', 'setDateCompleted', 'setDateAcknowledged');
72  $setUserId = $sectionEditorSubmission->getUserId();
73  $receiver =& $userDao->getUser($setUserId);
74  $setUserId = $receiver;
75  if (!isset($receiver)) return true;
76  $receiverName = $receiver->getFullName();
77  $receiverAddress = $receiver->getEmail();
78  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
79  $addParamArray = array(
80  'authorName' => $receiver->getFullName(),
81  'authorUsername' => $receiver->getUsername(),
82  'authorPassword' => $receiver->getPassword(),
83  'editorialContactSignature' => $user->getContactSignature(),
84  'submissionUrl' => Request::url(null, 'author', 'submissionEditing', $articleId)
85  );
86  break;
87 
88  case 'PROOFREAD_AUTHOR_ACK':
89  $eventType = ARTICLE_EMAIL_PROOFREAD_THANK_AUTHOR;
90  $signoffType = 'SIGNOFF_PROOFREADING_AUTHOR';
91  $setDateField = 'setDateAcknowledged';
92  $receiver =& $userDao->getUser($sectionEditorSubmission->getUserId());
93  if (!isset($receiver)) return true;
94  $receiverName = $receiver->getFullName();
95  $receiverAddress = $receiver->getEmail();
96  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
97  $addParamArray = array(
98  'authorName' => $receiver->getFullName(),
99  'editorialContactSignature' => $user->getContactSignature()
100  );
101  break;
102 
103  case 'PROOFREAD_AUTHOR_COMPLETE':
104  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_AUTHOR_COMPLETE;
105  $signoffType = 'SIGNOFF_PROOFREADING_AUTHOR';
106  $setDateField = 'setDateCompleted';
107  $getDateField = 'getDateCompleted';
108 
109  $editAssignments =& $sectionEditorSubmission->getEditAssignments();
110  $nextSignoff = $signoffDao->build('SIGNOFF_PROOFREADING_PROOFREADER', ASSOC_TYPE_ARTICLE, $articleId);
111 
112  if ($nextSignoff->getUserId() != 0) {
113  $setNextDateField = 'setDateNotified';
114  $proofreader =& $userDao->getUser($nextSignoff->getUserId());
115 
116  $receiverName = $proofreader->getFullName();
117  $receiverAddress = $proofreader->getEmail();
118 
119  $editorAdded = false;
120  foreach ($editAssignments as $editAssignment) {
121  if ($editAssignment->getIsEditor() || $editAssignment->getCanEdit()) {
122  $ccs[$editAssignment->getEditorEmail()] = $editAssignment->getEditorFullName();
123  $editorAdded = true;
124  }
125  }
126  if (!$editorAdded) $ccs[$journal->getSetting('contactEmail')] = $journal->getSetting('contactName');
127  } else {
128  $editorAdded = false;
129  $assignmentIndex = 0;
130  foreach ($editAssignments as $editAssignment) {
131  if ($editAssignment->getIsEditor() || $editAssignment->getCanEdit()) {
132  if ($assignmentIndex++ == 0) {
133  $receiverName = $editAssignment->getEditorFullName();
134  $receiverAddress = $editAssignment->getEditorEmail();
135  } else {
136  $ccs[$editAssignment->getEditorEmail()] = $editAssignment->getEditorFullName();
137  }
138  $editorAdded = true;
139  }
140  }
141  if (!$editorAdded) {
142  $receiverAddress = $journal->getSetting('contactEmail');
143  $receiverName = $journal->getSetting('contactName');
144  }
145  }
146 
147  $addParamArray = array(
148  'editorialContactName' => $receiverName,
149  'authorName' => $user->getFullName()
150  );
151  break;
152 
153  case 'PROOFREAD_REQUEST':
154  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_PROOFREADER;
155  $signoffType = 'SIGNOFF_PROOFREADING_PROOFREADER';
156  $setDateField = 'setDateNotified';
157  $nullifyDateFields = array('setDateUnderway', 'setDateCompleted', 'setDateAcknowledged');
158 
159  $receiver = $sectionEditorSubmission->getUserBySignoffType($signoffType);
160  if (!isset($receiver)) return true;
161  $receiverName = $receiver->getFullName();
162  $receiverAddress = $receiver->getEmail();
163  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
164 
165  $addParamArray = array(
166  'proofreaderName' => $receiverName,
167  'proofreaderUsername' => $receiver->getUsername(),
168  'proofreaderPassword' => $receiver->getPassword(),
169  'editorialContactSignature' => $user->getContactSignature(),
170  'submissionUrl' => Request::url(null, 'proofreader', 'submission', $articleId)
171  );
172  break;
173 
174  case 'PROOFREAD_ACK':
175  $eventType = ARTICLE_EMAIL_PROOFREAD_THANK_PROOFREADER;
176  $signoffType = 'SIGNOFF_PROOFREADING_PROOFREADER';
177  $setDateField = 'setDateAcknowledged';
178 
179  $receiver = $sectionEditorSubmission->getUserBySignoffType($signoffType);
180  if (!isset($receiver)) return true;
181  $receiverName = $receiver->getFullName();
182  $receiverAddress = $receiver->getEmail();
183  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
184 
185  $addParamArray = array(
186  'proofreaderName' => $receiverName,
187  'editorialContactSignature' => $user->getContactSignature()
188  );
189  break;
190 
191  case 'PROOFREAD_COMPLETE':
192  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_PROOFREADER_COMPLETE;
193  $signoffType = 'SIGNOFF_PROOFREADING_PROOFREADER';
194  $setDateField = 'setDateCompleted';
195  $getDateField = 'getDateCompleted';
196 
197  $setNextDateField = 'setDateNotified';
198  $nextSignoff = $signoffDao->build('SIGNOFF_PROOFREADING_LAYOUT', ASSOC_TYPE_ARTICLE, $articleId);
199 
200  $editAssignments =& $sectionEditorSubmission->getEditAssignments();
201 
202  $receiver = null;
203 
204  $editorAdded = false;
205  foreach ($editAssignments as $editAssignment) {
206  if ($editAssignment->getIsEditor() || $editAssignment->getCanEdit()) {
207  if ($receiver === null) {
208  $receiver =& $userDao->getUser($editAssignment->getEditorId());
209  } else {
210  $ccs[$editAssignment->getEditorEmail()] = $editAssignment->getEditorFullName();
211  }
212  $editorAdded = true;
213  }
214  }
215  if (isset($receiver)) {
216  $receiverName = $receiver->getFullName();
217  $receiverAddress = $receiver->getEmail();
218  } else {
219  $receiverAddress = $journal->getSetting('contactEmail');
220  $receiverName = $journal->getSetting('contactName');
221  }
222  if (!$editorAdded) {
223  $ccs[$journal->getSetting('contactEmail')] = $journal->getSetting('contactName');
224  }
225 
226  $addParamArray = array(
227  'editorialContactName' => $receiverName,
228  'proofreaderName' => $user->getFullName()
229  );
230  break;
231 
232  case 'PROOFREAD_LAYOUT_REQUEST':
233  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_LAYOUTEDITOR;
234  $signoffType = 'SIGNOFF_PROOFREADING_LAYOUT';
235  $setDateField = 'setDateNotified';
236  $nullifyDateFields = array('setDateUnderway', 'setDateCompleted', 'setDateAcknowledged');
237 
238  $receiver = $sectionEditorSubmission->getUserBySignoffType($signoffType);
239  if (!isset($receiver)) return true;
240  $receiverName = $receiver->getFullName();
241  $receiverAddress = $receiver->getEmail();
242  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
243 
244  $addParamArray = array(
245  'layoutEditorName' => $receiverName,
246  'layoutEditorUsername' => $receiver->getUsername(),
247  'layoutEditorPassword' => $receiver->getPassword(),
248  'editorialContactSignature' => $user->getContactSignature(),
249  'submissionUrl' => Request::url(null, 'proofreader', 'submission', $articleId)
250  );
251 
252  if (!$actionPath) {
253  // Reset underway/complete/thank dates
254  $signoffReset = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $articleId);
255  $signoffReset->setDateUnderway(null);
256  $signoffReset->setDateCompleted(null);
257  $signoffReset->setDateAcknowledged(null);
258  }
259  break;
260 
261  case 'PROOFREAD_LAYOUT_ACK':
262  $eventType = ARTICLE_EMAIL_PROOFREAD_THANK_LAYOUTEDITOR;
263  $signoffType = 'SIGNOFF_PROOFREADING_LAYOUT';
264  $setDateField = 'setDateAcknowledged';
265 
266  $receiver = $sectionEditorSubmission->getUserBySignoffType($signoffType);
267  if (!isset($receiver)) return true;
268  $receiverName = $receiver->getFullName();
269  $receiverAddress = $receiver->getEmail();
270  $email->ccAssignedEditingSectionEditors($sectionEditorSubmission->getId());
271 
272  $addParamArray = array(
273  'layoutEditorName' => $receiverName,
274  'editorialContactSignature' => $user->getContactSignature()
275  );
276  break;
277 
278  case 'PROOFREAD_LAYOUT_COMPLETE':
279  $eventType = ARTICLE_EMAIL_PROOFREAD_NOTIFY_LAYOUTEDITOR_COMPLETE;
280  $signoffType = 'SIGNOFF_PROOFREADING_LAYOUT';
281  $setDateField = 'setDateCompleted';
282  $getDateField = 'getDateCompleted';
283 
284  $editAssignments =& $sectionEditorSubmission->getEditAssignments();
285  $assignmentIndex = 0;
286  $editorAdded = false;
287  foreach ($editAssignments as $editAssignment) {
288  if ($editAssignment->getIsEditor() || $editAssignment->getCanEdit()) {
289  if ($assignmentIndex++ == 0) {
290  $receiverName = $editAssignment->getEditorFullName();
291  $receiverAddress = $editAssignment->getEditorEmail();
292  } else {
293  $ccs[$editAssignment->getEditorEmail()] = $editAssignment->getEditorFullName();
294  }
295  $editorAdded = true;
296  }
297  }
298  if (!$editorAdded) {
299  $receiverAddress = $journal->getSetting('contactEmail');
300  $receiverName = $journal->getSetting('contactName');
301  }
302 
303  $addParamArray = array(
304  'editorialContactName' => $receiverName,
305  'layoutEditorName' => $user->getFullName()
306  );
307  break;
308 
309  default:
310  return true;
311  }
312 
313  $signoff = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $articleId);
314 
315  if (isset($getDateField)) {
316  $date = $signoff->$getDateField();
317  if (isset($date)) {
318  Request::redirect(null, null, 'submission', $articleId);
319  }
320  }
321 
322  if ($email->isEnabled() && ($actionPath || $email->hasErrors())) {
323  if (!Request::getUserVar('continued')) {
324  $email->addRecipient($receiverAddress, $receiverName);
325  if (isset($ccs)) foreach ($ccs as $address => $name) {
326  $email->addCc($address, $name);
327  }
328 
329  $paramArray = array();
330 
331  if (isset($addParamArray)) {
332  $paramArray += $addParamArray;
333  }
334  $email->assignParams($paramArray);
335  }
336  $email->displayEditForm($actionPath, array('articleId' => $articleId));
337  return false;
338  } else {
339  HookRegistry::call('ProofreaderAction::proofreadEmail', array(&$email, $mailType));
340  if ($email->isEnabled()) {
341  $email->send($request);
342  }
343 
344  $signoff->$setDateField(Core::getCurrentDate());
345  if (isset($setNextDateField)) {
346  $nextSignoff->$setNextDateField(Core::getCurrentDate());
347  }
348  if (isset($nullifyDateFields)) foreach ($nullifyDateFields as $fieldSetter) {
349  $signoff->$fieldSetter(null);
350  }
351 
352  $signoffDao->updateObject($signoff);
353  if(isset($nextSignoff)) $signoffDao->updateObject($nextSignoff);
354 
355  return true;
356  }
357 
358  }
359 
365  function proofreadingUnderway(&$submission, $signoffType) {
366  $signoffDao =& DAORegistry::getDAO('SignoffDAO');
367  $signoff = $signoffDao->build($signoffType, ASSOC_TYPE_ARTICLE, $submission->getId());
368 
369  if (!$signoff->getDateUnderway() && $signoff->getDateNotified() && !HookRegistry::call('ProofreaderAction::proofreadingUnderway', array(&$submission, &$signoffType))) {
370  $dateUnderway = Core::getCurrentDate();
371  $signoff->setDateUnderway($dateUnderway);
372  $signoffDao->updateObject($signoff);
373  }
374  }
375 
376  //
377  // Misc
378  //
379 
386  function downloadProofreaderFile($submission, $fileId, $revision = null) {
387  $canDownload = false;
388 
389  // Proofreaders have access to:
390  // 1) All supplementary files.
391  // 2) All galley files.
392 
393  // Check supplementary files
394  foreach ($submission->getSuppFiles() as $suppFile) {
395  if ($suppFile->getFileId() == $fileId) {
396  $canDownload = true;
397  }
398  }
399 
400  // Check galley files
401  foreach ($submission->getGalleys() as $galleyFile) {
402  if ($galleyFile->getFileId() == $fileId) {
403  $canDownload = true;
404  }
405  }
406 
407  $result = false;
408  if (!HookRegistry::call('ProofreaderAction::downloadProofreaderFile', array(&$submission, &$fileId, &$revision, &$canDownload, &$result))) {
409  if ($canDownload) {
410  return Action::downloadFile($submission->getId(), $fileId, $revision);
411  } else {
412  return false;
413  }
414  }
415  return $result;
416  }
417 
422  function viewProofreadComments($article) {
423  if (!HookRegistry::call('ProofreaderAction::viewProofreadComments', array(&$article))) {
424  import('classes.submission.form.comment.ProofreadCommentForm');
425 
426  $commentForm = new ProofreadCommentForm($article, ROLE_ID_PROOFREADER);
427  $commentForm->initData();
428  $commentForm->display();
429  }
430  }
431 
438  function postProofreadComment($article, $emailComment, $request) {
439  if (!HookRegistry::call('ProofreaderAction::postProofreadComment', array(&$article, &$emailComment))) {
440  import('classes.submission.form.comment.ProofreadCommentForm');
441 
442  $commentForm = new ProofreadCommentForm($article, ROLE_ID_PROOFREADER);
443  $commentForm->readInputData();
444 
445  if ($commentForm->validate()) {
446  $commentForm->execute();
447 
448  // Send a notification to associated users
449  import('classes.notification.NotificationManager');
450  $notificationManager = new NotificationManager();
451  $notificationUsers = $article->getAssociatedUserIds(true, false);
452  foreach ($notificationUsers as $userRole) {
453  $notificationManager->createNotification(
454  $request, $userRole['id'], NOTIFICATION_TYPE_PROOFREAD_COMMENT,
455  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
456  );
457  }
458 
459  if ($emailComment) {
460  $commentForm->email($request);
461  }
462 
463  } else {
464  $commentForm->display();
465  return false;
466  }
467  return true;
468  }
469  }
470 
475  function viewLayoutComments($article) {
476  if (!HookRegistry::call('ProofreaderAction::viewLayoutComments', array(&$article))) {
477  import('classes.submission.form.comment.LayoutCommentForm');
478 
479  $commentForm = new LayoutCommentForm($article, ROLE_ID_PROOFREADER);
480  $commentForm->initData();
481  $commentForm->display();
482  }
483  }
484 
491  function postLayoutComment($article, $emailComment, $request) {
492  if (!HookRegistry::call('ProofreaderAction::postLayoutComment', array(&$article, &$emailComment))) {
493  import('classes.submission.form.comment.LayoutCommentForm');
494 
495  $commentForm = new LayoutCommentForm($article, ROLE_ID_PROOFREADER);
496  $commentForm->readInputData();
497 
498  if ($commentForm->validate()) {
499  $commentForm->execute();
500 
501  // Send a notification to associated users
502  import('classes.notification.NotificationManager');
503  $notificationManager = new NotificationManager();
504  $notificationUsers = $article->getAssociatedUserIds(true, false);
505  foreach ($notificationUsers as $userRole) {
506  $notificationManager->createNotification(
507  $request, $userRole['id'], NOTIFICATION_TYPE_LAYOUT_COMMENT,
508  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
509  );
510  }
511 
512  if ($emailComment) {
513  $commentForm->email($request);
514  }
515  } else {
516  $commentForm->display();
517  return false;
518  }
519  return true;
520  }
521  }
522 }
523 
524 ?>
postLayoutComment($article, $emailComment, $request)
logEvent(&$request, &$article, $eventType, $messageKey, $params=array())
downloadFile($articleId, $fileId, $revision=null)
Definition: Action.inc.php:180
downloadProofreaderFile($submission, $fileId, $revision=null)
Subclass of MailTemplate for sending emails related to articles.
& getJournal()
Definition: Request.inc.php:42
redirect($context=null, $page=null, $op=null, $path=null, $params=null, $anchor=null)
getCurrentDate($ts=null)
Definition: Core.inc.php:94
proofreadEmail($articleId, $mailType, $request, $actionPath= '')
Application-specific submission actions.
Definition: Action.inc.php:44
proofreadingUnderway(&$submission, $signoffType)
selectProofreader($userId, $article, $request)
ProofreaderAction class.
LayoutComment form.
& getDAO($name, $dbconn=null)
postProofreadComment($article, $emailComment, $request)
url($journalPath=null, $page=null, $op=null, $path=null, $params=null, $anchor=null, $escape=false)
Definition: Request.inc.php:88
ProofreadComment form.
call($hookName, $args=null)