GroupByNumeric.php 1.88 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

    $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') {
      $this->query->add_having_expression($this->options['group'], "$field >= $placeholder_min", array($placeholder_min => $this->value['min']));
      $this->query->add_having_expression($this->options['group'], "$field <= $placeholder_max", array($placeholder_max => $this->value['max']));
    }
    else {
      $this->query->add_having_expression($this->options['group'], "$field <= $placeholder_min OR $field >= $placeholder_max", array($placeholder_min => $this->value['min'], $placeholder_max => $this->value['max']));
    }
  }

  function op_simple($field) {
    $placeholder = $this->placeholder();
    $this->query->add_having_expression($this->options['group'], "$field $this->operator $placeholder", array($placeholder => $this->value['value']));
  }

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

    $this->query->add_having_expression($this->options['group'], "$field $operator");
  }

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

  function can_group() { return FALSE; }
63

merlinofchaos's avatar
merlinofchaos committed
64
}