Open Journal Systems  3.3.0
PKPNotificationManager.inc.php
1 <?php
2 
17 import('lib.pkp.classes.notification.PKPNotificationOperationManager');
18 import('lib.pkp.classes.workflow.WorkflowStageDAO');
19 
21 
26  public function getNotificationUrl($request, $notification) {
27  $url = parent::getNotificationUrl($request, $notification);
28  $dispatcher = Application::get()->getDispatcher();
29  $contextDao = Application::getContextDAO();
30  $context = $contextDao->getById($notification->getContextId());
31 
32  switch ($notification->getType()) {
33  case NOTIFICATION_TYPE_EDITOR_ASSIGN:
34  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
35  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'workflow', 'access', $notification->getAssocId());
36  case NOTIFICATION_TYPE_COPYEDIT_ASSIGNMENT:
37  case NOTIFICATION_TYPE_LAYOUT_ASSIGNMENT:
38  case NOTIFICATION_TYPE_INDEX_ASSIGNMENT:
39  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
40  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'workflow', 'access', $notification->getAssocId());
41  case NOTIFICATION_TYPE_REVIEWER_COMMENT:
42  assert($notification->getAssocType() == ASSOC_TYPE_REVIEW_ASSIGNMENT && is_numeric($notification->getAssocId()));
43  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
44  $reviewAssignment = $reviewAssignmentDao->getById($notification->getAssocId());
45  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
46  $operation = $reviewAssignment->getStageId()==WORKFLOW_STAGE_ID_INTERNAL_REVIEW?WORKFLOW_STAGE_PATH_INTERNAL_REVIEW:WORKFLOW_STAGE_PATH_EXTERNAL_REVIEW;
47  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'workflow', $operation, $reviewAssignment->getSubmissionId());
48  case NOTIFICATION_TYPE_REVIEW_ASSIGNMENT:
49  case NOTIFICATION_TYPE_REVIEW_ASSIGNMENT_UPDATED:
50  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
51  $reviewAssignment = $reviewAssignmentDao->getById($notification->getAssocId());
52  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'reviewer', 'submission', $reviewAssignment->getSubmissionId());
53  case NOTIFICATION_TYPE_NEW_ANNOUNCEMENT:
54  assert($notification->getAssocType() == ASSOC_TYPE_ANNOUNCEMENT);
55  $announcementDao = DAORegistry::getDAO('AnnouncementDAO'); /* @var $announcementDao AnnouncementDAO */
56  $announcement = $announcementDao->getById($notification->getAssocId()); /* @var $announcement Announcement */
57  $context = $contextDao->getById($announcement->getAssocId());
58  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'announcement', 'view', array($notification->getAssocId()));
59  case NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD:
60  return __('notification.type.configurePaymentMethod');
61  case NOTIFICATION_TYPE_PAYMENT_REQUIRED:
62  $context = $contextDao->getById($notification->getContextId());
64  assert($notification->getAssocType() == ASSOC_TYPE_QUEUED_PAYMENT);
65  $queuedPaymentDao = DAORegistry::getDAO('QueuedPaymentDAO'); /* @var $queuedPaymentDao QueuedPaymentDAO */
66  $queuedPayment = $queuedPaymentDao->getById($notification->getAssocId());
67  $context = $contextDao->getById($queuedPayment->getContextId());
68  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'payment', 'pay', array($queuedPayment->getId()));
69  default:
70  $delegateResult = $this->getByDelegate(
71  $notification->getType(),
72  $notification->getAssocType(),
73  $notification->getAssocId(),
74  __FUNCTION__,
75  array($request, $notification)
76  );
77 
78  if ($delegateResult) $url = $delegateResult;
79 
80  return $url;
81  }
82  }
83 
89  public function getNotificationMessage($request, $notification) {
90  $message = parent::getNotificationMessage($request, $notification);
91  $type = $notification->getType();
92  assert(isset($type));
93  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
94 
95  switch ($type) {
96  case NOTIFICATION_TYPE_SUCCESS:
97  case NOTIFICATION_TYPE_ERROR:
98  case NOTIFICATION_TYPE_WARNING:
99  if (!is_null($this->getNotificationSettings($notification->getId()))) {
100  $notificationSettings = $this->getNotificationSettings($notification->getId());
101  return $notificationSettings['contents'];
102  } else {
103  return __('common.changesSaved');
104  }
105  case NOTIFICATION_TYPE_FORM_ERROR:
106  case NOTIFICATION_TYPE_ERROR:
107  $notificationSettings = $this->getNotificationSettings($notification->getId());
108  assert(!is_null($notificationSettings['contents']));
109  return $notificationSettings['contents'];
110  case NOTIFICATION_TYPE_PLUGIN_ENABLED:
111  return $this->_getTranslatedKeyWithParameters('common.pluginEnabled', $notification->getId());
112  case NOTIFICATION_TYPE_PLUGIN_DISABLED:
113  return $this->_getTranslatedKeyWithParameters('common.pluginDisabled', $notification->getId());
114  case NOTIFICATION_TYPE_REVIEWER_COMMENT:
115  assert($notification->getAssocType() == ASSOC_TYPE_REVIEW_ASSIGNMENT && is_numeric($notification->getAssocId()));
116  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
117  $reviewAssignment = $reviewAssignmentDao->getById($notification->getAssocId());
118  $submission = $submissionDao->getById($reviewAssignment->getSubmissionId()); /* @var $submission Submission */
119  return __('notification.type.reviewerComment', array('title' => $submission->getLocalizedTitle()));
120  case NOTIFICATION_TYPE_EDITOR_ASSIGN:
121  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
122  $submission = $submissionDao->getById($notification->getAssocId());
123  return __('notification.type.editorAssign', array('title' => $submission->getLocalizedTitle()));
124  case NOTIFICATION_TYPE_COPYEDIT_ASSIGNMENT:
125  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
126  $submission = $submissionDao->getById($notification->getAssocId());
127  return __('notification.type.copyeditorRequest', array('title' => $submission->getLocalizedTitle()));
128  case NOTIFICATION_TYPE_LAYOUT_ASSIGNMENT:
129  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
130  $submission = $submissionDao->getById($notification->getAssocId());
131  return __('notification.type.layouteditorRequest', array('title' => $submission->getLocalizedTitle()));
132  case NOTIFICATION_TYPE_INDEX_ASSIGNMENT:
133  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
134  $submission = $submissionDao->getById($notification->getAssocId());
135  return __('notification.type.indexRequest', array('title' => $submission->getLocalizedTitle()));
136  case NOTIFICATION_TYPE_REVIEW_ASSIGNMENT:
137  return __('notification.type.reviewAssignment');
138  case NOTIFICATION_TYPE_REVIEW_ASSIGNMENT_UPDATED:
139  return __('notification.type.reviewAssignmentUpdated');
140  case NOTIFICATION_TYPE_REVIEW_ROUND_STATUS:
141  assert($notification->getAssocType() == ASSOC_TYPE_REVIEW_ROUND && is_numeric($notification->getAssocId()));
142  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
143  $reviewRound = $reviewRoundDao->getById($notification->getAssocId());
144  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
145 
146  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR); // load review round status keys.
147  $user = $request->getUser();
148  $stageAssignments = $stageAssignmentDao->getBySubmissionAndRoleId($reviewRound->getSubmissionId(), ROLE_ID_AUTHOR, null, $user->getId());
149  $isAuthor = $stageAssignments->getCount()>0;
150  $stageAssignments->close();
151  return __($reviewRound->getStatusKey($isAuthor));
152  case NOTIFICATION_TYPE_PAYMENT_REQUIRED:
153  return __('payment.type.publication.required');
154  case NOTIFICATION_TYPE_EDITORIAL_REPORT:
155  $notificationSettings = $this->getNotificationSettings($notification->getId());
156  return $notificationSettings['contents'];
157  default:
158  $delegateResult = $this->getByDelegate(
159  $notification->getType(),
160  $notification->getAssocType(),
161  $notification->getAssocId(),
162  __FUNCTION__,
163  array($request, $notification)
164  );
165 
166  if ($delegateResult) $message = $delegateResult;
167 
168  return $message;
169  }
170  }
171 
181  public function getNotificationContents($request, $notification) {
182  $content = parent::getNotificationContents($request, $notification);
183  $type = $notification->getType();
184  assert(isset($type));
185 
186  switch ($type) {
187  case NOTIFICATION_TYPE_FORM_ERROR:
188  $templateMgr = TemplateManager::getManager($request);
189  $templateMgr->assign('errors', $content);
190  return $templateMgr->fetch('controllers/notification/formErrorNotificationContent.tpl');
191  case NOTIFICATION_TYPE_ERROR:
192  if (is_array($content)) {
193  $templateMgr->assign('errors', $content);
194  return $templateMgr->fetch('controllers/notification/errorNotificationContent.tpl');
195  } else {
196  return $content;
197  }
198  default:
199  $delegateResult = $this->getByDelegate(
200  $notification->getType(),
201  $notification->getAssocType(),
202  $notification->getAssocId(),
203  __FUNCTION__,
204  array($request, $notification)
205  );
206 
207  if ($delegateResult) $content = $delegateResult;
208  return $content;
209  }
210  }
211 
215  public function getNotificationTitle($notification) {
216  $title = parent::getNotificationTitle($notification);
217  $type = $notification->getType();
218  assert(isset($type));
219 
220  switch ($type) {
221  case NOTIFICATION_TYPE_REVIEW_ROUND_STATUS:
222  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
223  $reviewRound = $reviewRoundDao->getById($notification->getAssocId());
224  return __('notification.type.roundStatusTitle', array('round' => $reviewRound->getRound()));
225  case NOTIFICATION_TYPE_FORM_ERROR:
226  return __('form.errorsOccurred');
227  default:
228  $delegateResult = $this->getByDelegate(
229  $notification->getType(),
230  $notification->getAssocType(),
231  $notification->getAssocId(),
232  __FUNCTION__,
233  array($notification)
234  );
235 
236  if ($delegateResult) $title = $delegateResult;
237  return $title;
238  }
239  }
240 
244  public function getStyleClass($notification) {
245  $styleClass = parent::getStyleClass($notification);
246  switch ($notification->getType()) {
247  case NOTIFICATION_TYPE_SUCCESS: return NOTIFICATION_STYLE_CLASS_SUCCESS;
248  case NOTIFICATION_TYPE_WARNING: return NOTIFICATION_STYLE_CLASS_WARNING;
249  case NOTIFICATION_TYPE_ERROR: return NOTIFICATION_STYLE_CLASS_ERROR;
250  case NOTIFICATION_TYPE_INFORMATION: return NOTIFICATION_STYLE_CLASS_INFORMATION;
251  case NOTIFICATION_TYPE_FORBIDDEN: return NOTIFICATION_STYLE_CLASS_FORBIDDEN;
252  case NOTIFICATION_TYPE_HELP: return NOTIFICATION_STYLE_CLASS_HELP;
253  case NOTIFICATION_TYPE_FORM_ERROR: return NOTIFICATION_STYLE_CLASS_FORM_ERROR;
254  case NOTIFICATION_TYPE_REVIEW_ROUND_STATUS: return NOTIFICATION_STYLE_CLASS_INFORMATION;
255  default:
256  $delegateResult = $this->getByDelegate(
257  $notification->getType(),
258  $notification->getAssocType(),
259  $notification->getAssocId(),
260  __FUNCTION__,
261  array($notification)
262  );
263  if ($delegateResult) $styleClass = $delegateResult;
264  return $styleClass;
265  }
266  }
267 
271  public function getIconClass($notification) {
272  $iconClass = parent::getIconClass($notification);
273  switch ($notification->getType()) {
274  case NOTIFICATION_TYPE_SUCCESS: return 'notifyIconSuccess';
275  case NOTIFICATION_TYPE_WARNING: return 'notifyIconWarning';
276  case NOTIFICATION_TYPE_ERROR: return 'notifyIconError';
277  case NOTIFICATION_TYPE_INFORMATION: return 'notifyIconInfo';
278  case NOTIFICATION_TYPE_FORBIDDEN: return 'notifyIconForbidden';
279  case NOTIFICATION_TYPE_HELP: return 'notifyIconHelp';
280  default:
281  $delegateResult = $this->getByDelegate(
282  $notification->getType(),
283  $notification->getAssocType(),
284  $notification->getAssocId(),
285  __FUNCTION__,
286  array($notification)
287  );
288  if ($delegateResult) $iconClass = $delegateResult;
289  return $iconClass;
290  }
291  }
292 
296  public function isVisibleToAllUsers($notificationType, $assocType, $assocId) {
297  $isVisible = parent::isVisibleToAllUsers($notificationType, $assocType, $assocId);
298  switch ($notificationType) {
299  case NOTIFICATION_TYPE_REVIEW_ROUND_STATUS:
300  case NOTIFICATION_TYPE_APPROVE_SUBMISSION:
301  case NOTIFICATION_TYPE_VISIT_CATALOG:
302  case NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD:
303  $isVisible = true;
304  break;
305  case NOTIFICATION_TYPE_PAYMENT_REQUIRED:
306  $isVisible = false;
307  break;
308  default:
309  $delegateResult = $this->getByDelegate(
310  $notificationType,
311  $assocType,
312  $assocId,
313  __FUNCTION__,
314  array($notificationType, $assocType, $assocId)
315  );
316  if (!is_null($delegateResult)) $isVisible = $delegateResult;
317  break;
318  }
319  return $isVisible;
320  }
321 
335  final public function updateNotification($request, $notificationTypes, $userIds, $assocType, $assocId) {
336  $returner = false;
337  foreach ($notificationTypes as $type) {
338  $managerDelegate = $this->getMgrDelegate($type, $assocType, $assocId);
339  if (!is_null($managerDelegate) && is_a($managerDelegate, 'NotificationManagerDelegate')) {
340  $returner = $managerDelegate->updateNotification($request, $userIds, $assocType, $assocId);
341  } else {
342  assert(false);
343  }
344  }
345 
346  return $returner;
347  }
348 
349 
350  //
351  // Protected methods
352  //
360  protected function getMgrDelegate($notificationType, $assocType, $assocId) {
361  switch ($notificationType) {
362  case NOTIFICATION_TYPE_SUBMISSION_SUBMITTED:
363  case NOTIFICATION_TYPE_METADATA_MODIFIED:
364  case NOTIFICATION_TYPE_SUBMISSION_NEW_VERSION:
365  case NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_REQUIRED:
366  assert($assocType == ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
367  import('lib.pkp.classes.notification.managerDelegate.SubmissionNotificationManager');
368  return new SubmissionNotificationManager($notificationType);
369  case NOTIFICATION_TYPE_NEW_QUERY:
370  case NOTIFICATION_TYPE_QUERY_ACTIVITY:
371  import('lib.pkp.classes.notification.managerDelegate.QueryNotificationManager');
372  return new QueryNotificationManager($notificationType);
373  case NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_SUBMISSION:
374  case NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EXTERNAL_REVIEW:
375  case NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_EDITING:
376  case NOTIFICATION_TYPE_EDITOR_ASSIGNMENT_PRODUCTION:
377  assert($assocType == ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
378  import('lib.pkp.classes.notification.managerDelegate.EditorAssignmentNotificationManager');
379  return new EditorAssignmentNotificationManager($notificationType);
380  case NOTIFICATION_TYPE_EDITOR_DECISION_ACCEPT:
381  case NOTIFICATION_TYPE_EDITOR_DECISION_EXTERNAL_REVIEW:
382  case NOTIFICATION_TYPE_EDITOR_DECISION_PENDING_REVISIONS:
383  case NOTIFICATION_TYPE_EDITOR_DECISION_RESUBMIT:
384  case NOTIFICATION_TYPE_EDITOR_DECISION_NEW_ROUND:
385  case NOTIFICATION_TYPE_EDITOR_DECISION_DECLINE:
386  case NOTIFICATION_TYPE_EDITOR_DECISION_SEND_TO_PRODUCTION:
387  assert($assocType == ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
388  import('lib.pkp.classes.notification.managerDelegate.EditorDecisionNotificationManager');
389  return new EditorDecisionNotificationManager($notificationType);
390  case NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS:
391  case NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS:
392  assert($assocType == ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
393  import('lib.pkp.classes.notification.managerDelegate.PendingRevisionsNotificationManager');
394  return new PendingRevisionsNotificationManager($notificationType);
395  case NOTIFICATION_TYPE_ASSIGN_COPYEDITOR:
396  case NOTIFICATION_TYPE_AWAITING_COPYEDITS:
397  case NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER:
398  case NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS:
399  assert($assocType == ASSOC_TYPE_SUBMISSION && is_numeric($assocId));
400  import('lib.pkp.classes.notification.managerDelegate.PKPEditingProductionStatusNotificationManager');
401  return new PKPEditingProductionStatusNotificationManager($notificationType);
402  case NOTIFICATION_TYPE_EDITORIAL_REPORT:
403  import('lib.pkp.classes.notification.managerDelegate.EditorialReportNotificationManager');
404  return new EditorialReportNotificationManager($notificationType);
405  }
406  return null; // No delegate required, let calling context handle null.
407  }
408 
416  protected function getByDelegate($notificationType, $assocType, $assocId, $operationName, $parameters) {
417  $delegate = $this->getMgrDelegate($notificationType, $assocType, $assocId);
418  if (is_a($delegate, 'NotificationManagerDelegate')) {
419  return call_user_func_array(array($delegate, $operationName), $parameters);
420  } else {
421  return null;
422  }
423  }
424 
425 
426  //
427  // Private helper methods.
428  //
434  private function getNotificationSettings($notificationId) {
435  $notificationSettingsDao = DAORegistry::getDAO('NotificationSettingsDAO'); /* @var $notificationSettingsDao NotificationSettingsDAO */
436  $notificationSettings = $notificationSettingsDao->getNotificationSettings($notificationId);
437  if (empty($notificationSettings)) {
438  return null;
439  } else {
440  return $notificationSettings;
441  }
442  }
443 
450  private function _getTranslatedKeyWithParameters($key, $notificationId) {
451  $params = $this->getNotificationSettings($notificationId);
452  return __($key, $this->getParamsForCurrentLocale($params));
453  }
454 }
455 
PKPNotificationManager\getStyleClass
getStyleClass($notification)
Definition: PKPNotificationManager.inc.php:244
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:137
PKPNotificationManager\getNotificationTitle
getNotificationTitle($notification)
Definition: PKPNotificationManager.inc.php:215
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPNotificationManager\getNotificationMessage
getNotificationMessage($request, $notification)
Definition: PKPNotificationManager.inc.php:89
PKPNotificationOperationManager
Base class for notification manager that implements basic notification operations and default notific...
Definition: PKPNotificationOperationManager.inc.php:23
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
QueryNotificationManager
Query notification types manager delegate.
Definition: QueryNotificationManager.inc.php:18
Application\getPaymentManager
static getPaymentManager($context)
Definition: Application.inc.php:226
PKPNotificationManager\getNotificationContents
getNotificationContents($request, $notification)
Definition: PKPNotificationManager.inc.php:181
PKPNotificationManager\updateNotification
updateNotification($request, $notificationTypes, $userIds, $assocType, $assocId)
Definition: PKPNotificationManager.inc.php:335
PKPNotificationManager
Class for Notification Manager.
Definition: PKPNotificationManager.inc.php:20
EditorDecisionNotificationManager
Editor decision notification types manager delegate.
Definition: EditorDecisionNotificationManager.inc.php:18
PKPNotificationManager\getMgrDelegate
getMgrDelegate($notificationType, $assocType, $assocId)
Definition: PKPNotificationManager.inc.php:360
EditorialReportNotificationManager
Editorial report notification manager.
Definition: EditorialReportNotificationManager.inc.php:17
PKPNotificationManager\getByDelegate
getByDelegate($notificationType, $assocType, $assocId, $operationName, $parameters)
Definition: PKPNotificationManager.inc.php:416
PKPEditingProductionStatusNotificationManager
Editing and productionstatus notifications types manager delegate.
Definition: PKPEditingProductionStatusNotificationManager.inc.php:18
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
SubmissionNotificationManager
Submission notification types manager delegate.
Definition: SubmissionNotificationManager.inc.php:18
PKPNotificationManager\getIconClass
getIconClass($notification)
Definition: PKPNotificationManager.inc.php:271
EditorAssignmentNotificationManager
Editor assignment notification types manager delegate.
Definition: EditorAssignmentNotificationManager.inc.php:18
PKPNotificationOperationManager\getParamsForCurrentLocale
getParamsForCurrentLocale($params)
Definition: PKPNotificationOperationManager.inc.php:107
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PendingRevisionsNotificationManager
Pending revision notification types manager delegate.
Definition: PendingRevisionsNotificationManager.inc.php:19
PKPNotificationManager\isVisibleToAllUsers
isVisibleToAllUsers($notificationType, $assocType, $assocId)
Definition: PKPNotificationManager.inc.php:296
PKPNotificationManager\getNotificationUrl
getNotificationUrl($request, $notification)
Definition: PKPNotificationManager.inc.php:26