You are here

public function Fraction::query in Fraction 8

Same name in this branch
  1. 8 src/Plugin/views/filter/Fraction.php \Drupal\fraction\Plugin\views\filter\Fraction::query()
  2. 8 src/Plugin/views/sort/Fraction.php \Drupal\fraction\Plugin\views\sort\Fraction::query()
Same name and namespace in other branches
  1. 2.x src/Plugin/views/filter/Fraction.php \Drupal\fraction\Plugin\views\filter\Fraction::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides NumericFilter::query

File

src/Plugin/views/filter/Fraction.php, line 26

Class

Fraction
Filter handler for Fraction fields.

Namespace

Drupal\fraction\Plugin\views\filter

Code

public function query() {

  // Ensure the main table for this field is included.
  $this
    ->ensureMyTable();

  // Formula for calculating the final value, by dividing numerator by denominator.
  // These are added as additional fields in hook_field_views_data_alter().
  $formula = $this->tableAlias . '.' . $this->definition['additional fields']['numerator'] . ' / ' . $this->tableAlias . '.' . $this->definition['additional fields']['denominator'];

  // Perform the filter using the selected operator and the formula.
  $info = $this
    ->operators();
  if (!empty($info[$this->operator]['method'])) {
    $this
      ->{$info[$this->operator]['method']}($formula);
  }
}