You are here

public function views_handler_filter_combine::query in Views (for Drupal 7) 7.3

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_string::query

File

handlers/views_handler_filter_combine.inc, line 62
Definition of views_handler_filter_combine.

Class

views_handler_filter_combine
Filter handler which allows to search on multiple fields.

Code

public function query() {
  $this->view
    ->_build('field');
  $fields = array();

  // Only add the fields if they have a proper field and table alias.
  foreach ($this->options['fields'] as $id) {

    // Field access checks may have removed this handler.
    if (!isset($this->view->field[$id])) {
      continue;
    }
    $field = $this->view->field[$id];

    // Always add the table of the selected fields to be sure a table alias
    // exists.
    $field
      ->ensure_my_table();
    if (!empty($field->table_alias) && !empty($field->real_field)) {
      $fields[] = "{$field->table_alias}.{$field->real_field}";
    }
  }
  if ($fields) {
    $count = count($fields);
    $separated_fields = array();
    foreach ($fields as $key => $field) {
      $separated_fields[] = $field;
      if ($key < $count - 1) {
        $separated_fields[] = "' '";
      }
    }
    $expression = implode(', ', $separated_fields);
    $expression = "CONCAT_WS(' ', {$expression})";
    $info = $this
      ->operators();
    if (!empty($info[$this->operator]['method'])) {
      $this
        ->{$info[$this->operator]['method']}($expression);
    }
  }
}