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