You are here

public function views_plugin_query_default::ensure_path in Views (for Drupal 7) 7.3

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

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 copies will NOT be added if the table is already there.

2 calls to views_plugin_query_default::ensure_path()
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_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.

File

plugins/views_plugin_query_default.inc, line 642
Definition of views_plugin_query_default.

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

public function ensure_path($table, $relationship = NULL, $join = NULL, $traced = array(), $add = array()) {
  if (!isset($relationship)) {
    $relationship = $this->base_table;
  }
  if (!array_key_exists($relationship, $this->relationships)) {
    return FALSE;
  }

  // If we do not have join info, fetch it.
  if (!isset($join)) {
    $join = $this
      ->get_join_data($table, $this->relationships[$relationship]['base']);
  }

  // If it can't be fetched, this won't work.
  if (empty($join)) {
    return FALSE;
  }

  // Does a table along this path exist?
  if (isset($this->tables[$relationship][$table]) || $join && $join->left_table == $relationship || $join && $join->left_table == $this->relationships[$relationship]['table']) {

    // Make sure that we're linking to the correct table for our relationship.
    foreach (array_reverse($add) as $table => $path_join) {
      $this
        ->queue_table($table, $relationship, $this
        ->adjust_join($path_join, $relationship));
    }
    return TRUE;
  }

  // Have we been this way?
  if (isset($traced[$join->left_table])) {

    // We looped. Broked.
    return FALSE;
  }

  // Do we have to add this table?
  $left_join = $this
    ->get_join_data($join->left_table, $this->relationships[$relationship]['base']);
  if (!isset($this->tables[$relationship][$join->left_table])) {
    $add[$join->left_table] = $left_join;
  }

  // Keep looking.
  $traced[$join->left_table] = TRUE;
  return $this
    ->ensure_path($join->left_table, $relationship, $left_join, $traced, $add);
}