You are here

function advuser_filters in Advanced User 6.3

Same name and namespace in other branches
  1. 5.2 advuser_filters.inc \advuser_filters()
  2. 6.2 advuser_filters.inc \advuser_filters()
  3. 7.4 advuser.module \advuser_filters()
  4. 7.3 advuser.module \advuser_filters()

List advuser administration filters that can be applied.

3 calls to advuser_filters()
advuser_build_filter_query in ./advuser.module
Build query for advuser administration filters based on session.
advuser_filter_ui in forms/advuser_filter_ui.inc
The phase controller.
_advuser_filter_ui_fields in forms/advuser_filter_ui.inc
Get a list of fields to select.

File

./advuser.module, line 664
Advanced user module allows you to select users based on an advanced set of filtering and apply actions to block, unblock, delete or email the selected users.

Code

function advuser_filters() {

  // Regular filters
  static $filters = array();
  if (empty($filters)) {
    $options = array();
    $t_module = t('module');
    foreach (module_list() as $module) {
      if ($permissions = module_invoke($module, 'perm')) {
        asort($permissions);
        foreach ($permissions as $permission) {
          $options["{$module} {$t_module}"][$permission] = t($permission);
        }
      }
    }
    ksort($options);
    $filters['permission'] = array(
      'title' => t('Permission'),
      'where' => " ((u.uid %in (SELECT ur.uid FROM {users_roles} ur WHERE ur.rid %in (SELECT p.rid FROM {permission} p WHERE p.perm %op '%s'))) %andor u.uid %eq 1)",
      'options' => $options,
      'form_type' => 'select',
    );
    $filters['status'] = array(
      'title' => t('Status'),
      'where' => "u.status %op '%s'",
      'options' => array(
        1 => t('active'),
        0 => t('blocked'),
      ),
      'form_type' => 'select',
    );
    $filters['created'] = array(
      'title' => t('Created'),
      'where' => "u.created %op %d",
      'form_type' => 'date',
    );
    $filters['last_access'] = array(
      'title' => t('Last Accessed'),
      'where' => "u.access %op %d",
      'form_type' => 'date',
    );
    $filters['email'] = array(
      'title' => t('Email'),
      'where' => "u.mail %op '%s'",
      'form_type' => 'textfield',
    );
    $filters['uid'] = array(
      'title' => t('User Id'),
      'where' => "u.uid %op %d",
      'form_type' => 'id',
    );
    $filters['username'] = array(
      'title' => t('Username'),
      'where' => "u.name %op '%s'",
      'form_type' => 'textfield',
    );
    $roles = advuser_user_roles();
    if (count($roles)) {
      $filters['user_roles'] = array(
        'title' => t('Role'),
        'where' => "ur.rid %op %s",
        'form_type' => 'select',
        'options' => $roles,
      );
    }
    $profile_fields = advuser_profile_fields();
    foreach ($profile_fields as $field) {

      // Build array of options if they exist
      $opts = NULL;
      if (!empty($field->options)) {
        $opts = array();
        foreach (explode("\n", $field->options) as $opt) {
          $opt = trim($opt);
          $opts[$opt] = $opt;
        }
      }

      // Each user defined profile field needs a unique table identifier for the
      //  JOIN and WHERE clauses.
      // TODO: Make sure the $field->name contains valid information for a table
      //  identifier.  This comment is to identify the source of a problem yet
      //  to be discovered.
      $pv = $field->name;
      $filters[$field->name] = array(
        'title' => check_plain($field->title),
        'type' => $field->type,
        'class' => $field->name,
        'where' => "{$pv}.value %op '%s' AND {$pv}.uid = u.uid",
        'options' => $opts,
        'autocomplete' => $field->autocomplete ? $field->fid : FALSE,
      );
    }
  }
  return $filters;
}