GroupByNumeric.php

Same filename in this branch
  1. 11.x core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
  2. 11.x core/modules/views/src/Plugin/views/argument/GroupByNumeric.php
Same filename in other branches
  1. 9 core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
  2. 9 core/modules/views/src/Plugin/views/filter/GroupByNumeric.php
  3. 9 core/modules/views/src/Plugin/views/argument/GroupByNumeric.php
  4. 8.9.x core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
  5. 8.9.x core/modules/views/src/Plugin/views/filter/GroupByNumeric.php
  6. 8.9.x core/modules/views/src/Plugin/views/argument/GroupByNumeric.php
  7. 10 core/modules/views/src/Plugin/views/sort/GroupByNumeric.php
  8. 10 core/modules/views/src/Plugin/views/filter/GroupByNumeric.php
  9. 10 core/modules/views/src/Plugin/views/argument/GroupByNumeric.php

Namespace

Drupal\views\Plugin\views\filter

File

core/modules/views/src/Plugin/views/filter/GroupByNumeric.php

View source
<?php

namespace Drupal\views\Plugin\views\filter;

use Drupal\views\Attribute\ViewsFilter;

/**
 * Simple filter to handle greater than/less than filters.
 *
 * @ingroup views_filter_handlers
 */
class GroupByNumeric extends NumericFilter {
    public function query() {
        $this->ensureMyTable();
        $field = $this->getField();
        $info = $this->operators();
        if (!empty($info[$this->operator]['method'])) {
            $this->{$info[$this->operator]['method']}($field);
        }
    }
    protected function opBetween($field) {
        $placeholder_min = $this->placeholder();
        $placeholder_max = $this->placeholder();
        if ($this->operator == 'between') {
            $this->query
                ->addHavingExpression($this->options['group'], "{$field} >= {$placeholder_min}", [
                $placeholder_min => $this->value['min'],
            ]);
            $this->query
                ->addHavingExpression($this->options['group'], "{$field} <= {$placeholder_max}", [
                $placeholder_max => $this->value['max'],
            ]);
        }
        else {
            $this->query
                ->addHavingExpression($this->options['group'], "{$field} < {$placeholder_min} OR {$field} > {$placeholder_max}", [
                $placeholder_min => $this->value['min'],
                $placeholder_max => $this->value['max'],
            ]);
        }
    }
    protected function opSimple($field) {
        $placeholder = $this->placeholder();
        $this->query
            ->addHavingExpression($this->options['group'], "{$field} {$this->operator} {$placeholder}", [
            $placeholder => $this->value['value'],
        ]);
    }
    protected function opEmpty($field) {
        if ($this->operator == 'empty') {
            $operator = "IS NULL";
        }
        else {
            $operator = "IS NOT NULL";
        }
        $this->query
            ->addHavingExpression($this->options['group'], "{$field} {$operator}");
    }
    public function adminLabel($short = FALSE) {
        return $this->getField(parent::adminLabel($short));
    }
    public function canGroup() {
        return FALSE;
    }

}

Classes

Title Deprecated Summary
GroupByNumeric Simple filter to handle greater than/less than filters.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.