You are here

protected function SearchApiString::opBetween in Search API 8

Filters by operator between.

Parameters

object $field: The views field.

Overrides NumericFilter::opBetween

File

src/Plugin/views/filter/SearchApiString.php, line 22

Class

SearchApiString
Defines a filter for adding conditions on string fields to the query.

Namespace

Drupal\search_api\Plugin\views\filter

Code

protected function opBetween($field) {

  // The parent implementation in NumericFilter uses is_numeric() checks now,
  // so we need to override it to check for any values.
  if ($this->value['min'] != '' && $this->value['max'] != '') {
    $operator = $this->operator == 'between' ? 'BETWEEN' : 'NOT BETWEEN';
    $this
      ->getQuery()
      ->addWhere($this->options['group'], $field, [
      $this->value['min'],
      $this->value['max'],
    ], $operator);
  }
  elseif ($this->value['min'] != '') {
    $operator = $this->operator == 'between' ? '>=' : '<';
    $this
      ->getQuery()
      ->addWhere($this->options['group'], $field, $this->value['min'], $operator);
  }
  elseif ($this->value['max'] != '') {
    $operator = $this->operator == 'between' ? '<=' : '>';
    $this
      ->getQuery()
      ->addWhere($this->options['group'], $field, $this->value['max'], $operator);
  }
}