fixed typo
[project/relation.git] / views / relation_handler_relationship.inc
1 <?php
2
3
4 class relation_handler_relationship extends views_handler_relationship {
5 }
6
7 class relation_handler_join extends views_join {
8 /**
9 * Build the SQL for the join this object represents.
10 */
11 function build_join($select_query, $table, $view_query) {
12 $directional = $this->definition['directional'];
13 // Join the left table with the entity type to the relation_data table.
14 $left = $view_query->get_table_info($this->left_table);
15 $entity_type_left = $this->definition['entity_type_left'];
16 $conditions = "$left[alias].$this->left_field = %alias.entity_id AND %alias.entity_type = '$entity_type_left'";
17 if ($directional) {
18 $conditions .= " AND %alias.r_index = 0";
19 }
20 $l = $left_join_alias = $select_query->innerJoin("relation_data", NULL, $conditions);
21
22 // Execute a self-join.
23 $entity_type_right = $this->definition['entity_type_right'];
24 $conditions = "%alias.rid = $l.rid AND %alias.r_index != $l.r_index AND %alias.entity_type = '$entity_type_right'";
25 $r = $right_join_alias = $select_query->innerJoin("relation_data", NULL, $conditions);
26
27 // Join the right table to the relation_data table.
28 $conditions = "%alias.$this->field = $r.entity_id";
29 $select_query->innerJoin($this->table, NULL, $conditions);
30 }
31 }