GroupByNumeric.php 1.87 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\filter\GroupByNumeric.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\filter;
9

10
use Drupal\Component\Annotation\PluginID;
dawehner's avatar
dawehner committed
11

merlinofchaos's avatar
merlinofchaos committed
12 13 14 15
/**
 * Simple filter to handle greater than/less than filters
 *
 * @ingroup views_filter_handlers
16
 *
17
 * @PluginID("groupby_numeric")
dawehner's avatar
dawehner committed
18
 */
19
class GroupByNumeric extends Numeric {
20

21
  public function query() {
22 23
    $this->ensureMyTable();
    $field = $this->getField();
merlinofchaos's avatar
merlinofchaos committed
24 25 26 27 28 29 30 31 32 33

    $info = $this->operators();
    if (!empty($info[$this->operator]['method'])) {
      $this->{$info[$this->operator]['method']}($field);
    }
  }
  function op_between($field) {
    $placeholder_min = $this->placeholder();
    $placeholder_max = $this->placeholder();
    if ($this->operator == 'between') {
34 35
      $this->query->addHavingExpression($this->options['group'], "$field >= $placeholder_min", array($placeholder_min => $this->value['min']));
      $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_max", array($placeholder_max => $this->value['max']));
merlinofchaos's avatar
merlinofchaos committed
36 37
    }
    else {
38
      $this->query->addHavingExpression($this->options['group'], "$field <= $placeholder_min OR $field >= $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
merlinofchaos's avatar
merlinofchaos committed
39 40 41 42 43
    }
  }

  function op_simple($field) {
    $placeholder = $this->placeholder();
44
    $this->query->addHavingExpression($this->options['group'], "$field $this->operator $placeholder", array($placeholder => $this->value['value']));
merlinofchaos's avatar
merlinofchaos committed
45 46 47 48 49 50 51 52 53 54
  }

  function op_empty($field) {
    if ($this->operator == 'empty') {
      $operator = "IS NULL";
    }
    else {
      $operator = "IS NOT NULL";
    }

55
    $this->query->addHavingExpression($this->options['group'], "$field $operator");
merlinofchaos's avatar
merlinofchaos committed
56 57
  }

58 59
  public function adminLabel($short = FALSE) {
    return $this->getField(parent::adminLabel($short));
merlinofchaos's avatar
merlinofchaos committed
60 61
  }

62
  public function canGroup() { return FALSE; }
63

merlinofchaos's avatar
merlinofchaos committed
64
}