You are here

function opigno_statistics_user_login in Opigno statistics 3.x

Same name and namespace in other branches
  1. 8 opigno_statistics.module \opigno_statistics_user_login()

Implements hook_user_login().

2 string references to 'opigno_statistics_user_login'
DashboardForm::buildUsersPerDay in src/Form/DashboardForm.php
Builds active users per day graph.
opigno_statistics_install in ./opigno_statistics.install
Implements hook_install().

File

./opigno_statistics.module, line 189
Contains opigno_statistics.module.

Code

function opigno_statistics_user_login($account) {

  /** @var \Drupal\Core\Session\AccountInterface $account */
  $uid = $account
    ->id();
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $datetime = DrupalDateTime::createFromTimestamp($timestamp);
  $datetime_str = $datetime
    ->format(DrupalDateTime::FORMAT);

  // Store user login event to the database.
  \Drupal::database()
    ->insert('opigno_statistics_user_login')
    ->fields([
    'uid' => $uid,
    'date' => $datetime_str,
  ])
    ->execute();
}