Commit 5601e988 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2686483 by stBorchert, daffie: Add support for database condition operator "NOT BETWEEN"

parent 9cae5235
Loading
Loading
Loading
Loading
+1
Changes for core/lib/Drupal/Core/Database/Query/Condition.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -300,6 +300,7 @@ protected function mapConditionOperator($operator) {
    // $specials does not use drupal_static as its value never changes.
    static $specials = array(
      'BETWEEN' => array('delimiter' => ' AND '),
      'NOT BETWEEN' => array('delimiter' => ' AND '),
      'IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
      'NOT IN' => array('delimiter' => ', ', 'prefix' => ' (', 'postfix' => ')'),
      'EXISTS' => array('prefix' => ' (', 'postfix' => ')'),
+2 −1
Changes for core/modules/datetime/src/Tests/Views/FilterDateTimeTest.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -136,7 +136,8 @@ protected function _testBetween() {
    $view->initHandlers();
    $view->filter[$field]->operator = 'not between';
    $view->filter[$field]->value['min'] = '2001-01-01';
    $view->filter[$field]->value['max'] = '2002-01-01';
    // Set maximum date to date of node 1 to test range borders.
    $view->filter[$field]->value['max'] = '2001-10-10T12:12:12';
    $view->setDisplay('default');
    $this->executeView($view);
    $expected_result = [
+1 −1
Changes for core/modules/views/src/Plugin/views/filter/GroupByNumeric.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ protected function opBetween($field) {
      $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_max", array($placeholder_max => $this->value['max']));
    }
    else {
      $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_min OR $field >= $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
      $this->query->addHavingExpression($this->options['group'], "$field < $placeholder_min OR $field > $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
    }
  }

+1 −1
Changes for core/modules/views/src/Plugin/views/filter/NumericFilter.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ protected function opBetween($field) {
      $this->query->addWhere($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'BETWEEN');
    }
    else {
      $this->query->addWhere($this->options['group'], db_or()->condition($field, $this->value['min'], '<=')->condition($field, $this->value['max'], '>='));
      $this->query->addWhere($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'NOT BETWEEN');
    }
  }

+7 −8
Changes for core/modules/views/src/Tests/Handler/FilterDateTest.php: 7 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ protected function _testBetween() {
    // Test between with min and max.
    $view->initHandlers();
    $view->filter['created']->operator = 'between';
    $view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:i:s');
    $view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $expected_result = array(
      array('nid' => $this->nodes[1]->id()),
@@ -100,7 +100,7 @@ protected function _testBetween() {
    // Test between with just max.
    $view->initHandlers();
    $view->filter['created']->operator = 'between';
    $view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $expected_result = array(
      array('nid' => $this->nodes[0]->id()),
@@ -112,11 +112,11 @@ protected function _testBetween() {
    // Test not between with min and max.
    $view->initHandlers();
    $view->filter['created']->operator = 'not between';
    $view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['min'] = format_date(100000, 'custom', 'Y-m-d H:i:s');
    $view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');

    $view->executeDisplay('default');
    $expected_result = array(
      array('nid' => $this->nodes[0]->id()),
      array('nid' => $this->nodes[2]->id()),
      array('nid' => $this->nodes[3]->id()),
    );
@@ -126,10 +126,9 @@ protected function _testBetween() {
    // Test not between with just max.
    $view->initHandlers();
    $view->filter['created']->operator = 'not between';
    $view->filter['created']->value['max'] = format_date(150000, 'custom', 'Y-m-d H:s');
    $view->filter['created']->value['max'] = format_date(200000, 'custom', 'Y-m-d H:i:s');
    $view->executeDisplay('default');
    $expected_result = array(
      array('nid' => $this->nodes[1]->id()),
      array('nid' => $this->nodes[2]->id()),
      array('nid' => $this->nodes[3]->id()),
    );
Loading