You are here

function views_handler_argument_string::query in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 handlers/views_handler_argument_string.inc \views_handler_argument_string::query()
  2. 7.3 handlers/views_handler_argument_string.inc \views_handler_argument_string::query()

Build the query based upon the formula

Overrides views_handler_argument::query

File

handlers/views_handler_argument_string.inc, line 175

Class

views_handler_argument_string
Basic argument handler to implement string arguments that may have length limits.

Code

function query() {
  $argument = $this->argument;
  if (!empty($this->options['transform_dash'])) {
    $argument = strtr($argument, '-', ' ');
  }
  if (!empty($this->options['break_phrase'])) {
    views_break_phrase_string($argument, $this);
  }
  else {
    $this->value = array(
      $argument,
    );
    $this->operator = 'or';
  }
  if (!empty($this->definition['many to one'])) {
    if (!empty($this->options['glossary'])) {
      $this->helper->formula = TRUE;
    }
    $this->helper
      ->ensure_my_table();
    $this->helper
      ->add_filter();
    return;
  }
  $this
    ->ensure_my_table();
  if (empty($this->options['glossary'])) {
    $field = "{$this->table_alias}.{$this->real_field}";
  }
  else {
    $field = $this
      ->get_formula();
  }
  if (count($this->value) > 1) {
    $operator = 'IN';
    $placeholders = '(' . implode(', ', array_fill(0, sizeof($this->value), "'%s'")) . ')';
    $argument = $this->value;
  }
  else {
    $placeholders = "'%s'";
    $operator = '=';
  }
  if (empty($this->options['ignorecase'])) {
    $this->query
      ->add_where(0, "{$field} {$operator} {$placeholders}", $argument);
  }
  else {
    $this->query
      ->add_where(0, "LOWER({$field}) {$operator} LOWER({$placeholders})", $argument);
  }
}