You are here

function opigno_lrs_stats_dashboard_present_most_active_users in Opigno TinCan API 7

Retrieve most active users (max 10) from tincan statements

Output example: array( array('url' => 'user/toto4', 'name' => 'toto4', 'statement_count' => 123), array('url' => 'user/toto2', 'name' => 'toto2', 'statement_count' => 34), array('url' => 'user/toto1', 'name' => 'toto1', 'statement_count' => 23) )

Return value

array

1 call to opigno_lrs_stats_dashboard_present_most_active_users()
opigno_lrs_stats_dashboard_page in modules/opigno_tincan_api_stats/includes/dashboard/dashboard.pages.inc
Display general statistics page

File

modules/opigno_tincan_api_stats/includes/dashboard/model.inc, line 196
Dashboard model functions

Code

function opigno_lrs_stats_dashboard_present_most_active_users() {
  $users = array();
  $statements_per_user = opigno_lrs_stats_aggregate_statements_by_user(opigno_lrs_stats_all_statements());
  foreach ($statements_per_user as $user_statements) {
    $users[] = array(
      'url' => 'users/' . $user_statements[0]->actor->name,
      'username' => $user_statements[0]->actor->name,
      'statement_count' => count($user_statements),
    );
  }
  usort($users, function ($user_a, $user_b) {
    return $user_a['statement_count'] < $user_b['statement_count'];
  });
  $most_active_users = array_slice($users, 0, 10);
  return $most_active_users;
}