1 user.module user_build_filter_query(SelectQuery $query)

Extends a query object for user administration filters based on session.

Parameters

$query: Query object that should be filtered.

File

core/modules/user/user.module, line 2715
Enables the user registration and login system.

Code

function user_build_filter_query(SelectQuery $query) {
  $filters = user_filters();
  // Extend Query with filter conditions.
  foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) {
    list($key, $value) = $filter;
    // This checks to see if this permission filter is an enabled permission for
    // the authenticated role. If so, then all users would be listed, and we can
    // skip adding it to the filter query.
    if ($key == 'permission') {
      $account = entity_create('user', array());
      $account->uid = 'user_filter';
      $account->roles = array(BACKDROP_AUTHENTICATED_ROLE);
      if (user_access($value, $account)) {
        continue;
      }
      $role_list = array();
      $user_roles = user_roles(FALSE, NULL, TRUE);
      foreach ($user_roles as $user_role) {
        if (in_array($value, $user_role->permissions)) {
          $role_list[] = $user_role->name;
        }
      }
      $users_roles_alias = $query->join('users_roles', 'ur', '%alias.uid = u.uid');
      $query->condition($users_roles_alias . '.role', $role_list);
    }
    elseif ($key == 'role') {
      $users_roles_alias = $query->join('users_roles', 'ur', '%alias.uid = u.uid');
      $query->condition($users_roles_alias . '.role', $value);
    }
    else {
      $query->condition($filters[$key]['field'], $value);
    }
  }
}