commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / views / modules / field / views_handler_relationship_entity_reverse.inc
1 <?php
2
3 /**
4 * @file
5 * Definition of views_handler_relationship_entity_reverse.
6 */
7
8 /**
9 * A relationship handlers which reverse entity references.
10 *
11 * @ingroup views_relationship_handlers
12 */
13 class views_handler_relationship_entity_reverse extends views_handler_relationship {
14 function init(&$view, &$options) {
15 parent::init($view, $options);
16
17 $this->field_info = field_info_field($this->definition['field_name']);
18 }
19
20 /**
21 * Called to implement a relationship in a query.
22 */
23 function query() {
24 $this->ensure_my_table();
25 // First, relate our base table to the current base table to the
26 // field, using the base table's id field to the field's column.
27 $views_data = views_fetch_data($this->table);
28 $left_field = $views_data['table']['base']['field'];
29
30 $first = array(
31 'left_table' => $this->table_alias,
32 'left_field' => $left_field,
33 'table' => $this->definition['field table'],
34 'field' => $this->definition['field field'],
35 );
36 if (!empty($this->options['required'])) {
37 $first['type'] = 'INNER';
38 }
39
40 if (!empty($this->definition['join_extra'])) {
41 $first['extra'] = $this->definition['join_extra'];
42 }
43
44 if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
45 $first_join = new $this->definition['join_handler'];
46 }
47 else {
48 $first_join = new views_join();
49 }
50 $first_join->definition = $first;
51 $first_join->construct();
52 $first_join->adjusted = TRUE;
53
54 $this->first_alias = $this->query->add_table($this->definition['field table'], $this->relationship, $first_join);
55
56 // Second, relate the field table to the entity specified using
57 // the entity id on the field table and the entity's id field.
58 $second = array(
59 'left_table' => $this->first_alias,
60 'left_field' => 'entity_id',
61 'table' => $this->definition['base'],
62 'field' => $this->definition['base field'],
63 );
64
65 if (!empty($this->options['required'])) {
66 $second['type'] = 'INNER';
67 }
68
69 if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
70 $second_join = new $this->definition['join_handler'];
71 }
72 else {
73 $second_join = new views_join();
74 }
75 $second_join->definition = $second;
76 $second_join->construct();
77 $second_join->adjusted = TRUE;
78
79 // use a short alias for this:
80 $alias = $this->definition['field_name'] . '_' . $this->table;
81
82 $this->alias = $this->query->add_relationship($alias, $second_join, $this->definition['base'], $this->relationship);
83 }
84 }