577b2dfde4f15420f3fffb7f9e72ebb4c94cac3e
[yaffs-website] / web / core / modules / views / src / Plugin / views / filter / GroupByNumeric.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\filter;
4
5 /**
6  * Simple filter to handle greater than/less than filters
7  *
8  * @ingroup views_filter_handlers
9  *
10  * @ViewsFilter("groupby_numeric")
11  */
12 class GroupByNumeric extends NumericFilter {
13
14   public function query() {
15     $this->ensureMyTable();
16     $field = $this->getField();
17
18     $info = $this->operators();
19     if (!empty($info[$this->operator]['method'])) {
20       $this->{$info[$this->operator]['method']}($field);
21     }
22   }
23   protected function opBetween($field) {
24     $placeholder_min = $this->placeholder();
25     $placeholder_max = $this->placeholder();
26     if ($this->operator == 'between') {
27       $this->query->addHavingExpression($this->options['group'], "$field >= $placeholder_min", [$placeholder_min => $this->value['min']]);
28       $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_max", [$placeholder_max => $this->value['max']]);
29     }
30     else {
31       $this->query->addHavingExpression($this->options['group'], "$field < $placeholder_min OR $field > $placeholder_max", [$placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']]);
32     }
33   }
34
35   protected function opSimple($field) {
36     $placeholder = $this->placeholder();
37     $this->query->addHavingExpression($this->options['group'], "$field $this->operator $placeholder", [$placeholder => $this->value['value']]);
38   }
39
40   protected function opEmpty($field) {
41     if ($this->operator == 'empty') {
42       $operator = "IS NULL";
43     }
44     else {
45       $operator = "IS NOT NULL";
46     }
47
48     $this->query->addHavingExpression($this->options['group'], "$field $operator");
49   }
50
51   public function adminLabel($short = FALSE) {
52     return $this->getField(parent::adminLabel($short));
53   }
54
55   public function canGroup() {
56     return FALSE;
57   }
58
59 }