1 utility.inc views_get_table_join($table, $base_table)

Fetch a handler to join one table to a primary table from the data cache

File

core/modules/views/includes/utility.inc, line 90
Utility functions for assembling Views queries.

Code

function views_get_table_join($table, $base_table) {
  $data = views_fetch_data($table);
  // #global is a special flag which let's a table appear all the time.
  // @see views_views_data().
  if (isset($data['table']['join']['#global'])) {
    return;
  }
  if (isset($data['table']['join'][$base_table])) {
    $h = $data['table']['join'][$base_table];
    if (!empty($h['handler']) && class_exists($h['handler'])) {
      $handler = new $h['handler'];
    }
    else {
      $handler = new views_join();
    }

    // Fill in some easy defaults
    $handler->definition = $h;
    if (empty($handler->definition['table'])) {
      $handler->definition['table'] = $table;
    }
    // If this is empty, it's a direct link.
    if (empty($handler->definition['left_table'])) {
      $handler->definition['left_table'] = $base_table;
    }

    if (isset($h['arguments'])) {
      call_user_func_array(array(&$handler, 'construct'), $h['arguments']);
    }
    else {
      $handler->construct();
    }

    return $handler;
  }

  // DEBUG: Identify missing handlers unless both tables are the same, because
  // no join is needed in that case.
  if ($table != $base_table) {
    watchdog('views', "Missing join: @table @base_table", array('@table' => $table, '@base_table' => $base_table));
  }
}