You are here

function opigno_statistics_app_query_most_active_users in Opigno Statistics App 7

Retrieve 10 most active users (sorted, cached for 1 day)

Output example: array( array( 'uid' => 1, 'last_visit' => 19955055 ), array( 'uid' => 10, 'last_visit' => 20292599 ), );

Return value

array

1 call to opigno_statistics_app_query_most_active_users()
opigno_statistics_app_present_most_active_users in includes/dashboard/presenters.inc
Present most active users

File

includes/dashboard/queries.inc, line 324

Code

function opigno_statistics_app_query_most_active_users() {
  $cache_key = __FUNCTION__;
  $cached_object = cache_get($cache_key);
  if ($cached_object) {
    $most_active_users = $cached_object->data;
  }
  else {
    $most_active_users = array();
    $result = db_query('
      SELECT accesslog.uid, MAX(accesslog.timestamp) as "last_visit", login_history.user_name
      FROM {accesslog}
      INNER JOIN {opigno_statistics_login_history} as login_history ON accesslog.uid = login_history.uid
      WHERE accesslog.uid <> 0
      GROUP BY accesslog.uid
      ORDER BY COUNT(*) DESC
      LIMIT 10');
    while ($record = $result
      ->fetchAssoc()) {
      $most_active_users[] = $record;
    }
    cache_set($cache_key, $most_active_users, 'cache', time() + 7200);

    // 7200s = 2h cache
  }
  return $most_active_users;
}