Fraction.php in Fraction 8
File
src/Plugin/views/filter/Fraction.php
View source
<?php
namespace Drupal\fraction\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\NumericFilter;
class Fraction extends NumericFilter {
public function query() {
$this
->ensureMyTable();
$formula = $this->tableAlias . '.' . $this->definition['additional fields']['numerator'] . ' / ' . $this->tableAlias . '.' . $this->definition['additional fields']['denominator'];
$info = $this
->operators();
if (!empty($info[$this->operator]['method'])) {
$this
->{$info[$this->operator]['method']}($formula);
}
}
protected function opBetween($field) {
if ($this->operator == 'between') {
$expression = $field . ' BETWEEN :min AND :max';
$this->query
->addWhereExpression($this->options['group'], $expression, [
':min' => $this->value['min'],
':max' => $this->value['max'],
]);
}
else {
$expression = $field . ' <= :min OR ' . $field . ' >= :max';
$this->query
->addWhereExpression($this->options['group'], $expression, [
':min' => $this->value['min'],
':max' => $this->value['max'],
]);
}
}
protected function opSimple($field) {
$expression = $field . ' ' . $this->operator . ' :value';
$this->query
->addWhereExpression($this->options['group'], $expression, [
':value' => $this->value['value'],
]);
}
protected function opRegex($field) {
$expression = $field . ' RLIKE :value';
$this->query
->addWhereExpression($this->options['group'], $expression, [
':value' => $this->value['value'],
]);
}
}
Classes
Name |
Description |
Fraction |
Filter handler for Fraction fields. |