NotificationManager::getNotificationUrl PHP Method

getNotificationUrl() public method

Construct a URL for the notification based on its type and associated object
public getNotificationUrl ( $request, $notification ) : string
$request PKPRequest
$notification Notification
return string
    function getNotificationUrl($request, $notification)
    {
        $router = $request->getRouter();
        $dispatcher = $router->getDispatcher();
        $contextDao = Application::getContextDAO();
        $context = $contextDao->getById($notification->getContextId());
        switch ($notification->getType()) {
            case NOTIFICATION_TYPE_PUBLISHED_ISSUE:
                return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'issue', 'current');
            default:
                return parent::getNotificationUrl($request, $notification);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Mark notifications unread
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON object
  */
 function markRead($args, $request)
 {
     $notificationDao = DAORegistry::getDAO('NotificationDAO');
     $user = $request->getUser();
     $selectedElements = (array) $request->getUserVar('selectedElements');
     foreach ($selectedElements as $notificationId) {
         if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
             $notificationDao->setDateRead($notificationId, Core::getCurrentDate());
         }
     }
     if ($request->getUserVar('redirect')) {
         // In this case, the user has clicked on a notification
         // and wants to view it. Mark it read first and redirect
         $notificationMgr = new NotificationManager();
         return $request->redirectUrlJson($notificationMgr->getNotificationUrl($request, $notification));
     } else {
         // The notification has been marked read explicitly.
         // Update its status in the grid.
         return DAO::getDataChangedEvent(null, null, $selectedElements);
     }
 }