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/argument/Range.php, line 75

Class

Range
Range views argument.

Namespace

Drupal\range\Plugin\views\argument

Code

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