You are here

function fraction_handler_field::get_value in Fraction 7

Load the numerator and denominator values and perform conversion to decimal.

Overrides views_handler_field::get_value

File

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

Class

fraction_handler_field
Field handler for Fraction database columns.

Code

function get_value($values, $field = NULL) {

  // Find the numerator and denominator field aliases.
  $numerator_alias = $this->aliases[$this->definition['additional fields']['numerator']];
  $denominator_alias = $this->aliases[$this->definition['additional fields']['denominator']];

  // If both values are available...
  if (isset($values->{$numerator_alias}) && isset($values->{$denominator_alias})) {

    // Convert to decimal.
    $numerator = $values->{$numerator_alias};
    $denominator = $values->{$denominator_alias};
    $precision = $this->options['precision'];
    $auto_precision = $this->options['auto_precision'];
    return fraction($numerator, $denominator)
      ->toDecimal($precision, $auto_precision);
  }
}