1 block.overview_user.inc DashboardOverviewUserBlock::getContent()

Return the content of a block.

Return value

mixed:

Overrides Block::getContent

File

core/modules/dashboard/includes/block.overview_user.inc, line 62
Dashboard block displaying information about user accounts, including:

Class

DashboardOverviewUserBlock
@file

Code

function getContent() {
  $settings = $this->settings;

  // User Overview.
  if ($settings['user_counts']) {
    $user_data['all'] = db_query("SELECT count(*) FROM {users}")->fetchField();
    // Account for UID 0. Faster than adding a where clause.
    $user_data['all']--;
  }
  if ($settings['user_counts_active']) {
    $user_data['active'] = db_query("SELECT count(*) FROM {users} WHERE status = 1 AND login <> 0")->fetchField();
  }
  if ($settings['user_counts_blocked']) {
    $user_data['blocked'] = db_query("SELECT count(*) FROM {users} WHERE status = 0")->fetchField();
    // Account for UID 0. Faster than adding a where clause.
    $user_data['blocked']--;
  }

  // Roles overview.
  $roles = user_roles(TRUE);
  $user_data['roles'] = array();
  foreach ($roles as $role_name => $role_label) {
    if (($role_name != BACKDROP_AUTHENTICATED_ROLE) && (in_array($role_name, $settings['roles']))) {
      $user_role_count = db_query("SELECT count(*) FROM {users} u INNER JOIN {users_roles} r on u.uid = r.uid WHERE r.role = :rid", array(':rid' => $role_name))->fetchField();
      $user_data['roles'][$role_name] = array();
      $user_data['roles'][$role_name]['name'] = t($role_label);
      $user_data['roles'][$role_name]['count'] = $user_role_count;
    }
  }

  // Assemble the overview from the collected data.
  $overview = array();
  if (isset($user_data['all'])) {
    $overview['all'] = format_plural($user_data['all'], '1 user account', '@count total user accounts');
  }
  if (isset($user_data['active'])) {
    $overview['active'] = format_plural($user_data['active'], '1 active user account', '@count active user accounts');
  }
  if (isset($user_data['blocked'])) {
    $overview['blocked'] = format_plural($user_data['blocked'], '1 blocked user account', '@count blocked user accounts');
  }
  foreach ($user_data['roles'] as $role_name => $data) {
    $overview['roles_' . $role_name] = format_plural(
    $user_data['roles'][$role_name]['count'], 
    '1 user account with the role @role', 
    '@count user accounts with the role @role', 
    array('@role' => $user_data['roles'][$role_name]['name'])
    );
  }

  $panel = array(
    '#theme' => 'dashboard_panel__overview_user',
  );
  $panel['list'] = array(
    '#theme' => 'item_list',
    '#items' => $overview,
  );
  if (user_access('administer users')) {
    $panel['link'] = array(
      '#theme' => 'link',
      '#path' => 'admin/people',
      '#text' => t('Manage user accounts'),
    );
  }

  return $panel;
}