function 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 184

Class

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

Code

public function query($group_by = FALSE) {
    $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();
    $formula = FALSE;
    if (empty($this->options['glossary'])) {
        $field = "{$this->table_alias}.{$this->real_field}";
    }
    else {
        $formula = TRUE;
        $field = $this->get_formula();
    }
    if (count($this->value) > 1) {
        $operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
        $argument = $this->value;
    }
    else {
        $operator = empty($this->options['not']) ? '=' : '!=';
    }
    if ($formula) {
        $placeholder = $this->placeholder();
        if (count($this->value) > 1) {
            $field .= " {$operator} ({$placeholder})";
        }
        else {
            $field .= " {$operator} {$placeholder}";
        }
        $placeholders = array(
            $placeholder => $argument,
        );
        $this->query
            ->add_where_expression(0, $field, $placeholders);
    }
    else {
        $this->query
            ->add_where(0, $field, $argument, $operator);
    }
}