You are here

function imagepicker_views_handler_filter_avail_roles::query in Image Picker 7

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides views_handler_filter::query

File

handlers/imagepicker_views_handler_filter_avail_roles.inc, line 30
@author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Class

imagepicker_views_handler_filter_avail_roles
@file @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function query() {
  if (imagepicker_variable_get('imagepicker_publicroles_enabled', 0)) {
    global $user;
    $this
      ->ensure_my_table();
    $field = $this->table_alias . '.' . $this->real_field;
    $roles = $user->roles;
    $rolesql = FALSE;
    if (count($roles)) {
      $ct = 0;
      foreach ($roles as $role) {
        $role = '%' . db_like($role) . '%';
        if (!$ct) {

          // first time
          $rolesql = db_or()
            ->condition($field, 'all', '=')
            ->condition($field, $role, 'LIKE');
        }
        else {
          $rolesql
            ->condition($field, $role, 'LIKE');
        }
        $ct++;
      }
    }
    if (is_object($rolesql)) {
      $this->query
        ->add_where($this->options['group'], $rolesql);
    }
  }
}