You are here

function fraction_handler_field::click_sort in Fraction 7

Use a query formula for click sorting.

Overrides views_handler_field::click_sort

File

views/handlers/fraction_handler_field.inc, line 57
Contains the Fraction Views field handler.

Class

fraction_handler_field
Field handler for Fraction database columns.

Code

function click_sort($order) {

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

  // 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->table_alias . '.' . $this->definition['additional fields']['numerator'] . ' / ' . $this->table_alias . '.' . $this->definition['additional fields']['denominator'];

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