summaryrefslogtreecommitdiffstats
path: root/views/relation_handler_relationship.inc
blob: c9be99cb9ea9576530f34387537af9ad40755318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php


class relation_handler_relationship extends views_handler_relationship {
}

class relation_handler_join extends views_join {
  /**
   * Build the SQL for the join this object represents.
   */
  function build_join($select_query, $table, $view_query) {
    $directional = $this->definition['directional'];
    // Join the left table with the entity type to the relation_data table.
    $left = $view_query->get_table_info($this->left_table);
    $entity_type_left = $this->definition['entity_type_left'];
    $conditions = "$left[alias].$this->left_field = %alias.entity_id AND %alias.entity_type = '$entity_type_left'";
    if ($directional) {
      $conditions .= " AND %alias.r_index = 0";
    }
    $l = $left_join_alias = $select_query->innerJoin("relation_data", NULL, $conditions);

    // Execute a self-join.
    $entity_type_right = $this->definition['entity_type_right'];
    $conditions = "%alias.rid = $l.rid AND %alias.r_index != $l.r_index AND %alias.entity_type = '$entity_type_right'";
    $r = $right_join_alias = $select_query->innerJoin("relation_data", NULL, $conditions);

    // Join the right table to the relation_data table.
    $conditions = "%alias.$this->field = $r.entity_id";
    $select_query->innerJoin($this->table, NULL, $conditions);
  }
}