You are here

function advuser_filters in Advanced User 7.3

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

List advuser administration filters that can be applied.

7 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_data_display in forms/advuser_filter_ui.inc
Translate data values to the user based on field name.
_advuser_filter_ui_fields in forms/advuser_filter_ui.inc
Get a list of fields to select.
_advuser_filter_ui_operations in forms/advuser_filter_ui.inc
Get a list of operators based on field.

... See full list

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();
    foreach (module_implements('permission') as $module) {
      if ($permissions = module_invoke($module, 'permission')) {
        asort($permissions);
        foreach ($permissions as $permission => $pattr) {
          $options[t("@module module", array(
            '@module' => $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 rp.rid FROM {role_permission} rp WHERE rp.permission %op %permission_pkey))) %andor u.uid %eq 1)",
      'options' => $options,
      'form_type' => 'select',
    );
    $filters['status'] = array(
      'title' => t('Status'),
      'where' => "u.status %op %status_pkey",
      'options' => array(
        1 => t('active'),
        0 => t('blocked'),
      ),
      'form_type' => 'select',
    );
    $filters['created'] = array(
      'title' => t('Created'),
      'where' => "u.created %op %created_pkey",
      'form_type' => 'date',
    );
    $filters['last_access'] = array(
      'title' => t('Last Accessed'),
      'where' => "u.access %op %last_access_pkey",
      'form_type' => 'date',
    );
    $filters['email'] = array(
      'title' => t('Email'),
      'where' => "u.mail %op %email_pkey",
      'form_type' => 'textfield',
    );
    $filters['uid'] = array(
      'title' => t('User Id'),
      'where' => "u.uid %op %uid_pkey",
      'form_type' => 'id',
    );
    $filters['username'] = array(
      'title' => t('Username'),
      'where' => "u.name %op %username_pkey",
      'form_type' => 'textfield',
    );
    $roles = advuser_user_roles();
    if (count($roles)) {
      $filters['user_roles'] = array(
        'title' => t('Role'),
        'where' => "ur.rid %op %user_roles_pkey",
        '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 %{$field->name}_pkey AND {$pv}.uid = u.uid",
        'options' => $opts,
        'autocomplete' => $field->autocomplete ? $field->fid : FALSE,
      );
    }
    drupal_alter('advuser_filters', $filters);
  }
  return $filters;
}