1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of views_plugin_row.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* @defgroup views_row_plugins Views row plugins
|
10
|
* @{
|
11
|
* Row plugins control how Views outputs an individual record.
|
12
|
*
|
13
|
* They are tightly coupled to style plugins, in that a style plugin is what
|
14
|
* calls the row plugin.
|
15
|
*
|
16
|
* @see hook_views_plugins()
|
17
|
*/
|
18
|
|
19
|
/**
|
20
|
* Default plugin to view a single row of a table. This is really just a wrapper
|
21
|
* around a theme function.
|
22
|
*/
|
23
|
class views_plugin_row extends views_plugin {
|
24
|
|
25
|
/**
|
26
|
* {@inheritdoc}
|
27
|
*/
|
28
|
public function init(&$view, &$display, $options = NULL) {
|
29
|
$this->view = &$view;
|
30
|
$this->display = &$display;
|
31
|
|
32
|
// Overlay incoming options on top of defaults
|
33
|
$this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options'));
|
34
|
}
|
35
|
|
36
|
/**
|
37
|
* {@inheritdoc}
|
38
|
*/
|
39
|
public function uses_fields() {
|
40
|
return !empty($this->definition['uses fields']);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* {@inheritdoc}
|
45
|
*/
|
46
|
public function option_definition() {
|
47
|
$options = parent::option_definition();
|
48
|
if (isset($this->base_table)) {
|
49
|
$options['relationship'] = array('default' => 'none');
|
50
|
}
|
51
|
|
52
|
return $options;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Provide a form for setting options.
|
57
|
*/
|
58
|
public function options_form(&$form, &$form_state) {
|
59
|
parent::options_form($form, $form_state);
|
60
|
if (isset($this->base_table)) {
|
61
|
$view = &$form_state['view'];
|
62
|
|
63
|
// A whole bunch of code to figure out what relationships are valid for
|
64
|
// this item.
|
65
|
$relationships = $view->display_handler->get_option('relationships');
|
66
|
$relationship_options = array();
|
67
|
|
68
|
foreach ($relationships as $relationship) {
|
69
|
$relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
|
70
|
|
71
|
// If this relationship is valid for this type, add it to the list.
|
72
|
$data = views_fetch_data($relationship['table']);
|
73
|
$base = $data[$relationship['field']]['relationship']['base'];
|
74
|
if ($base == $this->base_table) {
|
75
|
$relationship_handler->init($view, $relationship);
|
76
|
$relationship_options[$relationship['id']] = $relationship_handler->label();
|
77
|
}
|
78
|
}
|
79
|
|
80
|
if (!empty($relationship_options)) {
|
81
|
$relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
|
82
|
$rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
|
83
|
if (empty($relationship_options[$rel])) {
|
84
|
// Pick the first relationship.
|
85
|
$rel = key($relationship_options);
|
86
|
}
|
87
|
|
88
|
$form['relationship'] = array(
|
89
|
'#type' => 'select',
|
90
|
'#title' => t('Relationship'),
|
91
|
'#options' => $relationship_options,
|
92
|
'#default_value' => $rel,
|
93
|
);
|
94
|
}
|
95
|
else {
|
96
|
$form['relationship'] = array(
|
97
|
'#type' => 'value',
|
98
|
'#value' => 'none',
|
99
|
);
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Validate the options form.
|
106
|
*/
|
107
|
public function options_validate(&$form, &$form_state) {
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Perform any necessary changes to the form values prior to storage.
|
112
|
* There is no need for this function to actually store the data.
|
113
|
*/
|
114
|
public function options_submit(&$form, &$form_state) {
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* {@inheritdoc}
|
119
|
*/
|
120
|
public function query() {
|
121
|
if (isset($this->base_table)) {
|
122
|
if (isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
|
123
|
$relationship = $this->view->relationship[$this->options['relationship']];
|
124
|
$this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
|
125
|
}
|
126
|
else {
|
127
|
$this->field_alias = $this->view->query->add_field($this->base_table, $this->base_field);
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* Allow the style to do stuff before each row is rendered.
|
134
|
*
|
135
|
* @param array $result
|
136
|
* The full array of results from the query.
|
137
|
*/
|
138
|
public function pre_render($result) {
|
139
|
}
|
140
|
|
141
|
/**
|
142
|
* Render a row object. This usually passes through to a theme template
|
143
|
* of some form, but not always.
|
144
|
*
|
145
|
* @param stdClass $row
|
146
|
* A single row of the query result, so an element of $view->result.
|
147
|
*
|
148
|
* @return string
|
149
|
* The rendered output of a single row, used by the style plugin.
|
150
|
*/
|
151
|
public function render($row) {
|
152
|
return theme($this->theme_functions(),
|
153
|
array(
|
154
|
'view' => $this->view,
|
155
|
'options' => $this->options,
|
156
|
'row' => $row,
|
157
|
'field_alias' => isset($this->field_alias) ? $this->field_alias : '',
|
158
|
));
|
159
|
}
|
160
|
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* @}
|
165
|
*/
|