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
|
|
15
|
/**
|
16
|
* {@inheritdoc}
|
17
|
*/
|
18
|
public function init(&$view, &$options) {
|
19
|
parent::init($view, $options);
|
20
|
|
21
|
$this->field_info = field_info_field($this->definition['field_name']);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Called to implement a relationship in a query.
|
26
|
*/
|
27
|
public function query() {
|
28
|
$this->ensure_my_table();
|
29
|
// First, relate our base table to the current base table to the
|
30
|
// field, using the base table's id field to the field's column.
|
31
|
$views_data = views_fetch_data($this->table);
|
32
|
$left_field = $views_data['table']['base']['field'];
|
33
|
|
34
|
$first = array(
|
35
|
'left_table' => $this->table_alias,
|
36
|
'left_field' => $left_field,
|
37
|
'table' => $this->definition['field table'],
|
38
|
'field' => $this->definition['field field'],
|
39
|
);
|
40
|
if (!empty($this->options['required'])) {
|
41
|
$first['type'] = 'INNER';
|
42
|
}
|
43
|
|
44
|
if (!empty($this->definition['join_extra'])) {
|
45
|
$first['extra'] = $this->definition['join_extra'];
|
46
|
}
|
47
|
|
48
|
if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
|
49
|
$first_join = new $this->definition['join_handler'];
|
50
|
}
|
51
|
else {
|
52
|
$first_join = new views_join();
|
53
|
}
|
54
|
$first_join->definition = $first;
|
55
|
$first_join->construct();
|
56
|
$first_join->adjusted = TRUE;
|
57
|
|
58
|
$this->first_alias = $this->query->add_table($this->definition['field table'], $this->relationship, $first_join);
|
59
|
|
60
|
// Second, relate the field table to the entity specified using
|
61
|
// the entity id on the field table and the entity's id field.
|
62
|
$second = array(
|
63
|
'left_table' => $this->first_alias,
|
64
|
'left_field' => 'entity_id',
|
65
|
'table' => $this->definition['base'],
|
66
|
'field' => $this->definition['base field'],
|
67
|
);
|
68
|
|
69
|
if (!empty($this->options['required'])) {
|
70
|
$second['type'] = 'INNER';
|
71
|
}
|
72
|
|
73
|
if (!empty($this->definition['join_handler']) && class_exists($this->definition['join_handler'])) {
|
74
|
$second_join = new $this->definition['join_handler'];
|
75
|
}
|
76
|
else {
|
77
|
$second_join = new views_join();
|
78
|
}
|
79
|
$second_join->definition = $second;
|
80
|
$second_join->construct();
|
81
|
$second_join->adjusted = TRUE;
|
82
|
|
83
|
// Use a short alias for this.
|
84
|
$alias = $this->definition['field_name'] . '_' . $this->table;
|
85
|
|
86
|
$this->alias = $this->query->add_relationship($alias, $second_join, $this->definition['base'], $this->relationship);
|
87
|
}
|
88
|
|
89
|
}
|