function location_handler_filter_location_province::query in Location 6.3
Same name and namespace in other branches
- 7.5 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()
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);
}
$placeholders = db_placeholders($value, 'varchar');
$operator = $this->operator == 'is' ? 'IN' : 'NOT IN';
$this->query
->add_where($this->options['group'], "{$field} {$operator}({$placeholders})", $value);
}
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} {$operator} '%s'", $value);
}
}