d68970bd5a2953f6c2d00ce577d2a560e61bfe9b
[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
24   protected function opBetween($field) {
25     $placeholder_min = $this->placeholder();
26     $placeholder_max = $this->placeholder();
27     if ($this->operator == 'between') {
28       $this->query->addHavingExpression($this->options['group'], "$field >= $placeholder_min", [$placeholder_min => $this->value['min']]);
29       $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_max", [$placeholder_max => $this->value['max']]);
30     }
31     else {
32       $this->query->addHavingExpression($this->options['group'], "$field < $placeholder_min OR $field > $placeholder_max", [$placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']]);
33     }
34   }
35
36   protected function opSimple($field) {
37     $placeholder = $this->placeholder();
38     $this->query->addHavingExpression($this->options['group'], "$field $this->operator $placeholder", [$placeholder => $this->value['value']]);
39   }
40
41   protected function opEmpty($field) {
42     if ($this->operator == 'empty') {
43       $operator = "IS NULL";
44     }
45     else {
46       $operator = "IS NOT NULL";
47     }
48
49     $this->query->addHavingExpression($this->options['group'], "$field $operator");
50   }
51
52   public function adminLabel($short = FALSE) {
53     return $this->getField(parent::adminLabel($short));
54   }
55
56   public function canGroup() {
57     return FALSE;
58   }
59
60 }