20 import(
'classes.notification.Notification');
21 import(
'lib.pkp.classes.notification.INotificationInfoProvider');
54 return __(
'notification.notification');
92 public function getFormattedNotificationsForUser($request, $userId, $level = NOTIFICATION_LEVEL_NORMAL, $contextId =
null, $rangeInfo =
null, $notificationTemplate =
'notification/notification.tpl') {
94 $notifications = $notificationDao->getByUserId($userId, $level,
null, $contextId, $rangeInfo);
96 return $this->formatNotifications($request, $notifications, $notificationTemplate);
111 $localizedParams = array();
112 foreach ($params as $name => $value) {
113 if (!is_array($value)) {
115 $localizedParams[$name] = $value;
116 } elseif (isset($value[$locale])) {
118 $localizedParams[$name] = $value[$locale];
119 } elseif (isset($value[$primaryLocale])) {
121 $localizedParams[$name] = $value[$primaryLocale];
125 foreach ($locales as $localeKey) {
126 if (isset($value[$localeKey])) {
127 $localizedParams[$name] = $value[$localeKey];
133 return $localizedParams;
150 public function createNotification($request, $userId =
null, $notificationType, $contextId =
null, $assocType =
null, $assocId =
null, $level = NOTIFICATION_LEVEL_NORMAL, $params =
null, $suppressEmail =
false, callable $mailConfigurator =
null) {
153 if (!in_array($notificationType, $blockedNotifications)) {
155 $notification = $notificationDao->newDataObject();
156 $notification->setUserId((
int) $userId);
157 $notification->setType((
int) $notificationType);
158 $notification->setContextId((
int) $contextId);
159 $notification->setAssocType((
int) $assocType);
160 $notification->setAssocId((
int) $assocId);
161 $notification->setLevel((
int) $level);
163 $notificationId = $notificationDao->insertObject($notification);
166 if ($notification->getLevel() != NOTIFICATION_LEVEL_TRIVIAL && !$suppressEmail) {
169 if (!in_array($notificationType, $notificationEmailSettings)) {
176 foreach ($params as $name => $value) {
177 $notificationSettingsDao->updateNotificationSetting($notificationId, $name, $value);
181 return $notification;
195 $notification = $notificationDao->newDataObject();
196 $notification->setUserId($userId);
197 $notification->setContextId(CONTEXT_ID_NONE);
198 $notification->setType($notificationType);
199 $notification->setLevel(NOTIFICATION_LEVEL_TRIVIAL);
201 $notificationId = $notificationDao->insertObject($notification);
205 foreach ($params as $name => $value) {
206 $notificationSettingsDao->updateNotificationSetting($notificationId, $name, $value);
210 return $notification;
219 foreach($notifications as $notification) {
221 if($notification->getLevel() == NOTIFICATION_LEVEL_TRIVIAL) {
222 $notificationDao->deleteById($notification->getId(), $notification->getUserId());
234 $formattedNotificationsData = array();
235 foreach ($notifications as $notification) {
236 $formattedNotificationsData[$notification->getLevel()][$notification->getId()] = array(
241 'styling' =>
'jqueryui',
245 return $formattedNotificationsData;
255 $formattedNotificationsData =
null;
257 if (!empty($notifications)) {
259 foreach ((array)$notifications as $notification) {
260 $formattedNotificationsData[$notification->getLevel()][$notification->getId()] = $this->formatNotification($request, $notification,
'controllers/notification/inPlaceNotificationContent.tpl');
264 return $formattedNotificationsData;
274 $notificationSubscriptionSettingsDao =
DAORegistry::getDAO(
'NotificationSubscriptionSettingsDAO');
275 return $notificationSubscriptionSettingsDao->getNotificationSubscriptionSettings(
'blocked_notification', $userId, (
int) $contextId);
283 $notificationSubscriptionSettingsDao =
DAORegistry::getDAO(
'NotificationSubscriptionSettingsDAO');
284 return $notificationSubscriptionSettingsDao->getNotificationSubscriptionSettings(
'blocked_emailed_notification', $userId, (
int) $contextId);
294 import(
'lib.pkp.classes.mail.MailTemplate');
306 $templateMgr->assign(
'linkAction', $linkAction);
307 return $templateMgr->fetch(
'controllers/notification/linkActionNotificationContent.tpl');
321 private function formatNotifications($request, $notifications, $notificationTemplate =
'notification/notification.tpl') {
322 $notificationString =
'';
325 while($notification = $notifications->next()) {
326 $notificationString .= $this->formatNotification($request, $notification, $notificationTemplate);
329 return $notificationString;
338 private function formatNotification($request, $notification, $notificationTemplate =
'notification/notification.tpl') {
342 if (!$notification->getDateRead()) {
345 $notification->setDateRead($dateRead);
348 $user = $request->getUser();
349 $templateMgr->assign(array(
350 'isUserLoggedIn' => $user,
351 'notificationDateCreated' => $notification->getDateCreated(),
352 'notificationId' => $notification->getId(),
353 'notificationContents' => $this->getNotificationContents($request, $notification),
354 'notificationTitle' => $this->getNotificationTitle($notification),
355 'notificationStyleClass' => $this->getStyleClass($notification),
356 'notificationIconClass' => $this->getIconClass($notification),
357 'notificationDateRead' => $notification->getDateRead(),
360 if($notification->getLevel() != NOTIFICATION_LEVEL_TRIVIAL) {
361 $templateMgr->assign(
'notificationUrl', $this->
getNotificationUrl($request, $notification));
364 return $templateMgr->fetch($notificationTemplate);
374 protected function sendNotificationEmail($request, $notification, ?
int $contextId, callable $mailConfigurator =
null) {
375 $userId = $notification->getUserId();
377 $user = $userDao->getById($userId);
378 if ($user && !$user->getDisabled()) {
381 $context = $request->getContext();
382 if ($contextId && (!$context || $context->getId() != $contextId)) {
384 $context = $contextDao->getById($contextId);
387 $site = $request->getSite();
391 $mail->setReplyTo($context->getContactEmail(), $context->getContactName());
393 $mail->setReplyTo($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
396 $mail->assignParams(array(
399 'siteTitle' => $context?$context->getLocalizedName():$site->getLocalizedTitle()
401 $mail->addRecipient($user->getEmail(), $user->getFullName());
402 if (is_callable($mailConfigurator)) {
403 $mail = $mailConfigurator($mail);
405 if (!$mail->send() && $request->getUser()) {
406 import(
'classes.notification.NotificationManager');
408 $notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array(
'contents' => __(
'email.compose.error')));