1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Views hooks implemented for the Webform module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
function webform_views_data() {
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Webform table definitions.
|
12 |
|
|
*/
|
13 |
|
|
$data['webform']['table']['group'] = t('Webform');
|
14 |
a45e4bc1
|
Assos Assos
|
$data['webform']['table']['base'] = array(
|
15 |
|
|
'field' => 'nid',
|
16 |
|
|
'title' => t('Webform nodes'),
|
17 |
|
|
'help' => t('Nodes which have webforms.'),
|
18 |
|
|
);
|
19 |
85ad3d82
|
Assos Assos
|
$data['webform']['table']['join'] = array(
|
20 |
|
|
'node' => array(
|
21 |
|
|
'left_field' => 'nid',
|
22 |
|
|
'field' => 'nid',
|
23 |
|
|
'type' => 'INNER',
|
24 |
|
|
),
|
25 |
|
|
);
|
26 |
|
|
|
27 |
a45e4bc1
|
Assos Assos
|
// NID
|
28 |
|
|
$data['webform']['nid'] = array(
|
29 |
|
|
'title' => t('Node'),
|
30 |
|
|
'help' => t('The node this webform is part of.'),
|
31 |
|
|
'relationship' => array(
|
32 |
|
|
'base' => 'node',
|
33 |
|
|
'field' => 'nid',
|
34 |
|
|
'handler' => 'views_handler_relationship',
|
35 |
|
|
'label' => t('Node for webform'),
|
36 |
|
|
),
|
37 |
|
|
'filter' => array(
|
38 |
|
|
'handler' => 'views_handler_filter_numeric',
|
39 |
|
|
),
|
40 |
|
|
'sort' => array(
|
41 |
|
|
'handler' => 'views_handler_sort',
|
42 |
|
|
),
|
43 |
|
|
'argument' => array(
|
44 |
|
|
'handler' => 'views_handler_argument_node_nid',
|
45 |
|
|
'name field' => 'title', // the field to display in the summary.
|
46 |
|
|
'numeric' => TRUE,
|
47 |
|
|
'validate type' => 'nid',
|
48 |
|
|
),
|
49 |
|
|
);
|
50 |
|
|
|
51 |
85ad3d82
|
Assos Assos
|
// status
|
52 |
|
|
$data['webform']['status'] = array(
|
53 |
|
|
'title' => t('Status'),
|
54 |
|
|
'help' => t('The open or closed status of a webform.'),
|
55 |
|
|
'field' => array(
|
56 |
|
|
'handler' => 'webform_handler_field_webform_status',
|
57 |
|
|
'click sortable' => TRUE,
|
58 |
|
|
),
|
59 |
|
|
'filter' => array(
|
60 |
|
|
'label' => t('Status'),
|
61 |
|
|
'handler' => 'webform_handler_filter_webform_status',
|
62 |
|
|
'type' => 'open-closed',
|
63 |
|
|
),
|
64 |
|
|
'sort' => array(
|
65 |
|
|
'handler' => 'views_handler_sort',
|
66 |
|
|
),
|
67 |
|
|
);
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Submissions table definitions.
|
71 |
|
|
*/
|
72 |
|
|
$data['webform_submissions']['table']['group'] = t('Webform submissions');
|
73 |
|
|
$data['webform_submissions']['table']['base'] = array(
|
74 |
|
|
'field' => 'sid',
|
75 |
|
|
'title' => t('Webform submissions'),
|
76 |
|
|
'help' => t('Submissions generated from Webform forms.'),
|
77 |
|
|
);
|
78 |
|
|
|
79 |
a45e4bc1
|
Assos Assos
|
// Serial number.
|
80 |
|
|
$data['webform_submissions']['serial'] = array(
|
81 |
|
|
'title' => t('Serial number'),
|
82 |
|
|
'help' => t('The serial number of the submission.'),
|
83 |
|
|
'field' => array(
|
84 |
|
|
'handler' => 'views_handler_field_numeric',
|
85 |
|
|
'click sortable' => TRUE,
|
86 |
|
|
),
|
87 |
|
|
'filter' => array(
|
88 |
|
|
'title' => t('Serial number'),
|
89 |
|
|
'handler' => 'views_handler_filter_numeric',
|
90 |
|
|
),
|
91 |
|
|
'sort' => array(
|
92 |
|
|
'handler' => 'views_handler_sort',
|
93 |
|
|
),
|
94 |
|
|
'argument' => array(
|
95 |
|
|
'handler' => 'views_handler_argument_numeric',
|
96 |
|
|
),
|
97 |
|
|
);
|
98 |
|
|
|
99 |
|
|
// SID.
|
100 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['sid'] = array(
|
101 |
|
|
'title' => t('Sid'),
|
102 |
|
|
'help' => t('The submission ID of the submission.'),
|
103 |
|
|
'field' => array(
|
104 |
|
|
'handler' => 'views_handler_field_numeric',
|
105 |
|
|
'click sortable' => TRUE,
|
106 |
|
|
),
|
107 |
|
|
'filter' => array(
|
108 |
|
|
'title' => t('Sid'),
|
109 |
|
|
'handler' => 'views_handler_filter_numeric',
|
110 |
|
|
),
|
111 |
|
|
'sort' => array(
|
112 |
|
|
'handler' => 'views_handler_sort',
|
113 |
|
|
),
|
114 |
|
|
'argument' => array(
|
115 |
|
|
'handler' => 'views_handler_argument_numeric',
|
116 |
|
|
),
|
117 |
|
|
);
|
118 |
|
|
|
119 |
a45e4bc1
|
Assos Assos
|
// Submission data as a field loads the entire submission.
|
120 |
|
|
$data['webform_submissions']['value'] = array(
|
121 |
|
|
'title' => t('Value'),
|
122 |
|
|
'help' => t('The value of a component as submitted by a user.'),
|
123 |
|
|
'real field' => 'sid',
|
124 |
|
|
'group' => t('Webform submission data'),
|
125 |
|
|
'field' => array(
|
126 |
|
|
'handler' => 'webform_handler_field_submission_data',
|
127 |
|
|
'webform_expand' => FALSE,
|
128 |
|
|
'click sortable' => TRUE,
|
129 |
|
|
),
|
130 |
|
|
);
|
131 |
|
|
|
132 |
|
|
// Expanded to generate a field for every viewable component
|
133 |
|
|
$data['webform_submissions']['webform_all_fields'] = array(
|
134 |
|
|
'title' => t('All values'),
|
135 |
|
|
'help' => t('Displays all values as submitted by a user.'),
|
136 |
|
|
'real field' => 'sid',
|
137 |
|
|
'group' => t('Webform submission data'),
|
138 |
|
|
'field' => array(
|
139 |
|
|
'handler' => 'webform_handler_field_submission_data',
|
140 |
|
|
'webform_expand' => TRUE,
|
141 |
|
|
'click sortable' => TRUE,
|
142 |
|
|
),
|
143 |
|
|
);
|
144 |
|
|
|
145 |
|
|
// NID.
|
146 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['nid'] = array(
|
147 |
|
|
'title' => t('Node'),
|
148 |
|
|
'help' => t('The webform node this submission was generated from.'),
|
149 |
|
|
'relationship' => array(
|
150 |
|
|
'base' => 'node',
|
151 |
|
|
'field' => 'nid',
|
152 |
|
|
'handler' => 'views_handler_relationship',
|
153 |
|
|
'label' => t('Webform Node'),
|
154 |
|
|
),
|
155 |
a45e4bc1
|
Assos Assos
|
'filter' => array(
|
156 |
|
|
'handler' => 'views_handler_filter_numeric',
|
157 |
|
|
),
|
158 |
|
|
'sort' => array(
|
159 |
|
|
'handler' => 'views_handler_sort',
|
160 |
|
|
),
|
161 |
|
|
'argument' => array(
|
162 |
|
|
'handler' => 'views_handler_argument_node_nid',
|
163 |
|
|
'name field' => 'title', // the field to display in the summary.
|
164 |
|
|
'numeric' => TRUE,
|
165 |
|
|
'validate type' => 'nid',
|
166 |
|
|
),
|
167 |
85ad3d82
|
Assos Assos
|
);
|
168 |
|
|
|
169 |
a45e4bc1
|
Assos Assos
|
// UID.
|
170 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['uid'] = array(
|
171 |
|
|
'title' => t('User'),
|
172 |
|
|
'help' => t('The user who sent the webform submission.'),
|
173 |
|
|
'relationship' => array(
|
174 |
|
|
'base' => 'users',
|
175 |
|
|
'field' => 'uid',
|
176 |
|
|
'handler' => 'views_handler_relationship',
|
177 |
|
|
'label' => t('Webform Submission User'),
|
178 |
|
|
),
|
179 |
a45e4bc1
|
Assos Assos
|
'filter' => array(
|
180 |
|
|
'handler' => 'views_handler_filter_user_name',
|
181 |
|
|
),
|
182 |
|
|
'sort' => array(
|
183 |
|
|
'handler' => 'views_handler_sort',
|
184 |
|
|
),
|
185 |
|
|
'argument' => array(
|
186 |
|
|
'handler' => 'views_handler_argument_numeric',
|
187 |
|
|
),
|
188 |
|
|
'field' => array(
|
189 |
|
|
'handler' => 'views_handler_field_user',
|
190 |
|
|
),
|
191 |
85ad3d82
|
Assos Assos
|
);
|
192 |
|
|
|
193 |
a45e4bc1
|
Assos Assos
|
// Is draft.
|
194 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['is_draft'] = array(
|
195 |
|
|
'title' => t('Draft'),
|
196 |
|
|
'help' => t('Whether or not the submission is a draft.'),
|
197 |
|
|
'field' => array(
|
198 |
|
|
'handler' => 'webform_handler_field_is_draft',
|
199 |
|
|
'click sortable' => TRUE,
|
200 |
|
|
),
|
201 |
|
|
'filter' => array(
|
202 |
|
|
'handler' => 'webform_handler_filter_is_draft',
|
203 |
|
|
),
|
204 |
|
|
'sort' => array(
|
205 |
|
|
'handler' => 'views_handler_sort',
|
206 |
|
|
),
|
207 |
|
|
);
|
208 |
|
|
|
209 |
a45e4bc1
|
Assos Assos
|
// Submitted timestamp.
|
210 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['submitted'] = array(
|
211 |
|
|
'title' => t('Submitted'),
|
212 |
a45e4bc1
|
Assos Assos
|
'help' => t('Timestamp when the form was first saved as draft or submitted.'),
|
213 |
85ad3d82
|
Assos Assos
|
'field' => array(
|
214 |
|
|
'handler' => 'views_handler_field_date',
|
215 |
|
|
'click sortable' => TRUE,
|
216 |
|
|
),
|
217 |
|
|
'filter' => array(
|
218 |
|
|
'title' => t('Submitted'),
|
219 |
|
|
'handler' => 'views_handler_filter_date',
|
220 |
|
|
),
|
221 |
|
|
'sort' => array(
|
222 |
|
|
'handler' => 'views_handler_sort_date',
|
223 |
|
|
),
|
224 |
a45e4bc1
|
Assos Assos
|
'argument' => array(
|
225 |
|
|
'handler' => 'views_handler_argument_date',
|
226 |
|
|
),
|
227 |
|
|
);
|
228 |
|
|
|
229 |
|
|
// Completed timestamp.
|
230 |
|
|
$data['webform_submissions']['completed'] = array(
|
231 |
|
|
'title' => t('Completed'),
|
232 |
|
|
'help' => t('Timestamp when the form was submitted as complete (not draft).'),
|
233 |
|
|
'field' => array(
|
234 |
|
|
'handler' => 'views_handler_field_date',
|
235 |
|
|
'click sortable' => TRUE,
|
236 |
|
|
),
|
237 |
|
|
'filter' => array(
|
238 |
|
|
'title' => t('Completed'),
|
239 |
|
|
'handler' => 'views_handler_filter_date',
|
240 |
|
|
),
|
241 |
|
|
'sort' => array(
|
242 |
|
|
'handler' => 'views_handler_sort_date',
|
243 |
|
|
),
|
244 |
|
|
'argument' => array(
|
245 |
|
|
'handler' => 'views_handler_argument_date',
|
246 |
|
|
),
|
247 |
|
|
);
|
248 |
|
|
|
249 |
|
|
// Modified timestamp.
|
250 |
|
|
$data['webform_submissions']['modified'] = array(
|
251 |
|
|
'title' => t('Modified'),
|
252 |
|
|
'help' => t('Timestamp when the form was last saved (complete or draft).'),
|
253 |
|
|
'field' => array(
|
254 |
|
|
'handler' => 'views_handler_field_date',
|
255 |
|
|
'click sortable' => TRUE,
|
256 |
|
|
),
|
257 |
|
|
'filter' => array(
|
258 |
|
|
'title' => t('Modified'),
|
259 |
|
|
'handler' => 'views_handler_filter_date',
|
260 |
|
|
),
|
261 |
|
|
'sort' => array(
|
262 |
|
|
'handler' => 'views_handler_sort_date',
|
263 |
|
|
),
|
264 |
|
|
'argument' => array(
|
265 |
|
|
'handler' => 'views_handler_argument_date',
|
266 |
|
|
),
|
267 |
85ad3d82
|
Assos Assos
|
);
|
268 |
|
|
|
269 |
a45e4bc1
|
Assos Assos
|
// IP Address (remote_addr).
|
270 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['remote_addr'] = array(
|
271 |
|
|
'title' => t('Remote address'),
|
272 |
|
|
'help' => t('The remote IP address of the user that submitted this submission.'),
|
273 |
|
|
'field' => array(
|
274 |
|
|
'handler' => 'views_handler_field',
|
275 |
|
|
'click sortable' => TRUE,
|
276 |
|
|
),
|
277 |
|
|
'filter' => array(
|
278 |
|
|
'title' => t('Remote address'),
|
279 |
|
|
'handler' => 'views_handler_filter_string',
|
280 |
|
|
),
|
281 |
|
|
'sort' => array(
|
282 |
|
|
'handler' => 'views_handler_sort',
|
283 |
|
|
),
|
284 |
|
|
);
|
285 |
|
|
|
286 |
a45e4bc1
|
Assos Assos
|
// View submission link.
|
287 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['view_submission'] = array(
|
288 |
a45e4bc1
|
Assos Assos
|
'title' => t('View link'),
|
289 |
|
|
'help' => t('Provide a simple link to view the submission.'),
|
290 |
|
|
'real field' => 'serial',
|
291 |
85ad3d82
|
Assos Assos
|
'field' => array(
|
292 |
|
|
'handler' => 'webform_handler_field_submission_link',
|
293 |
a45e4bc1
|
Assos Assos
|
'click sortable' => TRUE,
|
294 |
|
|
'real field' => 'serial',
|
295 |
85ad3d82
|
Assos Assos
|
'link_type' => 'view',
|
296 |
|
|
),
|
297 |
a45e4bc1
|
Assos Assos
|
'sort' => array(
|
298 |
|
|
'handler' => 'views_handler_sort',
|
299 |
|
|
),
|
300 |
85ad3d82
|
Assos Assos
|
);
|
301 |
|
|
|
302 |
a45e4bc1
|
Assos Assos
|
// Edit submission link.
|
303 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['edit_submission'] = array(
|
304 |
a45e4bc1
|
Assos Assos
|
'title' => t('Edit link'),
|
305 |
|
|
'help' => t('Provide a simple link to edit the submission.'),
|
306 |
|
|
'real field' => 'serial',
|
307 |
85ad3d82
|
Assos Assos
|
'field' => array(
|
308 |
|
|
'handler' => 'webform_handler_field_submission_link',
|
309 |
a45e4bc1
|
Assos Assos
|
'click sortable' => TRUE,
|
310 |
85ad3d82
|
Assos Assos
|
'link_type' => 'edit',
|
311 |
|
|
),
|
312 |
a45e4bc1
|
Assos Assos
|
'sort' => array(
|
313 |
|
|
'handler' => 'views_handler_sort',
|
314 |
|
|
),
|
315 |
85ad3d82
|
Assos Assos
|
);
|
316 |
|
|
|
317 |
a45e4bc1
|
Assos Assos
|
// Delete submission link.
|
318 |
85ad3d82
|
Assos Assos
|
$data['webform_submissions']['delete_submission'] = array(
|
319 |
a45e4bc1
|
Assos Assos
|
'title' => t('Delete link'),
|
320 |
|
|
'help' => t('Provide a simple link to delete the submission.'),
|
321 |
|
|
'real field' => 'serial',
|
322 |
85ad3d82
|
Assos Assos
|
'field' => array(
|
323 |
|
|
'handler' => 'webform_handler_field_submission_link',
|
324 |
a45e4bc1
|
Assos Assos
|
'click sortable' => TRUE,
|
325 |
85ad3d82
|
Assos Assos
|
'link_type' => 'delete',
|
326 |
|
|
),
|
327 |
a45e4bc1
|
Assos Assos
|
'sort' => array(
|
328 |
|
|
'handler' => 'views_handler_sort',
|
329 |
|
|
),
|
330 |
|
|
);
|
331 |
|
|
|
332 |
|
|
// Relation to webform_submitted_data table.
|
333 |
|
|
$data['webform_submissions']['data'] = array(
|
334 |
|
|
'title' => t('Data'),
|
335 |
|
|
'help' => t('Relates to a webform submission data'),
|
336 |
|
|
'real field' => 'sid',
|
337 |
|
|
'relationship' => array(
|
338 |
|
|
'handler' => 'webform_handler_relationship_submission_data',
|
339 |
|
|
'base' => 'webform_submitted_data',
|
340 |
|
|
'base field' => 'sid',
|
341 |
|
|
'label' => t('Submission Data'),
|
342 |
|
|
),
|
343 |
|
|
);
|
344 |
|
|
|
345 |
|
|
/**
|
346 |
|
|
* Submission data table definitions.
|
347 |
|
|
*/
|
348 |
|
|
$data['webform_submitted_data']['table']['group'] = t('Webform submission data');
|
349 |
|
|
|
350 |
|
|
// Raw access to the submitted values. This usually will only be used for
|
351 |
|
|
// sorts and filters, since the 'value' field for the submission will often
|
352 |
|
|
// be faster and easier to configure than the raw values.
|
353 |
|
|
$data['webform_submitted_data']['data'] = array(
|
354 |
|
|
'table' => 'webform_submitted_data',
|
355 |
|
|
'title' => t('Data field'),
|
356 |
|
|
'help' => t('The value of a component as submitted by a user.'),
|
357 |
|
|
'real field' => 'data',
|
358 |
|
|
'field' => array(
|
359 |
|
|
'title' => t('Value (raw)'), // Distinguish from the normal value handler.
|
360 |
|
|
'help' => t('The raw value from the database as submitted by a user. Use only when needing to sort on a field value.'),
|
361 |
|
|
'handler' => 'views_handler_field',
|
362 |
|
|
'click sortable' => TRUE,
|
363 |
|
|
),
|
364 |
|
|
'argument' => array(
|
365 |
|
|
'handler' => 'views_handler_argument_string',
|
366 |
|
|
),
|
367 |
|
|
'filter' => array(
|
368 |
|
|
'handler' => 'webform_handler_filter_submission_data',
|
369 |
|
|
),
|
370 |
|
|
'sort' => array(
|
371 |
|
|
'handler' => 'views_handler_sort',
|
372 |
|
|
),
|
373 |
|
|
);
|
374 |
|
|
|
375 |
|
|
// Same as 'data', but handled as numeric data.
|
376 |
|
|
$data['webform_submitted_data']['data_numeric'] = array(
|
377 |
|
|
'table' => 'webform_submitted_data',
|
378 |
|
|
'title' => t('Data field (numeric)'),
|
379 |
|
|
'help' => t('The numeric value of a component as submitted by a user.'),
|
380 |
|
|
'real field' => 'data',
|
381 |
|
|
'field' => array(
|
382 |
|
|
'title' => t('Numeric value (raw)'), // Distinguish from the normal value handler.
|
383 |
|
|
'help' => t('The raw value from the database, cast to a number, as submitted by a user. Use only when needing to sort on a field value.'),
|
384 |
|
|
'handler' => 'webform_handler_field_numeric_data',
|
385 |
|
|
'click sortable' => TRUE,
|
386 |
|
|
'float' => TRUE,
|
387 |
|
|
),
|
388 |
|
|
'argument' => array(
|
389 |
|
|
'handler' => 'views_handler_argument_numeric',
|
390 |
|
|
),
|
391 |
|
|
'filter' => array(
|
392 |
|
|
'handler' => 'webform_handler_filter_numeric_data',
|
393 |
|
|
),
|
394 |
|
|
'sort' => array(
|
395 |
|
|
'handler' => 'webform_handler_sort_numeric_data',
|
396 |
|
|
),
|
397 |
|
|
);
|
398 |
|
|
|
399 |
|
|
// Number field for multi-value fields.
|
400 |
|
|
$data['webform_submitted_data']['no'] = array(
|
401 |
|
|
'title' => t('Value delta'),
|
402 |
|
|
'help' => t('The delta value of the submitted data in a multi value component (such as checkboxes).'),
|
403 |
|
|
'real field' => 'no',
|
404 |
|
|
'argument' => array(
|
405 |
|
|
'handler' => 'views_handler_argument_numeric',
|
406 |
|
|
),
|
407 |
|
|
'field' => array(
|
408 |
|
|
'handler' => 'views_handler_field_numeric',
|
409 |
|
|
),
|
410 |
|
|
'filter' => array(
|
411 |
|
|
'handler' => 'views_handler_filter_numeric',
|
412 |
|
|
),
|
413 |
|
|
'sort' => array(
|
414 |
|
|
'handler' => 'views_handler_sort',
|
415 |
|
|
),
|
416 |
85ad3d82
|
Assos Assos
|
);
|
417 |
|
|
|
418 |
|
|
return $data;
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
/**
|
422 |
|
|
* Implements hook_views_data_alter().
|
423 |
|
|
*/
|
424 |
|
|
function webform_views_data_alter(&$data) {
|
425 |
|
|
// Webform submission from node.
|
426 |
|
|
$data['node']['webform_submission'] = array(
|
427 |
|
|
'title' => t('Webform submission'),
|
428 |
|
|
'help' => t('Webform submissions of the given Webform node.'),
|
429 |
|
|
'real field' => 'nid',
|
430 |
|
|
'relationship' => array(
|
431 |
|
|
'base' => 'webform_submissions',
|
432 |
|
|
'base field' => 'nid',
|
433 |
|
|
'handler' => 'views_handler_relationship',
|
434 |
|
|
'label' => t('Webform Submission'),
|
435 |
|
|
),
|
436 |
|
|
);
|
437 |
|
|
$data['node']['table']['join']['webform_submissions'] = array(
|
438 |
|
|
'field' => 'nid',
|
439 |
|
|
'left_field' => 'nid',
|
440 |
|
|
'left_table' => 'webform_submissions',
|
441 |
|
|
);
|
442 |
|
|
// Submission count (node).
|
443 |
|
|
$data['node']['webform_submission_count_node'] = array(
|
444 |
|
|
'group' => t('Webform'),
|
445 |
|
|
'field' => array(
|
446 |
|
|
'title' => t('Webform submission count'),
|
447 |
|
|
'help' => t('The number of webform submissions on this node.'),
|
448 |
|
|
'handler' => 'webform_handler_field_submission_count',
|
449 |
|
|
'count_type' => 'node',
|
450 |
|
|
),
|
451 |
|
|
);
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
// Webform submission of user.
|
455 |
|
|
$data['users']['webform_submission'] = array(
|
456 |
|
|
'title' => t('Webform submission'),
|
457 |
|
|
'help' => t('Webform submissions of the given user.'),
|
458 |
|
|
'real field' => 'uid',
|
459 |
|
|
'relationship' => array(
|
460 |
|
|
'base' => 'webform_submissions',
|
461 |
|
|
'base field' => 'uid',
|
462 |
|
|
'handler' => 'views_handler_relationship',
|
463 |
|
|
'label' => t('Webform Submission'),
|
464 |
|
|
),
|
465 |
|
|
);
|
466 |
|
|
// Submission count (user).
|
467 |
|
|
$data['users']['webform_submission_count_user'] = array(
|
468 |
|
|
'field' => array(
|
469 |
|
|
'title' => t('Webform submission count'),
|
470 |
|
|
'help' => t('The number of webform submissions for this user.'),
|
471 |
|
|
'handler' => 'webform_handler_field_submission_count',
|
472 |
|
|
'count_type' => 'users',
|
473 |
|
|
),
|
474 |
|
|
);
|
475 |
|
|
|
476 |
|
|
// Link for editing the webform.
|
477 |
|
|
$data['node']['webform_edit'] = array(
|
478 |
|
|
'group' => t('Webform'),
|
479 |
|
|
'field' => array(
|
480 |
|
|
'title' => t('Webform edit link'),
|
481 |
|
|
'help' => t('Provide a simple link to edit the webform components and configuration.'),
|
482 |
|
|
'handler' => 'webform_handler_field_node_link_edit',
|
483 |
|
|
),
|
484 |
|
|
);
|
485 |
|
|
|
486 |
|
|
// Link for viewing webform results.
|
487 |
|
|
$data['node']['webform_results'] = array(
|
488 |
|
|
'group' => t('Webform'),
|
489 |
|
|
'field' => array(
|
490 |
|
|
'title' => t('Webform results link'),
|
491 |
|
|
'help' => t('Provide a simple link to view the results of a webform.'),
|
492 |
|
|
'handler' => 'webform_handler_field_node_link_results',
|
493 |
|
|
),
|
494 |
|
|
);
|
495 |
|
|
|
496 |
|
|
// Webform form content.
|
497 |
|
|
$data['node']['webform_form_body'] = array(
|
498 |
|
|
'group' => t('Webform'),
|
499 |
|
|
'field' => array(
|
500 |
|
|
'title' => t('Webform form body'),
|
501 |
|
|
'help' => t('The Webform form body display for this node.'),
|
502 |
|
|
'handler' => 'webform_handler_field_form_body',
|
503 |
|
|
),
|
504 |
|
|
);
|
505 |
a45e4bc1
|
Assos Assos
|
|
506 |
|
|
$data['views']['webform_result'] = array(
|
507 |
|
|
'title' => t('Result summary with an additional token to change the items/page'),
|
508 |
|
|
'help' => t('Shows result summary, for example the items per page, plus links to change the items per page.'),
|
509 |
|
|
'area' => array(
|
510 |
|
|
'handler' => 'webform_handler_area_result_pager',
|
511 |
|
|
),
|
512 |
|
|
);
|
513 |
|
|
|
514 |
85ad3d82
|
Assos Assos
|
}
|
515 |
|
|
|
516 |
|
|
/**
|
517 |
a45e4bc1
|
Assos Assos
|
* Implements hook_views_plugins().
|
518 |
85ad3d82
|
Assos Assos
|
*/
|
519 |
a45e4bc1
|
Assos Assos
|
function webform_views_plugins() {
|
520 |
85ad3d82
|
Assos Assos
|
return array(
|
521 |
a45e4bc1
|
Assos Assos
|
'row' => array(
|
522 |
|
|
'webform_submission' => array(
|
523 |
|
|
'title' => t('Rendered submissions'),
|
524 |
|
|
'help' => t('Display the rendered submission'),
|
525 |
|
|
'handler' => 'webform_views_plugin_row_submission_view',
|
526 |
|
|
'uses options' => TRUE,
|
527 |
|
|
'type' => 'normal',
|
528 |
85ad3d82
|
Assos Assos
|
),
|
529 |
|
|
),
|
530 |
|
|
);
|
531 |
a45e4bc1
|
Assos Assos
|
|
532 |
|
|
return $plugins;
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
/**
|
536 |
|
|
* Implements hook_view_pre_view().
|
537 |
|
|
*/
|
538 |
|
|
function webform_views_pre_view($view, $display_id, $args) {
|
539 |
|
|
$display = $view->display[$display_id];
|
540 |
|
|
$all_fields_id = _webform_view_find_id($view, $display_id, 'field', array('field' => 'webform_all_fields'));
|
541 |
|
|
|
542 |
|
|
if ($all_fields_id !== NULL &&
|
543 |
|
|
!empty($args[0]) && is_numeric($args[0]) && $args[0] > 0 &&
|
544 |
|
|
_webform_view_find_id($view, $display_id, 'argument', array('field' => 'nid', 'table' => 'webform_submissions')) !== NULL &&
|
545 |
|
|
($node = node_load($args[0])) && isset($node->webform['components'])) {
|
546 |
|
|
// This is a view/display that needs its fields expanded. It contains the
|
547 |
|
|
// webform_all_fields field, has a nid argument to the webform_submission
|
548 |
|
|
// table that is a valid node.
|
549 |
|
|
|
550 |
|
|
// Retrieve the display's fields and remove any fields after the 'webform_all_fields' field.
|
551 |
|
|
$fields = $view->get_items('field', $display_id);
|
552 |
|
|
$prototype = $fields[$all_fields_id];
|
553 |
|
|
$field_index = array_flip(array_keys($fields));
|
554 |
|
|
$trailing_fields = array_slice($fields, $field_index[$all_fields_id] + 1, NULL, TRUE);
|
555 |
|
|
$fields = array_slice($fields, 0, $field_index[$all_fields_id], TRUE);
|
556 |
|
|
|
557 |
|
|
// Remove any fields after the webform_add_fields field.
|
558 |
|
|
|
559 |
|
|
$new_columns = array();
|
560 |
|
|
foreach ($node->webform['components'] as $component) {
|
561 |
|
|
if (webform_component_invoke($component['type'], 'table', $component, array('')) !== NULL) {
|
562 |
|
|
$new_id = 'webform_component_' . $component['cid'];
|
563 |
|
|
$new_fields = array(
|
564 |
|
|
array(
|
565 |
|
|
'id' => $new_id,
|
566 |
|
|
'field' => 'value',
|
567 |
|
|
'table' => 'webform_submissions',
|
568 |
|
|
'label' => $component['name'],
|
569 |
|
|
'webform_nid' => $node->nid,
|
570 |
|
|
'webform_cid' => $component['cid'],
|
571 |
|
|
'exclude' => 0,
|
572 |
|
|
) + $prototype,
|
573 |
|
|
);
|
574 |
|
|
if (webform_component_implements($component['type'], 'view_field')) {
|
575 |
|
|
$new_fields = webform_component_invoke($component['type'], 'view_field', $component, $new_fields);
|
576 |
|
|
}
|
577 |
|
|
foreach ($new_fields as $sub_id => $new_field) {
|
578 |
|
|
$field_id = $new_id . ($sub_id ? '_' . $sub_id : '');
|
579 |
|
|
$fields[$field_id] = $new_field;
|
580 |
|
|
$new_columns[$field_id] = $field_id;
|
581 |
|
|
}
|
582 |
|
|
}
|
583 |
|
|
}
|
584 |
|
|
|
585 |
|
|
// Add any trailing fields back in.
|
586 |
|
|
$fields += $trailing_fields;
|
587 |
|
|
|
588 |
|
|
|
589 |
|
|
// Store. Alas, there is no view::set_items() method.
|
590 |
|
|
$display->handler->set_option('fields', $fields);
|
591 |
|
|
|
592 |
|
|
// If this display's style is a table, add columns for click-sorting.
|
593 |
|
|
// Note: Test for count($new_columns) is necessary because prior to PHP 5.6,
|
594 |
|
|
// array_fill requires a positve number of elements to insert.
|
595 |
|
|
if ($display->handler->get_option('style_plugin') == 'table' && count($new_columns)) {
|
596 |
|
|
$style_options = $display->handler->get_option('style_options');
|
597 |
|
|
$style_options['columns'] += $new_columns;
|
598 |
|
|
$style_prototype = isset($style_options['info'][$all_fields_id])
|
599 |
|
|
? $style_options['info'][$all_fields_id]
|
600 |
|
|
: array();
|
601 |
|
|
$style_prototype += array(
|
602 |
|
|
'sortable' => 1,
|
603 |
|
|
'default_sort_order' => 'asc',
|
604 |
|
|
'align' => '',
|
605 |
|
|
'separator' => '',
|
606 |
|
|
'empty_column' => 0,
|
607 |
|
|
);
|
608 |
|
|
$style_options['info'] += array_combine($new_columns, array_fill(1, count($new_columns), $style_prototype));
|
609 |
|
|
$display->handler->set_option('style_options', $style_options);
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
// Reset field handlers cache and rebuild field handlers.
|
613 |
|
|
unset($display->handler->handlers['field']);
|
614 |
|
|
$display->handler->get_handlers('field');
|
615 |
|
|
|
616 |
|
|
// Allow other modules to alter these modifications to the view.
|
617 |
|
|
drupal_alter('webform_view', $view, $display_id, $args);
|
618 |
|
|
}
|
619 |
|
|
}
|
620 |
|
|
|
621 |
|
|
/**
|
622 |
|
|
* Helper; Finds an item by option.
|
623 |
|
|
*/
|
624 |
|
|
function _webform_view_find_id($view, $display_id, $type, $options) {
|
625 |
|
|
foreach ($view->get_items($type, $display_id) as $id => $item) {
|
626 |
|
|
foreach ($options as $option_key => $option_value) {
|
627 |
|
|
if ($item[$option_key] != $option_value) {
|
628 |
|
|
continue 2;
|
629 |
|
|
}
|
630 |
|
|
}
|
631 |
|
|
return $id;
|
632 |
|
|
}
|
633 |
|
|
return NULL;
|
634 |
|
|
}
|
635 |
|
|
|
636 |
|
|
/**
|
637 |
|
|
* Menu callback; Provide a list of Webform nodes for use in autocomplete.
|
638 |
|
|
*/
|
639 |
|
|
function webform_views_autocomplete($string = '') {
|
640 |
|
|
$matches = array();
|
641 |
|
|
if ($string) {
|
642 |
|
|
$or = db_or();
|
643 |
|
|
|
644 |
|
|
// Strings with nid: in them can be used as direct matches.
|
645 |
|
|
$matches = array();
|
646 |
|
|
if (preg_match('/nid:([0-9]+)/', $string, $matches)) {
|
647 |
|
|
$or->condition('n.nid', (int) $matches[1]);
|
648 |
|
|
}
|
649 |
|
|
// Otherwise match on title and optionally indirect NIDs.
|
650 |
|
|
else {
|
651 |
|
|
$or->condition('n.title', '%' . db_like($string) . '%', 'LIKE');
|
652 |
|
|
if (is_numeric($string)) {
|
653 |
|
|
$or->condition('n.nid', (int) $string);
|
654 |
|
|
}
|
655 |
|
|
}
|
656 |
|
|
|
657 |
|
|
$options = array();
|
658 |
|
|
$query = db_select('node', 'n')
|
659 |
|
|
->fields('n', array('nid', 'title'))
|
660 |
|
|
->condition($or);
|
661 |
|
|
$query->innerJoin('webform', 'w', 'w.nid = n.nid');
|
662 |
|
|
$result = $query
|
663 |
|
|
->range(0, 10)
|
664 |
|
|
->execute();
|
665 |
|
|
foreach ($result as $node) {
|
666 |
|
|
$options[$node->title . ' [nid:' . $node->nid . ']'] = check_plain($node->title) . ' [nid:' . $node->nid . ']';
|
667 |
|
|
}
|
668 |
|
|
}
|
669 |
|
|
|
670 |
|
|
drupal_json_output($options);
|
671 |
|
|
}
|
672 |
|
|
|
673 |
|
|
/**
|
674 |
|
|
* Shared form for the Webform submission data field and relationship handler.
|
675 |
|
|
*/
|
676 |
|
|
function _webform_views_options_form(&$form, &$form_state, $nid, $cid) {
|
677 |
|
|
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components');
|
678 |
|
|
$node = $nid ? node_load($nid) : NULL;
|
679 |
|
|
|
680 |
|
|
$form['webform_nid'] = array(
|
681 |
|
|
'#type' => 'textfield',
|
682 |
|
|
'#title' => t('Webform node'),
|
683 |
|
|
'#default_value' => isset($node) ? $node->title . ' [nid:' . $node->nid . ']' : '',
|
684 |
|
|
'#ajax' => array(
|
685 |
|
|
'path' => views_ui_build_form_url($form_state),
|
686 |
|
|
'event' => 'blur',
|
687 |
|
|
),
|
688 |
|
|
'#autocomplete_path' => 'webform/autocomplete',
|
689 |
|
|
'#description' => t('Enter the title or NID of the Webform whose values should be made available.'),
|
690 |
|
|
'#submit' => array('views_ui_config_item_form_submit_temporary'),
|
691 |
|
|
'#executes_submit_callback' => TRUE,
|
692 |
|
|
);
|
693 |
|
|
|
694 |
|
|
$components = array();
|
695 |
|
|
if (isset($node->webform['components'])) {
|
696 |
|
|
$components = $node->webform['components'];
|
697 |
|
|
}
|
698 |
|
|
|
699 |
|
|
$type_options = array();
|
700 |
|
|
foreach (webform_components() as $key => $component) {
|
701 |
|
|
$type_options[$key] = check_plain($component['label']);
|
702 |
|
|
}
|
703 |
|
|
|
704 |
|
|
$options = webform_component_list($node, NULL, 'path', TRUE);
|
705 |
|
|
$form['webform_cid'] = array(
|
706 |
|
|
'#title' => t('Component data'),
|
707 |
|
|
'#type' => 'select',
|
708 |
|
|
'#options' => $options,
|
709 |
|
|
'#default_value' => $cid,
|
710 |
|
|
'#access' => count($components),
|
711 |
|
|
'#description' => t('Select the component whose values should be made available.'),
|
712 |
|
|
);
|
713 |
|
|
}
|
714 |
|
|
|
715 |
|
|
/**
|
716 |
|
|
* Validate handler for webform_views_options_form().
|
717 |
|
|
*/
|
718 |
|
|
function _webform_views_options_validate(&$form, &$form_state) {
|
719 |
|
|
// Just store the checked components of the selected type.
|
720 |
|
|
if (empty($form_state['values']['options']['webform_nid'])) {
|
721 |
|
|
form_error($form['webform_nid'], t('Webform NID is required.'));
|
722 |
|
|
}
|
723 |
|
|
else {
|
724 |
|
|
$nid = preg_replace('/^.*?nid:([0-9]+).*?$/', '$1', $form_state['values']['options']['webform_nid']);
|
725 |
|
|
if (!($nid && ($node = node_load($nid)) && !empty($node->webform['components']))) {
|
726 |
|
|
form_error($form['webform_nid'], t('The specified node is not valid.'));
|
727 |
|
|
}
|
728 |
|
|
}
|
729 |
|
|
}
|
730 |
|
|
|
731 |
|
|
/**
|
732 |
|
|
* Submit handler for webform_views_options_form().
|
733 |
|
|
*/
|
734 |
|
|
function _webform_views_options_submit(&$form, &$form_state) {
|
735 |
|
|
// Save the NID as just the number instead of the title.
|
736 |
|
|
$nid = preg_replace('/^.*?nid:([0-9]+).*?$/', '$1', $form_state['values']['options']['webform_nid']);
|
737 |
|
|
$form_state['values']['options']['webform_nid'] = $nid;
|
738 |
|
|
} |