You are here

public function SessionLimit::getUserActiveSessionCount in Session Limit 8

Same name and namespace in other branches
  1. 2.x src/Services/SessionLimit.php \Drupal\session_limit\Services\SessionLimit::getUserActiveSessionCount()

Get the number of active sessions for a user.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user to check on.

Return value

int The total number of active sessions for the given user

1 call to SessionLimit::getUserActiveSessionCount()
SessionLimit::onKernelRequest in src/Services/SessionLimit.php
Event listener, on executing a Kernel request.

File

src/Services/SessionLimit.php, line 378

Class

SessionLimit

Namespace

Drupal\session_limit\Services

Code

public function getUserActiveSessionCount(AccountInterface $account) {
  $query = $this->database
    ->select('sessions', 's')
    ->distinct()
    ->fields('s', [
    'sid',
  ])
    ->condition('s.uid', $account
    ->id());
  if ($this
    ->getMasqueradeIgnore()) {

    // Masquerading sessions do not count.
    $like = '%' . $this->database
      ->escapeLike('masquerading') . '%';
    $query
      ->condition('s.session', $like, 'NOT LIKE');
  }

  /** @var \Drupal\Core\Database\Query\Select $query */
  return $query
    ->countQuery()
    ->execute()
    ->fetchField();
}