public function SearchApiViewsHandlerFilterOptions::query in Search API 7
Add this filter to the query.
Overrides SearchApiViewsHandlerFilter::query
1 call to SearchApiViewsHandlerFilterOptions::query()
- SearchApiViewsHandlerFilterLanguage::query in contrib/
search_api_views/ includes/ handler_filter_language.inc - Add this filter to the query.
1 method overrides SearchApiViewsHandlerFilterOptions::query()
- SearchApiViewsHandlerFilterLanguage::query in contrib/
search_api_views/ includes/ handler_filter_language.inc - Add this filter to the query.
File
- contrib/
search_api_views/ includes/ handler_filter_options.inc, line 289 - Contains the SearchApiViewsHandlerFilterOptions class.
Class
- SearchApiViewsHandlerFilterOptions
- Views filter handler for fields with a limited set of possible values.
Code
public function query() {
if ($this->operator === 'empty') {
$this->query
->condition($this->real_field, NULL, '=', $this->options['group']);
return;
}
if ($this->operator === 'not empty') {
$this->query
->condition($this->real_field, NULL, '<>', $this->options['group']);
return;
}
// Extract the value.
while (is_array($this->value) && count($this->value) == 1) {
$this->value = reset($this->value);
}
// Determine operator and conjunction. The defaults are already right for
// "all of".
$operator = '=';
$conjunction = 'AND';
switch ($this->operator) {
case '=':
$conjunction = 'OR';
break;
case '<>':
$operator = '<>';
break;
}
// If the value is an empty array, we either want no filter at all (for
// "is none of"), or want to find only items with no value for the field.
if ($this->value === array()) {
if ($operator != '<>') {
$this->query
->condition($this->real_field, NULL, '=', $this->options['group']);
}
return;
}
if (is_scalar($this->value) && $this->value !== '') {
$this->query
->condition($this->real_field, $this->value, $operator, $this->options['group']);
}
elseif ($this->value) {
$filter = $this->query
->createFilter($conjunction);
// $filter will be NULL if there were errors in the query.
if ($filter) {
foreach ($this->value as $v) {
$filter
->condition($this->real_field, $v, $operator);
}
$this->query
->filter($filter, $this->options['group']);
}
}
}