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/sort/Fraction.php \Drupal\fraction\Plugin\views\sort\Fraction::query()

Called to add the sort to a query.

Overrides SortPluginBase::query

File

src/Plugin/views/sort/Fraction.php, line 22

Class

Fraction
Sort handler for Fraction fields.

Namespace

Drupal\fraction\Plugin\views\sort

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'];

  // Add the orderby.
  $this->query
    ->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_decimal');
}