You are here

public static function OpignoNotification::unreadCount in Opigno notifications 3.x

Same name and namespace in other branches
  1. 8 src/Entity/OpignoNotification.php \Drupal\opigno_notification\Entity\OpignoNotification::unreadCount()

Returns unread notifications count.

Parameters

\Drupal\user\Entity\User|null $account: User for which notifications will be counted. Current user if not specified.

Return value

int Unread notifications count.

File

src/Entity/OpignoNotification.php, line 127

Class

OpignoNotification
Defines the opigno_notification entity.

Namespace

Drupal\opigno_notification\Entity

Code

public static function unreadCount($account = NULL) {
  if ($account === NULL) {
    $account = \Drupal::currentUser();
  }
  $query = \Drupal::entityQuery('opigno_notification');
  $query
    ->condition('uid', $account
    ->id());
  $query
    ->condition('has_read', FALSE);
  $query
    ->count();
  $result = $query
    ->execute();
  return (int) $result;
}