You are here

protected function Range::opWithin in Range 8

Same name in this branch
  1. 8 src/Plugin/views/filter/Range.php \Drupal\range\Plugin\views\filter\Range::opWithin()
  2. 8 src/Plugin/views/argument/Range.php \Drupal\range\Plugin\views\argument\Range::opWithin()

Operator callback.

File

src/Plugin/views/filter/Range.php, line 93

Class

Range
Range views filter.

Namespace

Drupal\range\Plugin\views\filter

Code

protected function opWithin($field_from, $field_to) {
  $operators = [
    '<',
    '>',
    '<=',
    '>=',
  ];
  $inlude_endpoints = !($this->options['include_endpoints'] xor $this->operator === 'within');
  list($op_left, $op_right) = array_slice($operators, $inlude_endpoints ? 2 : 0, 2);
  if ($this->operator === 'within') {
    $condition = $this
      ->getDatabaseConnection($this->query)
      ->condition('AND');
    $this->query
      ->addWhere($this->options['group'], $condition
      ->condition($field_from, $this->value, $op_left)
      ->condition($field_to, $this->value, $op_right));
  }
  else {
    $condition = $this
      ->getDatabaseConnection($this->query)
      ->condition('OR');
    $this->query
      ->addWhere($this->options['group'], $condition
      ->condition($field_from, $this->value, $op_right)
      ->condition($field_to, $this->value, $op_left));
  }
}