You are here

function views_join_course::build_join in Course 7.2

Same name and namespace in other branches
  1. 8.3 views/handlers/views_join_course.inc \views_join_course::build_join()
  2. 8.2 views/handlers/views_join_course.inc \views_join_course::build_join()
  3. 7 views/handlers/views_join_course.inc \views_join_course::build_join()

Build the SQL for the join this object represents.

When possible, try to use table alias instead of table names.

Parameters

$select_query: An implementation of SelectQueryInterface.

$table: The base table to join.

$view_query: The source query, implementation of views_plugin_query.

Overrides views_join::build_join

File

views/handlers/views_join_course.inc, line 23

Class

views_join_course
Special join handler to allow join on two colums.

Code

function build_join($select_query, $table, $view_query) {
  if (empty($this->definition['table formula'])) {
    $right_table = $this->table;
  }
  else {
    $right_table = $this->definition['table formula'];
  }
  if ($this->left_table) {
    $left = $view_query
      ->get_table_info($this->left_table);
    $left_field = "{$left['alias']}.{$this->left_field}";
  }
  else {

    // This can be used if left_field is a formula or something. It should be used only *very* rarely.
    $left_field = $this->left_field;
  }
  $condition = "{$left_field} = {$table['alias']}.{$this->field}";
  $condition2 = "{$left['alias']}.{$this->extra[0]['field']} = {$table['alias']}.{$this->extra[0]['value']}";
  $condition = "({$condition} AND {$condition2})";
  $arguments = array();
  $select_query
    ->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
}