You are here

public function views_plugin_query_default::queue_table 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::queue_table()

Add a table to the query without ensuring the path.

This is a pretty internal function to Views and add_table() or ensure_table() should be used instead of this one, unless you are absolutely sure this is what you want.

Parameters

string $table: The name of the table to add. It needs to exist in the global table array.

string $relationship: The primary table alias this table is related to. If not set, the primary table will be used.

views_join $join: In some join configurations this table may actually join back through a different method; this is most likely to be used when tracing a hierarchy path. (node->parent->parent2->parent3). This parameter will specify how this table joins if it is not the default.

string $alias: A specific alias to use, rather than the default alias.

Return value

string The alias of the table; this alias can be used to access information about the table and should always be used to refer to the table when adding parts to the query. Or FALSE if the table was not able to be added.

3 calls to views_plugin_query_default::queue_table()
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.

File

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

Class

views_plugin_query_default
Object used to create a SELECT query.

Code

public function queue_table($table, $relationship = NULL, $join = NULL, $alias = NULL) {

  // If the alias is set, make sure it doesn't already exist.
  if (isset($this->table_queue[$alias])) {
    return $alias;
  }
  if (empty($relationship)) {
    $relationship = $this->base_table;
  }
  if (!array_key_exists($relationship, $this->relationships)) {
    return FALSE;
  }
  if (!$alias && $join && $relationship && !empty($join->adjusted) && $table != $join->table) {
    if ($relationship == $this->base_table) {
      $alias = $table;
    }
    else {
      $alias = $relationship . '_' . $table;
    }
  }

  // Check this again to make sure we don't blow up existing aliases for
  // already adjusted joins.
  if (isset($this->table_queue[$alias])) {
    return $alias;
  }
  $alias = $this
    ->mark_table($table, $relationship, $alias);

  // If no alias is specified, give it the default.
  if (!isset($alias)) {
    $alias = $this->tables[$relationship][$table]['alias'] . $this->tables[$relationship][$table]['count'];
  }

  // If this is a relationship based table, add a marker with the
  // relationship as a primary table for the alias.
  if ($table != $alias) {
    $this
      ->mark_table($alias, $this->base_table, $alias);
  }

  // If no join is specified, pull it from the table data.
  if (!isset($join)) {
    $join = $this
      ->get_join_data($table, $this->relationships[$relationship]['base']);
    if (empty($join)) {
      return FALSE;
    }
    $join = $this
      ->adjust_join($join, $relationship);
  }
  $this->table_queue[$alias] = array(
    'table' => $table,
    'num' => $this->tables[$relationship][$table]['count'],
    'alias' => $alias,
    'join' => $join,
    'relationship' => $relationship,
  );
  return $alias;
}