You are here

function mvf_handler_field_mvf::click_sort in Measured Value Field 7

Called to determine what to tell the clicksorter.

Overrides views_handler_field_field::click_sort

File

views/mvf_handler_field_mvf.inc, line 27
Definition of mvf_handler_field_mvf class.

Class

mvf_handler_field_mvf
Base Views Field Handler for field types defined in MVF module.

Code

function click_sort($order) {
  $this
    ->ensure_my_table();

  // Loading the field info, we will need the information about db columns.
  $field = field_info_field($this->definition['field_name']);

  // We are going to join the {units_unit} table because it contains the
  // knowledge of factors.
  $units_unit_alias = $field['field_name'] . '_units_unit';

  // @todo: figure out whether it matters here if it is FIELD_LOAD_CURRENT or
  // FIELD_LOAD_REVISION?
  $storage = reset($field['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
  $unit_units_entity_info = entity_get_info('units_unit');
  $join = new views_join();
  $join
    ->construct('units_unit', $this->table, $storage[mvf_subfield_to_column('unit')], $unit_units_entity_info['entity keys']['id'], array(), 'INNER');
  $units_unit_alias = $this->query
    ->add_relationship($units_unit_alias, $join, $this->table_alias, $this->relationship);
  $orderby_expression = $this->table_alias . '.' . $this->real_field . ' * ' . $units_unit_alias . '.factor';
  $this->query
    ->add_orderby(NULL, $orderby_expression, $order, 'mvf_orderby');
}