diff --git a/handlers/views_handler_filter_string.inc b/handlers/views_handler_filter_string.inc index c50eff4..085bc0c 100644 --- a/handlers/views_handler_filter_string.inc +++ b/handlers/views_handler_filter_string.inc @@ -19,6 +19,10 @@ class views_handler_filter_string extends views_handler_filter { $options = parent::option_definition(); $options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE); + $options['op_location'] = array( + 'default' => 'WHERE', + 'export' => 'export_plugin', + ); return $options; } @@ -134,6 +138,21 @@ class views_handler_filter_string extends views_handler_filter { return $operators; } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['op_location'] = array( + '#type' => 'select', + '#required' => FALSE, + '#title' => t('Condition Location'), + '#description' => t('Advanced: Apply condition in WHERE clause, or in JOIN ON clause of RIGHT field table.'), + '#options' => array( + 'where' => 'WHERE', + 'on' => 'ON', + ), + '#default_value' => $this->options['op_location'], + ); + } /** * Build strings from the operators() for 'select' options @@ -250,11 +269,38 @@ class views_handler_filter_string extends views_handler_filter { } function op_equal($field) { - $this->query->add_where($this->options['group'], $field, $this->value, $this->operator()); + switch (strtolower($this->options['op_location'])) { + case 'on': + $this->query->table_queue[$this->table_alias]['join']->extra[] = array( + 'field' => $this->real_field, + 'operator' => $this->options['operator'], + 'value' => $this->value, + ); + break; + case 'where': + default: + // Build piece of SQL. + $this->query->add_where($this->options['group'], $field, $this->value, $this->operator()); + break; + } } function op_contains($field) { - $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE'); + switch (strtolower($this->options['op_location'])) { + case 'on': + $this->query->table_queue[$this->table_alias]['join']->extra[] = array( + 'field' => $this->real_field, + 'operator' => 'LIKE', + 'value' => '%' . db_like($this->value) . '%', + ); + break; + case 'where': + default: + // Build piece of SQL. + $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE'); + break; + } + } function op_word($field) { @@ -291,11 +337,39 @@ class views_handler_filter_string extends views_handler_filter { } function op_starts($field) { - $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE'); + switch (strtolower($this->options['op_location'])) { + case 'on': + $this->query->table_queue[$this->table_alias]['join']->extra[] = array( + 'field' => $this->real_field, + 'operator' => 'LIKE', + 'value' => db_like($this->value) . '%', + ); + break; + case 'where': + default: + // Build piece of SQL. + $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE'); + break; + } + } function op_not_starts($field) { - $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE'); + switch (strtolower($this->options['op_location'])) { + case 'on': + $this->query->table_queue[$this->table_alias]['join']->extra[] = array( + 'field' => $this->real_field, + 'operator' => 'NOT LIKE', + 'value' => db_like($this->value) . '%', + ); + break; + case 'where': + default: + // Build piece of SQL. + $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE'); + break; + } + } function op_ends($field) { @@ -331,8 +405,22 @@ class views_handler_filter_string extends views_handler_filter { else { $operator = "IS NOT NULL"; } + switch ($this->options['op_location']) { + case 'on': + $this->query->table_queue[$this->table_alias]['join']->extra[] = array( + 'field' => $this->real_field, + 'operator' => $operator, + 'value' => NULL, + ); + break; + case 'where': + default: + // Build piece of SQL. + $this->query->add_where($this->options['group'], $field, NULL, $operator); + break; + } - $this->query->add_where($this->options['group'], $field, NULL, $operator); + } }