You are here

public function location_handler_sort_location_country::query in Location 7.3

Same name and namespace in other branches
  1. 6.3 handlers/location_handler_sort_location_country.inc \location_handler_sort_location_country::query()

Called to add the sort to a query.

Overrides views_handler_sort::query

File

handlers/location_handler_sort_location_country.inc, line 47
Country sort handler.

Class

location_handler_sort_location_country

Code

public function query() {

  // Make sure the table_alias work.  This sets up some of the list pointers.
  $this
    ->ensure_my_table();

  // This is needed otherwise the the add_relationship will not work.
  $this->query
    ->ensure_path($this->table_alias);
  if ($this->options['country_sort'] == 'name') {
    $join = new views_join();
    $join->definition = array(
      'table' => 'location_country',
      'field' => 'code',
      'left_table' => $this->table_alias,
      'left_field' => 'country',
    );
    if (!empty($this->options['required'])) {
      $join->definition['type'] = 'INNER';
    }
    $join
      ->construct();
    $this->query
      ->add_relationship('country_name', $join, isset($this->definition['base']) ? $this->definition['base'] : NULL, NULL);
    $this->query
      ->add_orderby('country_name', 'name', $this->options['order'], 'country_sort');
  }
  elseif ($this->options['country_sort'] == 'code') {
    $this->query
      ->add_orderby($this->table_alias, 'country', $this->options['order'], 'country_code_sort');
  }
}