You are here

function views_handler_relationship_translation::query in Views (for Drupal 7) 6.2

Same name and namespace in other branches
  1. 6.3 modules/translation/views_handler_relationship_translation.inc \views_handler_relationship_translation::query()
  2. 7.3 modules/translation/views_handler_relationship_translation.inc \views_handler_relationship_translation::query()

Called to implement a relationship in a query.

Overrides views_handler_relationship::query

File

modules/translation/views_handler_relationship_translation.inc, line 39

Class

views_handler_relationship_translation
Handles relationships for content translation sets and provides multiple options.

Code

function query() {

  // Figure out what base table this relationship brings to the party.
  $table_data = views_fetch_data($this->definition['base']);
  $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
  $this
    ->ensure_my_table();
  $def = $this->definition;
  $def['table'] = $this->definition['base'];
  $def['field'] = $base_field;
  $def['left_table'] = $this->table_alias;
  $def['left_field'] = $this->field;
  if (!empty($this->options['required'])) {
    $def['type'] = 'INNER';
  }
  $def['extra'] = array();
  if ($this->options['language'] != 'all') {
    switch ($this->options['language']) {
      case 'current':
        $def['extra'][] = array(
          'field' => 'language',
          'value' => '***CURRENT_LANGUAGE***',
        );
        break;
      case 'default':
        $def['extra'][] = array(
          'field' => 'language',
          'value' => '***DEFAULT_LANGUAGE***',
        );
        break;

      // Other values will be the language codes.
      default:
        $def['extra'][] = array(
          'field' => 'language',
          'value' => $this->options['language'],
        );
        break;
    }
  }
  if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
    $join = new $def['join_handler']();
  }
  else {
    $join = new views_join();
  }
  $join->definition = $def;
  $join
    ->construct();
  $join->adjusted = TRUE;

  // use a short alias for this:
  $alias = $def['table'] . '_' . $this->table;
  $this->alias = $this->query
    ->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
}