You are here

function admin_menu_session_count in Administration menu 8.3

Same name and namespace in other branches
  1. 7.3 admin_menu.module \admin_menu_session_count()

Counts how many users are active on the site.

Counts how many users have sessions which have been active since the specified time. Can count either anonymous sessions or authenticated sessions.

@todo There are mostly no anonymous sessions anymore. Split this into a separate module providing proper user statistics.

Parameters

$timestamp: A Unix timestamp. Users who have been active since this time will be counted. The default is 0, which counts all existing sessions.

$anonymous: TRUE counts only anonymous users. FALSE counts only authenticated users.

Return value

The number of users with sessions.

1 call to admin_menu_session_count()
admin_menu_get_user_count in ./admin_menu.module
Return count of online anonymous/authenticated users.

File

./admin_menu.module, line 432
Render an administrative menu as a dropdown menu at the top of the window.

Code

function admin_menu_session_count($timestamp = 0, $anonymous = TRUE) {

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  $query = \Drupal::database()
    ->select('sessions');
  $query
    ->addExpression('COUNT(sid)', 'count');
  $query
    ->condition('timestamp', $timestamp, '>=');
  $query
    ->condition('uid', 0, $anonymous ? '=' : '>');
  return $query
    ->execute()
    ->fetchField();
}