You are here

public function OpignoNotificationController::markReadAll in Opigno notifications 8

Same name and namespace in other branches
  1. 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'
opigno_notification.routing.yml in ./opigno_notification.routing.yml
opigno_notification.routing.yml

File

src/Controller/OpignoNotificationController.php, line 54

Class

OpignoNotificationController
Provides the controller for OpignoNotification entity pages.

Namespace

Drupal\opigno_notification\Controller

Code

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([]);
}