You are here

function location_handler_filter_location_country::query in Location 6.3

Same name and namespace in other branches
  1. 7.5 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country::query()
  2. 7.3 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country::query()
  3. 7.4 handlers/location_handler_filter_location_country.inc \location_handler_filter_location_country::query()

File

handlers/location_handler_filter_location_country.inc, line 152

Class

location_handler_filter_location_country
Filter on country.

Code

function query() {
  if (empty($this->value)) {
    return;
  }
  $this
    ->ensure_my_table();
  $field = "{$this->table_alias}.{$this->real_field}";

  // Normalize values.
  $value = $this->value;
  if (is_array($value)) {
    $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 (is_array($value)) {

    // Multiple values
    $placeholders = db_placeholders($value, 'varchar');
    $operator = $this->operator == 'in' ? 'IN' : 'NOT IN';
    $this->query
      ->add_where($this->options['group'], "{$field} {$operator}({$placeholders})", $value);
  }
  else {

    // Single value
    $operator = $this->operator == 'in' ? '=' : '!=';
    $this->query
      ->add_where($this->options['group'], "{$field} {$operator} '%s'", $this->value);
  }
}