You are here

function og_users_roles_join::build_join in Organic groups 7.2

Build the SQL for the join this object represents.

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

Parameters

SelectQueryInterface $select_query: An Implements SelectQueryInterface.

string $table: The base table to join.

views_plugin_query $view_query: The source query, Implements views_plugin_query.

Overrides views_join::build_join

File

includes/views/handlers/og_handler_relationship_membership_roles.inc, line 29

Class

og_users_roles_join
Views join handler for the join from {og_membership} to {og_users_roles}.

Code

function build_join($select_query, $table, $view_query) {

  // We can't use the $this->extra array to add on our conditions, as they
  // relate two fields rather than a field to a value, and the parent method
  // doesn't allow this. Rather than completely rewrite it, we can call the
  // parent and then add our conditions to the SelectQuery directly.
  parent::build_join($select_query, $table, $view_query);
  $tables =& $select_query
    ->getTables();
  $left_table = $view_query
    ->get_table_info($this->left_table);

  // The left table is {og_membership}, the right table {og_users_roles}.
  $og_membership_alias = $left_table['alias'];
  $og_users_roles_alias = $table['alias'];

  // Add the condition that the group_type and gid fields match in the join
  // from the {og_membership} table to the {og_users_roles} table.
  $tables[$og_users_roles_alias]['condition'] .= " AND {$og_membership_alias}.group_type = {$og_users_roles_alias}.group_type" . " AND {$og_membership_alias}.gid = {$og_users_roles_alias}.gid";
}