You are here

public function Fraction::clickSort in Fraction 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/field/Fraction.php \Drupal\fraction\Plugin\views\field\Fraction::clickSort()

Adds an ORDER BY clause to the query for click sort columns.

Parameters

string $order: Either ASC or DESC

Overrides FieldPluginBase::clickSort

File

src/Plugin/views/field/Fraction.php, line 63

Class

Fraction
Field handler for Fraction database columns.

Namespace

Drupal\fraction\Plugin\views\field

Code

public function clickSort($order) {

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

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

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