/**
* 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);
}
}