You are here

function views_handler_filter_profile_andor in Views (for Drupal 7) 5

Custom filter for andor operator for serialized profile fields. Note: This sunstring matching method may not be the most elegant method, yet working, and anyone is free to point out a better approach to me..

1 string reference to 'views_handler_filter_profile_andor'
profile_views_add_filter in modules/views_profile.inc
Add profile filters to view table

File

modules/views_profile.inc, line 381

Code

function views_handler_filter_profile_andor($op, $filter, $filterinfo, &$query) {
  if (empty($filter['value'])) {
    return;
  }
  switch ($op) {
    case 'handler':
      $table = $filterinfo['table'];
      $column = $filterinfo['field'];
      if (empty($column)) {
        $fieldbits = explode('.', $filter['field']);
        $column = $fieldbits[1];
      }
      $field = "{$table}.{$column}";
      $query
        ->ensure_table($table);
      $where = array();
      $args = array();
      $operator = $filter['operator'] == 'NOR' ? 'NOT LIKE' : 'LIKE';

      // for 'force single' convert to array
      if (!is_array($filter['value'])) {
        $filter['value'] = array(
          $filter['value'],
        );
      }
      foreach ($filter['value'] as $value) {

        //$where[] = "%s $operator '%%\"%s\"%%'"; // use this line with modified version of profile.module
        $where[] = "%s {$operator} '%s'";

        // use this line with original version of profile.module
        $args[] = $field;
        $args[] = $value;
      }
      $operator = $filter['operator'] == 'NOR' ? 'AND' : $filter['operator'];
      $where = implode(" {$operator} ", $where);
      $query
        ->add_where("{$where}", $args);
      break;
  }
}