function location_handler_filter_location_province::query in Location 7.5
Same name and namespace in other branches
- 6.3 handlers/location_handler_filter_location_province.inc \location_handler_filter_location_province::query()
- 7.3 handlers/location_handler_filter_location_province.inc \location_handler_filter_location_province::query()
- 7.4 handlers/location_handler_filter_location_province.inc \location_handler_filter_location_province::query()
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/
location_handler_filter_location_province.inc, line 90
Class
- location_handler_filter_location_province
- Filter on province.
Code
function query() {
// Normalize values.
$value = $this->value;
if (is_array($value)) {
// At one point during development, provinces was a select box.
// Right now it's an autocomplete textfield.
// @@@ Investigate correct fix sometime.
//$value = array_keys($value);
if (count($value) == 1) {
// If multiple is allowed but only one was chosen, use a string instead.
$value = reset($value);
}
}
if (empty($value)) {
return;
}
$country = $this
->grovel_country();
$this
->ensure_my_table();
$field = "{$this->table_alias}.{$this->real_field}";
if (is_array($value)) {
// Multiple values
foreach ($value as $k => $v) {
// Convert to province codes.
$value[$k] = location_province_code($country, $v);
}
$operator = $this->operator == 'is' ? 'IN' : 'NOT IN';
$this->query
->add_where($this->options['group'], $field, $value, $operator);
}
else {
// Single value
// Convert to province code.
$value = location_province_code($country, $value);
$operator = $this->operator == 'is' ? '=' : '!=';
$this->query
->add_where($this->options['group'], $field, $value, $operator);
}
}