public static function OpignoNotification::getUnreadNotifications in Opigno notifications 3.x
Returns unread notifications list.
Parameters
\Drupal\user\UserInterface|null $account: User to get notifications for. Current user will be taken by default.
int $amount: The number of notifications to be loaded.
Return value
array Unread notifications list.
2 calls to OpignoNotification::getUnreadNotifications()
- OpignoNotificationController::markReadAll in src/
Controller/ OpignoNotificationController.php - Ajax callback. Marks all current user notifications as read.
- OpignoNotificationManager::getUserHeaderNotifications in src/
Services/ OpignoNotificationManager.php - Get user unread notifications (ILT + LM + standard ones).
File
- src/
Entity/ OpignoNotification.php, line 152
Class
- OpignoNotification
- Defines the opigno_notification entity.
Namespace
Drupal\opigno_notification\EntityCode
public static function getUnreadNotifications(UserInterface $account = NULL, int $amount = 0) : array {
if ($account === NULL) {
$account = \Drupal::currentUser();
}
// Get IDs of unread notifications.
$query = \Drupal::entityQuery('opigno_notification')
->condition('uid', (int) $account
->id())
->condition('has_read', FALSE)
->sort('created', 'DESC');
if ($amount) {
$query
->range(0, $amount);
}
$ids = $query
->execute();
// Load entities.
$notifications = [];
if (is_array($ids) && $ids) {
try {
$notifications = \Drupal::entityTypeManager()
->getStorage('opigno_notification')
->loadMultiple($ids);
} catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
watchdog_exception('opigno_notification_exception', $e);
}
}
return $notifications;
}