/** * Return formatted notification data using Json. * @param $args array * @param $request Request * * @return JSONMessage */ function fetchNotification($args, &$request) { $this->setupTemplate(); $user =& $request->getUser(); $context =& $request->getContext(); $notificationDao =& DAORegistry::getDAO('NotificationDAO'); $notifications = array(); // Get the notification options from request. $notificationOptions = $request->getUserVar('requestOptions'); if (is_array($notificationOptions)) { // Retrieve the notifications. $notifications = $this->_getNotificationsByOptions($notificationOptions, $context->getId(), $user->getId()); } else { // No options, get only TRIVIAL notifications. $notifications =& $notificationDao->getByUserId($user->getId(), NOTIFICATION_LEVEL_TRIVIAL); $notifications =& $notifications->toArray(); } import('lib.pkp.classes.core.JSONMessage'); $json = new JSONMessage(); if (is_array($notifications) && !empty($notifications)) { $formattedNotificationsData = array(); $notificationManager = new NotificationManager(); // Format in place notifications. $formattedNotificationsData['inPlace'] = $notificationManager->formatToInPlaceNotification($request, $notifications); // Format general notifications. $formattedNotificationsData['general'] = $notificationManager->formatToGeneralNotification($request, $notifications); // Delete trivial notifications from database. $notificationManager->deleteTrivialNotifications($notifications); $json->setContent($formattedNotificationsData); } return $json->getString(); }