You are here

function advuser_filters in Advanced User 7.4

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.3 advuser.module \advuser_filters()

Returns a list of filter form elements for the user entity.

2 calls to advuser_filters()
advuser_form_user_filter_form_add in ./advuser.module
AJAX callback for "Add Filter".
advuser_query_advuser_FILTER_QUERY_alter in ./advuser.module
Implements hook_query_TAG_alter().

File

./advuser.module, line 10
advuser.module

Code

function advuser_filters() {
  $filters =& drupal_static(__FUNCTION__);
  if (empty($filters)) {
    $filters = array();

    // Get property and field info for user entity.
    $user_entity_info = entity_get_property_info('user');

    // Set the entity properties to expose.
    $user_properties = array_intersect(array_keys($user_entity_info['properties']), array(
      'uid',
      'name',
      'mail',
      'last_access',
      'last_login',
      'created',
    ));

    // Set property filters.
    foreach ($user_properties as $key) {
      $filters['propertyCondition'][$key] =& $user_entity_info['properties'][$key];
      $filters['propertyCondition'][$key] = array_merge($filters['propertyCondition'][$key], array(
        '#title' => $filters['propertyCondition'][$key]['label'],
      ));
    }

    // Set field filters.
    $form = array(
      '#parents' => array(
        'advuser',
      ),
    );
    $form_state = array();
    $filters['fieldCondition'] =& $user_entity_info['bundles']['user']['properties'];
    foreach ($filters['fieldCondition'] as $key => &$meta) {
      $field = field_info_field($key);
      $instance = field_info_instance('user', $key, 'user');
      $meta = field_default_form('user', NULL, $field, $instance, LANGUAGE_NONE, array(), $form, $form_state);
      if (!empty($meta[$key][$meta[$key]['#language']][0]['value'])) {
        $meta = $meta[$key][$meta[$key]['#language']][0]['value'];
      }
      else {
        $meta = $meta[$key][$meta[$key]['#language']];
      }
      $filters['fieldCondition'][$key] = $meta;
    }

    // Do some clean up on form elements.
    foreach ($filters as &$group) {
      foreach ($group as $key => &$meta) {
        foreach ($meta as $property => &$value) {
          if (!in_array($property, array(
            '#type',
            '#title',
            '#options',
            '#multiple',
            '#maxlength',
            '#weight',
            '#columns',
          ))) {
            unset($group[$key][$property]);
          }
        }
        $meta['#required'] = FALSE;
        $meta['#title'] = drupal_strtolower($meta['#title']);
        if (empty($meta['#type'])) {
          $meta['#type'] = 'textfield';
        }
        if ($meta['#type'] == 'textarea') {
          $meta['#type'] = 'textfield';
        }
        if (!empty($meta['#options']['_none'])) {
          $label = $meta['#options']['_none'];
          unset($meta['#options']['_none']);
          array_unshift($meta['#options'], $label);
        }
      }
    }
  }
  return $filters;
}