public function OpignoNotificationController::markReadAll in Opigno notifications 8
Same name and namespace in other branches
- 3.x src/Controller/OpignoNotificationController.php \Drupal\opigno_notification\Controller\OpignoNotificationController::markReadAll()
Ajax callback. Marks all current user notifications as read.
1 string reference to 'OpignoNotificationController::markReadAll'
File
- src/
Controller/ OpignoNotificationController.php, line 54
Class
- OpignoNotificationController
- Provides the controller for OpignoNotification entity pages.
Namespace
Drupal\opigno_notification\ControllerCode
public function markReadAll() {
$uid = \Drupal::currentUser()
->id();
$query = \Drupal::entityQuery('opigno_notification');
$query
->condition('uid', $uid);
$query
->condition('has_read', FALSE);
$ids = $query
->execute();
/* @var OpignoNotificationInterface[] $notifications */
$notifications = OpignoNotification::loadMultiple($ids);
foreach ($notifications as $notification) {
$notification
->setHasRead(TRUE);
$notification
->save();
}
return new JsonResponse([]);
}