Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
Action.inc.php
1 <?php
2 
21 /* These constants correspond to editing decision "decision codes". */
22 define('SUBMISSION_EDITOR_DECISION_ACCEPT', 1);
23 define('SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS', 2);
24 define('SUBMISSION_EDITOR_DECISION_RESUBMIT', 3);
25 define('SUBMISSION_EDITOR_DECISION_DECLINE', 4);
26 
27 /* These constants are used as search fields for the various submission lists */
28 define('SUBMISSION_FIELD_AUTHOR', 1);
29 define('SUBMISSION_FIELD_EDITOR', 2);
30 define('SUBMISSION_FIELD_TITLE', 3);
31 define('SUBMISSION_FIELD_REVIEWER', 4);
32 define('SUBMISSION_FIELD_COPYEDITOR', 5);
33 define('SUBMISSION_FIELD_LAYOUTEDITOR', 6);
34 define('SUBMISSION_FIELD_PROOFREADER', 7);
35 define('SUBMISSION_FIELD_ID', 8);
36 
37 define('SUBMISSION_FIELD_DATE_SUBMITTED', 4);
38 define('SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE', 5);
39 define('SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE', 6);
40 define('SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE', 7);
41 
42 import('lib.pkp.classes.submission.common.PKPAction');
43 
44 class Action extends PKPAction {
48  function Action() {
49  parent::PKPAction();
50  }
51 
52  //
53  // Actions.
54  //
59  function viewMetadata($article, $journal) {
60  if (!HookRegistry::call('Action::viewMetadata', array(&$article, &$journal))) {
61  import('classes.submission.form.MetadataForm');
62  $metadataForm = new MetadataForm($article, $journal);
63  if ($metadataForm->getCanEdit() && $metadataForm->isLocaleResubmit()) {
64  $metadataForm->readInputData();
65  } else {
66  $metadataForm->initData();
67  }
68  $metadataForm->display();
69  }
70  }
71 
77  function saveMetadata($article, &$request) {
78  $router =& $request->getRouter();
79  if (!HookRegistry::call('Action::saveMetadata', array(&$article))) {
80  import('classes.submission.form.MetadataForm');
81  $journal =& $request->getJournal();
82  $metadataForm = new MetadataForm($article, $journal);
83  $metadataForm->readInputData();
84 
85  // Check for any special cases before trying to save
86  if ($request->getUserVar('addAuthor')) {
87  // Add an author
88  $editData = true;
89  $authors = $metadataForm->getData('authors');
90  array_push($authors, array());
91  $metadataForm->setData('authors', $authors);
92 
93  } else if (($delAuthor = $request->getUserVar('delAuthor')) && count($delAuthor) == 1) {
94  // Delete an author
95  $editData = true;
96  list($delAuthor) = array_keys($delAuthor);
97  $delAuthor = (int) $delAuthor;
98  $authors = $metadataForm->getData('authors');
99  if (isset($authors[$delAuthor]['authorId']) && !empty($authors[$delAuthor]['authorId'])) {
100  $deletedAuthors = explode(':', $metadataForm->getData('deletedAuthors'));
101  array_push($deletedAuthors, $authors[$delAuthor]['authorId']);
102  $metadataForm->setData('deletedAuthors', join(':', $deletedAuthors));
103  }
104  array_splice($authors, $delAuthor, 1);
105  $metadataForm->setData('authors', $authors);
106 
107  if ($metadataForm->getData('primaryContact') == $delAuthor) {
108  $metadataForm->setData('primaryContact', 0);
109  }
110 
111  } else if ($request->getUserVar('moveAuthor')) {
112  // Move an author up/down
113  $editData = true;
114  $moveAuthorDir = $request->getUserVar('moveAuthorDir');
115  $moveAuthorDir = $moveAuthorDir == 'u' ? 'u' : 'd';
116  $moveAuthorIndex = (int) $request->getUserVar('moveAuthorIndex');
117  $authors = $metadataForm->getData('authors');
118 
119  if (!(($moveAuthorDir == 'u' && $moveAuthorIndex <= 0) || ($moveAuthorDir == 'd' && $moveAuthorIndex >= count($authors) - 1))) {
120  $tmpAuthor = $authors[$moveAuthorIndex];
121  $primaryContact = $metadataForm->getData('primaryContact');
122  if ($moveAuthorDir == 'u') {
123  $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex - 1];
124  $authors[$moveAuthorIndex - 1] = $tmpAuthor;
125  if ($primaryContact == $moveAuthorIndex) {
126  $metadataForm->setData('primaryContact', $moveAuthorIndex - 1);
127  } else if ($primaryContact == ($moveAuthorIndex - 1)) {
128  $metadataForm->setData('primaryContact', $moveAuthorIndex);
129  }
130  } else {
131  $authors[$moveAuthorIndex] = $authors[$moveAuthorIndex + 1];
132  $authors[$moveAuthorIndex + 1] = $tmpAuthor;
133  if ($primaryContact == $moveAuthorIndex) {
134  $metadataForm->setData('primaryContact', $moveAuthorIndex + 1);
135  } else if ($primaryContact == ($moveAuthorIndex + 1)) {
136  $metadataForm->setData('primaryContact', $moveAuthorIndex);
137  }
138  }
139  }
140  $metadataForm->setData('authors', $authors);
141  }
142 
143  if (isset($editData)) {
144  $metadataForm->display();
145  return false;
146 
147  } else {
148  if (!$metadataForm->validate()) {
149  return $metadataForm->display();
150  }
151  $metadataForm->execute($request);
152 
153  // Send a notification to associated users
154  import('classes.notification.NotificationManager');
155  $notificationManager = new NotificationManager();
156  $notificationUsers = $article->getAssociatedUserIds();
157  foreach ($notificationUsers as $userRole) {
158  $notificationManager->createNotification(
159  $request, $userRole['id'], NOTIFICATION_TYPE_METADATA_MODIFIED,
160  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
161  );
162  }
163 
164  // Add log entry
165  $user =& $request->getUser();
166  import('classes.article.log.ArticleLog');
167  ArticleLog::logEvent($request, $article, ARTICLE_LOG_METADATA_UPDATE, 'log.editor.metadataModified', array('editorName' => $user->getFullName()));
168 
169  return true;
170  }
171  }
172  }
173 
180  function downloadFile($articleId, $fileId, $revision = null) {
181  import('classes.file.ArticleFileManager');
182  $articleFileManager = new ArticleFileManager($articleId);
183  return $articleFileManager->downloadFile($fileId, $revision);
184  }
185 
192  function viewFile($articleId, $fileId, $revision = null) {
193  import('classes.file.ArticleFileManager');
194  $articleFileManager = new ArticleFileManager($articleId);
195  return $articleFileManager->downloadFile($fileId, $revision, true);
196  }
197 
202  function instructions($type, $allowed = array('copy', 'layout', 'proof', 'referenceLinking')) {
203  $journal =& Request::getJournal();
204  $templateMgr =& TemplateManager::getManager();
205 
206  if (!HookRegistry::call('Action::instructions', array(&$type, &$allowed))) {
207  if (!in_array($type, $allowed)) {
208  return false;
209  }
210 
211  AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON);
212  switch ($type) {
213  case 'copy':
214  $title = 'submission.copyedit.instructions';
215  $instructions = $journal->getLocalizedSetting('copyeditInstructions');
216  break;
217  case 'layout':
218  $title = 'submission.layout.instructions';
219  $instructions = $journal->getLocalizedSetting('layoutInstructions');
220  break;
221  case 'proof':
222  $title = 'submission.proofread.instructions';
223  $instructions = $journal->getLocalizedSetting('proofInstructions');
224  break;
225  case 'referenceLinking':
226  if (!$journal->getSetting('provideRefLinkInstructions')) return false;
227  $title = 'submission.layout.referenceLinking';
228  $instructions = $journal->getLocalizedSetting('refLinkInstructions');
229  break;
230  default:
231  return false;
232  }
233  }
234 
235  $templateMgr->assign('pageTitle', $title);
236  $templateMgr->assign('instructions', $instructions);
237  $templateMgr->display('submission/instructions.tpl');
238 
239  return true;
240  }
241 
246  function editComment($article, $comment) {
247  if (!HookRegistry::call('Action::editComment', array(&$article, &$comment))) {
248  import('classes.submission.form.comment.EditCommentForm');
249 
250  $commentForm = new EditCommentForm($article, $comment);
251  $commentForm->initData();
252  $commentForm->display();
253  }
254  }
255 
260  function saveComment($article, &$comment, $emailComment, $request) {
261  if (!HookRegistry::call('Action::saveComment', array(&$article, &$comment, &$emailComment))) {
262  import('classes.submission.form.comment.EditCommentForm');
263 
264  $commentForm = new EditCommentForm($article, $comment);
265  $commentForm->readInputData();
266 
267  if ($commentForm->validate()) {
268  $commentForm->execute();
269 
270  // Send a notification to associated users
271  import('classes.notification.NotificationManager');
272  $notificationManager = new NotificationManager();
273  $notificationUsers = $article->getAssociatedUserIds(true, false);
274  foreach ($notificationUsers as $userRole) {
275  $notificationManager->createNotification(
276  $request, $userRole['id'], NOTIFICATION_TYPE_SUBMISSION_COMMENT,
277  $article->getJournalId(), ASSOC_TYPE_ARTICLE, $article->getId()
278  );
279  }
280 
281  if ($emailComment) {
282  $commentForm->email($commentForm->emailHelper(), $request);
283  }
284 
285  } else {
286  $commentForm->display();
287  }
288  }
289  }
290 
296  function deleteComment($commentId, $user = null) {
297  if ($user == null) $user =& Request::getUser();
298 
299  $articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
300  $comment =& $articleCommentDao->getArticleCommentById($commentId);
301 
302  if ($comment->getAuthorId() == $user->getId()) {
303  if (!HookRegistry::call('Action::deleteComment', array(&$comment))) {
304  $articleCommentDao->deleteArticleComment($comment);
305  }
306  }
307  }
308 }
309 
310 ?>
logEvent(&$request, &$article, $eventType, $messageKey, $params=array())
downloadFile($articleId, $fileId, $revision=null)
Definition: Action.inc.php:180
Form to change metadata information for a submission.
& getJournal()
Definition: Request.inc.php:42
viewMetadata($article, $journal)
Definition: Action.inc.php:59
Edit comment form.
saveComment($article, &$comment, $emailComment, $request)
Definition: Action.inc.php:260
Application-specific submission actions.
Definition: Action.inc.php:44
viewFile($articleId, $fileId, $revision=null)
Definition: Action.inc.php:192
editComment($article, $comment)
Definition: Action.inc.php:246
Application-independent submission actions.
& getDAO($name, $dbconn=null)
Class defining operations for article file management.
instructions($type, $allowed=array('copy', 'layout', 'proof', 'referenceLinking'))
Definition: Action.inc.php:202
call($hookName, $args=null)
Action()
Definition: Action.inc.php:48
saveMetadata($article, &$request)
Definition: Action.inc.php:77
deleteComment($commentId, $user=null)
Definition: Action.inc.php:296