You are here

public function SearchApiViewsHandlerFilterDate::query in Search API 7

Add this filter to the query.

Overrides SearchApiViewsHandlerFilterNumeric::query

File

contrib/search_api_views/includes/handler_filter_date.inc, line 128
Contains SearchApiViewsHandlerFilterDate.

Class

SearchApiViewsHandlerFilterDate
Views filter handler base class for handling date fields.

Code

public function query() {
  $this
    ->normalizeValue();
  if ($this->operator === 'empty') {
    $this->query
      ->condition($this->real_field, NULL, '=', $this->options['group']);
  }
  elseif ($this->operator === 'not empty') {
    $this->query
      ->condition($this->real_field, NULL, '<>', $this->options['group']);
  }
  elseif (in_array($this->operator, array(
    'between',
    'not between',
  ), TRUE)) {
    $min = $this->value['min'];
    if ($min !== '') {
      $min = is_numeric($min) ? $min : strtotime($min, REQUEST_TIME);
    }
    $max = $this->value['max'];
    if ($max !== '') {
      $max = is_numeric($max) ? $max : strtotime($max, REQUEST_TIME);
    }
    if (is_numeric($min) && is_numeric($max)) {
      $this->query
        ->condition($this->real_field, array(
        $min,
        $max,
      ), strtoupper($this->operator), $this->options['group']);
    }
    elseif (is_numeric($min)) {
      $operator = $this->operator === 'between' ? '>=' : '<';
      $this->query
        ->condition($this->real_field, $min, $operator, $this->options['group']);
    }
    elseif (is_numeric($max)) {
      $operator = $this->operator === 'between' ? '<=' : '>';
      $this->query
        ->condition($this->real_field, $min, $operator, $this->options['group']);
    }
  }
  else {
    $v = is_numeric($this->value['value']) ? $this->value['value'] : strtotime($this->value['value'], REQUEST_TIME);
    if ($v !== FALSE) {
      $this->query
        ->condition($this->real_field, $v, $this->operator, $this->options['group']);
    }
  }
}