GroupByNumeric.php 1.89 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\Plugin;
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
 *
 * @Plugin(
aspilicious's avatar
aspilicious committed
18
 *   id = "groupby_numeric"
dawehner's avatar
dawehner committed
19 20
 * )
 */
21
class GroupByNumeric extends Numeric {
22

23
  public function query() {
24 25
    $this->ensureMyTable();
    $field = $this->getField();
merlinofchaos's avatar
merlinofchaos committed
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 58 59

    $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");
  }

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

  function can_group() { return FALSE; }
65

merlinofchaos's avatar
merlinofchaos committed
66
}