You are here

function views_plugin_query_default::adjust_join in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 7.3 plugins/views_plugin_query_default.inc \views_plugin_query_default::adjust_join()

Fix a join to adhere to the proper relationship; the left table can vary based upon what relationship items are joined in on.

5 calls to views_plugin_query_default::adjust_join()
views_plugin_query_default::add_relationship in plugins/views_plugin_query_default.inc
A relationship is an alternative endpoint to a series of table joins. Relationships must be aliases of the primary table and they must join either to the primary table or to a pre-existing relationship.
views_plugin_query_default::add_table in plugins/views_plugin_query_default.inc
Add a table to the query, ensuring the path exists.
views_plugin_query_default::ensure_path in plugins/views_plugin_query_default.inc
Make sure that the specified table can be properly linked to the primary table in the JOINs. This function uses recursion. If the tables needed to complete the path back to the primary table are not in the query they will be added, but additional…
views_plugin_query_default::ensure_table in plugins/views_plugin_query_default.inc
Ensure a table exists in the queue; if it already exists it won't do anything, but if it doesn't it will add the table queue. It will ensure a path leads back to the relationship table.
views_plugin_query_default::queue_table in plugins/views_plugin_query_default.inc
Add a table to the query without ensuring the path.

File

plugins/views_plugin_query_default.inc, line 580
views_plugin_query_default.inc Defines the default query object which builds SQL to execute using the Drupal database API.

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

function adjust_join($join, $relationship) {
  if (!empty($join->adjusted)) {
    return $join;
  }
  if (empty($relationship) || empty($this->relationships[$relationship])) {
    return $join;
  }

  // Adjusts the left table for our relationship.
  if ($relationship != $this->base_table) {

    // If we're linking to the primary table, the relationship to use will
    // be the prior relationship. Unless it's a direct link.
    // Safety! Don't modify an original here.
    $join = drupal_clone($join);

    // Do we need to try to ensure a path?
    if ($join->left_table != $this->relationships[$relationship]['table'] && $join->left_table != $this->relationships[$relationship]['base'] && !isset($this->tables[$relationship][$join->left_table]['alias'])) {
      $this
        ->ensure_table($join->left_table, $relationship);
    }

    // First, if this is our link point/anchor table, just use the relationship
    if ($join->left_table == $this->relationships[$relationship]['table']) {
      $join->left_table = $relationship;
    }
    else {
      if (isset($this->tables[$relationship][$join->left_table]['alias'])) {
        $join->left_table = $this->tables[$relationship][$join->left_table]['alias'];
      }
      else {
        if (isset($this->table_queue[$relationship]['alias'])) {
          $join->left_table = $this->table_queue[$relationship]['alias'];
        }
      }
    }
  }
  $join->adjusted = TRUE;
  return $join;
}