You are here

public function views_handler_filter_fields_compare::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::query

File

handlers/views_handler_filter_fields_compare.inc, line 100
Definition of views_handler_filter_fields_compare.

Class

views_handler_filter_fields_compare
A handler to filter a view using fields comparison.

Code

public function query() {

  // Build extra condition from existing fields (from existing joins).
  $left = $this->options['left_field'];
  $right = $this->options['right_field'];

  // Get all existing field handlers.
  $field_handlers = $this->view->display_handler
    ->get_handlers('field');

  // Make sure the selected fields still exist.
  if (!isset($field_handlers[$left], $field_handlers[$right])) {
    return;
  }

  // Get the left table and field.
  $left_handler = $field_handlers[$left];
  $left_handler
    ->set_relationship();
  $left_table_alias = $this->query
    ->ensure_table($left_handler->table, $left_handler->relationship);

  // Get the left table and field.
  $right_handler = $field_handlers[$right];
  $right_handler
    ->set_relationship();
  $right_table_alias = $this->query
    ->ensure_table($right_handler->table, $right_handler->relationship);

  // Build piece of SQL.
  $snippet = $left_table_alias . '.' . $left_handler->real_field . ' ' . $this->options['operator'] . ' ' . $right_table_alias . '.' . $right_handler->real_field;
  $this->query
    ->add_where_expression($this->options['group'], $snippet);
}