1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Views hooks implemented for the Webform module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_views_data().
|
10
|
*/
|
11
|
function webform_views_data() {
|
12
|
// Webform table definitions.
|
13
|
$data['webform']['table']['group'] = t('Webform');
|
14
|
$data['webform']['table']['base'] = array(
|
15
|
'field' => 'nid',
|
16
|
'title' => t('Webform nodes'),
|
17
|
'help' => t('Nodes which have webforms.'),
|
18
|
);
|
19
|
$data['webform']['table']['join'] = array(
|
20
|
'node' => array(
|
21
|
'left_field' => 'nid',
|
22
|
'field' => 'nid',
|
23
|
'type' => 'INNER',
|
24
|
),
|
25
|
);
|
26
|
|
27
|
// 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
|
// The field to display in the summary.
|
46
|
'name field' => 'title',
|
47
|
'numeric' => TRUE,
|
48
|
'validate type' => 'nid',
|
49
|
),
|
50
|
);
|
51
|
|
52
|
// Status.
|
53
|
$data['webform']['status'] = array(
|
54
|
'title' => t('Status'),
|
55
|
'help' => t('The open or closed status of a webform.'),
|
56
|
'field' => array(
|
57
|
'handler' => 'webform_handler_field_webform_status',
|
58
|
'click sortable' => TRUE,
|
59
|
),
|
60
|
'filter' => array(
|
61
|
'label' => t('Status'),
|
62
|
'handler' => 'webform_handler_filter_webform_status',
|
63
|
'type' => 'open-closed',
|
64
|
),
|
65
|
'sort' => array(
|
66
|
'handler' => 'views_handler_sort',
|
67
|
),
|
68
|
);
|
69
|
|
70
|
// Submissions table definitions.
|
71
|
$data['webform_submissions']['table']['group'] = t('Webform submissions');
|
72
|
$data['webform_submissions']['table']['base'] = array(
|
73
|
'field' => 'sid',
|
74
|
'title' => t('Webform submissions'),
|
75
|
'help' => t('Submissions generated from Webform forms.'),
|
76
|
);
|
77
|
|
78
|
// Serial number.
|
79
|
$data['webform_submissions']['serial'] = array(
|
80
|
'title' => t('Serial number'),
|
81
|
'help' => t('The serial number of the submission.'),
|
82
|
'field' => array(
|
83
|
'handler' => 'views_handler_field_numeric',
|
84
|
'click sortable' => TRUE,
|
85
|
),
|
86
|
'filter' => array(
|
87
|
'title' => t('Serial number'),
|
88
|
'handler' => 'views_handler_filter_numeric',
|
89
|
),
|
90
|
'sort' => array(
|
91
|
'handler' => 'views_handler_sort',
|
92
|
),
|
93
|
'argument' => array(
|
94
|
'handler' => 'views_handler_argument_numeric',
|
95
|
),
|
96
|
);
|
97
|
|
98
|
// SID.
|
99
|
$data['webform_submissions']['sid'] = array(
|
100
|
'title' => t('Sid'),
|
101
|
'help' => t('The submission ID of the submission.'),
|
102
|
'field' => array(
|
103
|
'handler' => 'views_handler_field_numeric',
|
104
|
'click sortable' => TRUE,
|
105
|
),
|
106
|
'filter' => array(
|
107
|
'title' => t('Sid'),
|
108
|
'handler' => 'views_handler_filter_numeric',
|
109
|
),
|
110
|
'sort' => array(
|
111
|
'handler' => 'views_handler_sort',
|
112
|
),
|
113
|
'argument' => array(
|
114
|
'handler' => 'views_handler_argument_numeric',
|
115
|
),
|
116
|
);
|
117
|
|
118
|
// Submission data as a field loads the entire submission.
|
119
|
$data['webform_submissions']['value'] = array(
|
120
|
'title' => t('Value'),
|
121
|
'help' => t('The value of a component as submitted by a user.'),
|
122
|
'real field' => 'sid',
|
123
|
'group' => t('Webform submission data'),
|
124
|
'field' => array(
|
125
|
'handler' => 'webform_handler_field_submission_data',
|
126
|
'webform_expand' => FALSE,
|
127
|
'click sortable' => TRUE,
|
128
|
),
|
129
|
);
|
130
|
|
131
|
// Expanded to generate a field for every viewable component.
|
132
|
$data['webform_submissions']['webform_all_fields'] = array(
|
133
|
'title' => t('All values'),
|
134
|
'help' => t('Displays all values as submitted by a user.'),
|
135
|
'real field' => 'sid',
|
136
|
'group' => t('Webform submission data'),
|
137
|
'field' => array(
|
138
|
'handler' => 'webform_handler_field_submission_data',
|
139
|
'webform_expand' => TRUE,
|
140
|
'click sortable' => TRUE,
|
141
|
),
|
142
|
);
|
143
|
|
144
|
// NID.
|
145
|
$data['webform_submissions']['nid'] = array(
|
146
|
'title' => t('Node'),
|
147
|
'help' => t('The webform node this submission was generated from.'),
|
148
|
'relationship' => array(
|
149
|
'base' => 'node',
|
150
|
'field' => 'nid',
|
151
|
'handler' => 'views_handler_relationship',
|
152
|
'label' => t('Webform Node'),
|
153
|
),
|
154
|
'filter' => array(
|
155
|
'handler' => 'views_handler_filter_numeric',
|
156
|
),
|
157
|
'sort' => array(
|
158
|
'handler' => 'views_handler_sort',
|
159
|
),
|
160
|
'argument' => array(
|
161
|
'handler' => 'views_handler_argument_node_nid',
|
162
|
// The field to display in the summary.
|
163
|
'name field' => 'title',
|
164
|
'numeric' => TRUE,
|
165
|
'validate type' => 'nid',
|
166
|
),
|
167
|
);
|
168
|
|
169
|
// UID.
|
170
|
$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
|
'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
|
);
|
192
|
|
193
|
// Is draft.
|
194
|
$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
|
// Submitted timestamp.
|
210
|
$data['webform_submissions']['submitted'] = array(
|
211
|
'title' => t('Submitted'),
|
212
|
'help' => t('Timestamp when the form was first saved as draft or submitted.'),
|
213
|
'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
|
'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
|
);
|
268
|
|
269
|
// IP Address (remote_addr).
|
270
|
$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
|
// View submission link.
|
287
|
$data['webform_submissions']['view_submission'] = array(
|
288
|
'title' => t('View link'),
|
289
|
'help' => t('Provide a simple link to view the submission.'),
|
290
|
'real field' => 'serial',
|
291
|
'field' => array(
|
292
|
'handler' => 'webform_handler_field_submission_link',
|
293
|
'click sortable' => TRUE,
|
294
|
'real field' => 'serial',
|
295
|
'link_type' => 'view',
|
296
|
),
|
297
|
'sort' => array(
|
298
|
'handler' => 'views_handler_sort',
|
299
|
),
|
300
|
);
|
301
|
|
302
|
// Edit submission link.
|
303
|
$data['webform_submissions']['edit_submission'] = array(
|
304
|
'title' => t('Edit link'),
|
305
|
'help' => t('Provide a simple link to edit the submission.'),
|
306
|
'real field' => 'serial',
|
307
|
'field' => array(
|
308
|
'handler' => 'webform_handler_field_submission_link',
|
309
|
'click sortable' => TRUE,
|
310
|
'link_type' => 'edit',
|
311
|
),
|
312
|
'sort' => array(
|
313
|
'handler' => 'views_handler_sort',
|
314
|
),
|
315
|
);
|
316
|
|
317
|
// Delete submission link.
|
318
|
$data['webform_submissions']['delete_submission'] = array(
|
319
|
'title' => t('Delete link'),
|
320
|
'help' => t('Provide a simple link to delete the submission.'),
|
321
|
'real field' => 'serial',
|
322
|
'field' => array(
|
323
|
'handler' => 'webform_handler_field_submission_link',
|
324
|
'click sortable' => TRUE,
|
325
|
'link_type' => 'delete',
|
326
|
),
|
327
|
'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
|
// Submission data table definitions.
|
346
|
$data['webform_submitted_data']['table']['group'] = t('Webform submission data');
|
347
|
|
348
|
// Raw access to the submitted values. This usually will only be used for
|
349
|
// sorts and filters, since the 'value' field for the submission will often
|
350
|
// be faster and easier to configure than the raw values.
|
351
|
$data['webform_submitted_data']['data'] = array(
|
352
|
'table' => 'webform_submitted_data',
|
353
|
'title' => t('Data field'),
|
354
|
'help' => t('The value of a component as submitted by a user.'),
|
355
|
'real field' => 'data',
|
356
|
'field' => array(
|
357
|
// Distinguish from the normal value handler.
|
358
|
'title' => t('Value (raw)'),
|
359
|
'help' => t('The raw value from the database as submitted by a user. Use only when needing to sort on a field value.'),
|
360
|
'handler' => 'views_handler_field',
|
361
|
'click sortable' => TRUE,
|
362
|
),
|
363
|
'argument' => array(
|
364
|
'handler' => 'views_handler_argument_string',
|
365
|
),
|
366
|
'filter' => array(
|
367
|
'handler' => 'webform_handler_filter_submission_data',
|
368
|
),
|
369
|
'sort' => array(
|
370
|
'handler' => 'views_handler_sort',
|
371
|
),
|
372
|
);
|
373
|
|
374
|
// Same as 'data', but handled as numeric data.
|
375
|
$data['webform_submitted_data']['data_numeric'] = array(
|
376
|
'table' => 'webform_submitted_data',
|
377
|
'title' => t('Data field (numeric)'),
|
378
|
'help' => t('The numeric value of a component as submitted by a user.'),
|
379
|
'real field' => 'data',
|
380
|
'field' => array(
|
381
|
// Distinguish from the normal value handler.
|
382
|
'title' => t('Numeric value (raw)'),
|
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
|
);
|
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
|
// Webform submission of user.
|
454
|
$data['users']['webform_submission'] = array(
|
455
|
'title' => t('Webform submission'),
|
456
|
'help' => t('Webform submissions of the given user.'),
|
457
|
'real field' => 'uid',
|
458
|
'relationship' => array(
|
459
|
'base' => 'webform_submissions',
|
460
|
'base field' => 'uid',
|
461
|
'handler' => 'views_handler_relationship',
|
462
|
'label' => t('Webform Submission'),
|
463
|
),
|
464
|
);
|
465
|
// Submission count (user).
|
466
|
$data['users']['webform_submission_count_user'] = array(
|
467
|
'field' => array(
|
468
|
'title' => t('Webform submission count'),
|
469
|
'help' => t('The number of webform submissions for this user.'),
|
470
|
'handler' => 'webform_handler_field_submission_count',
|
471
|
'count_type' => 'users',
|
472
|
),
|
473
|
);
|
474
|
|
475
|
// Link for editing the webform.
|
476
|
$data['node']['webform_edit'] = array(
|
477
|
'group' => t('Webform'),
|
478
|
'field' => array(
|
479
|
'title' => t('Webform edit link'),
|
480
|
'help' => t('Provide a simple link to edit the webform components and configuration.'),
|
481
|
'handler' => 'webform_handler_field_node_link_edit',
|
482
|
),
|
483
|
);
|
484
|
|
485
|
// Link for viewing webform results.
|
486
|
$data['node']['webform_results'] = array(
|
487
|
'group' => t('Webform'),
|
488
|
'field' => array(
|
489
|
'title' => t('Webform results link'),
|
490
|
'help' => t('Provide a simple link to view the results of a webform.'),
|
491
|
'handler' => 'webform_handler_field_node_link_results',
|
492
|
),
|
493
|
);
|
494
|
|
495
|
// Webform form content.
|
496
|
$data['node']['webform_form_body'] = array(
|
497
|
'group' => t('Webform'),
|
498
|
'field' => array(
|
499
|
'title' => t('Webform form body'),
|
500
|
'help' => t('The Webform form body display for this node.'),
|
501
|
'handler' => 'webform_handler_field_form_body',
|
502
|
),
|
503
|
);
|
504
|
|
505
|
$data['views']['webform_result'] = array(
|
506
|
'title' => t('Result summary with an additional token to change the items/page'),
|
507
|
'help' => t('Shows result summary, for example the items per page, plus links to change the items per page.'),
|
508
|
'area' => array(
|
509
|
'handler' => 'webform_handler_area_result_pager',
|
510
|
),
|
511
|
);
|
512
|
|
513
|
}
|
514
|
|
515
|
/**
|
516
|
* Implements hook_views_plugins().
|
517
|
*/
|
518
|
function webform_views_plugins() {
|
519
|
return array(
|
520
|
'row' => array(
|
521
|
'webform_submission' => array(
|
522
|
'title' => t('Rendered submissions'),
|
523
|
'help' => t('Display the rendered submission'),
|
524
|
'handler' => 'webform_views_plugin_row_submission_view',
|
525
|
'uses options' => TRUE,
|
526
|
'type' => 'normal',
|
527
|
),
|
528
|
),
|
529
|
);
|
530
|
}
|
531
|
|
532
|
/**
|
533
|
* Implements hook_view_pre_view().
|
534
|
*/
|
535
|
function webform_views_pre_view($view, $display_id, $args) {
|
536
|
$display = $view->display[$display_id];
|
537
|
$all_fields_id = _webform_view_find_id($view, $display_id, 'field', array('field' => 'webform_all_fields'));
|
538
|
|
539
|
if ($all_fields_id !== NULL &&
|
540
|
!empty($args[0]) && is_numeric($args[0]) && $args[0] > 0 &&
|
541
|
_webform_view_find_id($view, $display_id, 'argument', array('field' => 'nid', 'table' => 'webform_submissions')) !== NULL &&
|
542
|
($node = node_load($args[0])) && isset($node->webform['components'])) {
|
543
|
// This is a view/display that needs its fields expanded. It contains the
|
544
|
// webform_all_fields field, has a nid argument to the webform_submission
|
545
|
// table that is a valid node. Retrieve the display's fields and remove any
|
546
|
// fields after the 'webform_all_fields' field.
|
547
|
$fields = $view->get_items('field', $display_id);
|
548
|
$prototype = $fields[$all_fields_id];
|
549
|
$field_index = array_flip(array_keys($fields));
|
550
|
$trailing_fields = array_slice($fields, $field_index[$all_fields_id] + 1, NULL, TRUE);
|
551
|
$fields = array_slice($fields, 0, $field_index[$all_fields_id], TRUE);
|
552
|
|
553
|
// Remove any fields after the webform_add_fields field.
|
554
|
$new_columns = array();
|
555
|
foreach ($node->webform['components'] as $component) {
|
556
|
if (webform_component_invoke($component['type'], 'table', $component, array('')) !== NULL) {
|
557
|
$new_id = 'webform_component_' . $component['cid'];
|
558
|
$new_fields = array(
|
559
|
array(
|
560
|
'id' => $new_id,
|
561
|
'field' => 'value',
|
562
|
'table' => 'webform_submissions',
|
563
|
'label' => $component['name'],
|
564
|
'webform_nid' => $node->nid,
|
565
|
'webform_cid' => $component['cid'],
|
566
|
'exclude' => 0,
|
567
|
) + $prototype,
|
568
|
);
|
569
|
if (webform_component_implements($component['type'], 'view_field')) {
|
570
|
$new_fields = webform_component_invoke($component['type'], 'view_field', $component, $new_fields);
|
571
|
}
|
572
|
foreach ($new_fields as $sub_id => $new_field) {
|
573
|
$field_id = $new_id . ($sub_id ? '_' . $sub_id : '');
|
574
|
$fields[$field_id] = $new_field;
|
575
|
$new_columns[$field_id] = $field_id;
|
576
|
}
|
577
|
}
|
578
|
}
|
579
|
|
580
|
// Add any trailing fields back in.
|
581
|
$fields += $trailing_fields;
|
582
|
|
583
|
// Store. Alas, there is no view::set_items() method.
|
584
|
$display->handler->set_option('fields', $fields);
|
585
|
|
586
|
// If this display's style is a table, add columns for click-sorting.
|
587
|
// Note: Test for count($new_columns) is necessary because prior to PHP 5.6,
|
588
|
// array_fill requires a positive number of elements to insert.
|
589
|
if ($display->handler->get_option('style_plugin') == 'table' && count($new_columns)) {
|
590
|
$style_options = $display->handler->get_option('style_options');
|
591
|
$style_options['columns'] += $new_columns;
|
592
|
$style_prototype = isset($style_options['info'][$all_fields_id])
|
593
|
? $style_options['info'][$all_fields_id]
|
594
|
: array();
|
595
|
$style_prototype += array(
|
596
|
'sortable' => 1,
|
597
|
'default_sort_order' => 'asc',
|
598
|
'align' => '',
|
599
|
'separator' => '',
|
600
|
'empty_column' => 0,
|
601
|
);
|
602
|
$style_options['info'] += array_combine($new_columns, array_fill(1, count($new_columns), $style_prototype));
|
603
|
$display->handler->set_option('style_options', $style_options);
|
604
|
}
|
605
|
|
606
|
// Reset field handlers cache and rebuild field handlers.
|
607
|
unset($display->handler->handlers['field']);
|
608
|
$display->handler->get_handlers('field');
|
609
|
|
610
|
// Allow other modules to alter these modifications to the view.
|
611
|
drupal_alter('webform_view', $view, $display_id, $args);
|
612
|
}
|
613
|
}
|
614
|
|
615
|
/**
|
616
|
* Helper; Finds an item by option.
|
617
|
*/
|
618
|
function _webform_view_find_id($view, $display_id, $type, $options) {
|
619
|
foreach ($view->get_items($type, $display_id) as $id => $item) {
|
620
|
foreach ($options as $option_key => $option_value) {
|
621
|
if ($item[$option_key] != $option_value) {
|
622
|
continue 2;
|
623
|
}
|
624
|
}
|
625
|
return $id;
|
626
|
}
|
627
|
return NULL;
|
628
|
}
|
629
|
|
630
|
/**
|
631
|
* Menu callback; Provide a list of Webform nodes for use in autocomplete.
|
632
|
*/
|
633
|
function webform_views_autocomplete($string = '') {
|
634
|
if ($string) {
|
635
|
$or = db_or();
|
636
|
|
637
|
// Strings with nid: in them can be used as direct matches.
|
638
|
$matches = array();
|
639
|
if (preg_match('/nid:([0-9]+)/', $string, $matches)) {
|
640
|
$or->condition('n.nid', (int) $matches[1]);
|
641
|
}
|
642
|
// Otherwise match on title and optionally indirect NIDs.
|
643
|
else {
|
644
|
$or->condition('n.title', '%' . db_like($string) . '%', 'LIKE');
|
645
|
if (is_numeric($string)) {
|
646
|
$or->condition('n.nid', (int) $string);
|
647
|
}
|
648
|
}
|
649
|
|
650
|
$options = array();
|
651
|
$query = db_select('node', 'n')
|
652
|
->fields('n', array('nid', 'title'))
|
653
|
->condition($or);
|
654
|
$query->innerJoin('webform', 'w', 'w.nid = n.nid');
|
655
|
$result = $query
|
656
|
->range(0, 10)
|
657
|
->execute();
|
658
|
foreach ($result as $node) {
|
659
|
$options[$node->title . ' [nid:' . $node->nid . ']'] = check_plain($node->title) . ' [nid:' . $node->nid . ']';
|
660
|
}
|
661
|
}
|
662
|
|
663
|
drupal_json_output($options);
|
664
|
}
|
665
|
|
666
|
/**
|
667
|
* Shared form for the Webform submission data field and relationship handler.
|
668
|
*/
|
669
|
function _webform_views_options_form(&$form, &$form_state, $nid, $cid) {
|
670
|
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components');
|
671
|
$node = $nid ? node_load($nid) : NULL;
|
672
|
|
673
|
$form['webform_nid'] = array(
|
674
|
'#type' => 'textfield',
|
675
|
'#title' => t('Webform node'),
|
676
|
'#default_value' => isset($node) ? $node->title . ' [nid:' . $node->nid . ']' : '',
|
677
|
'#ajax' => array(
|
678
|
'path' => views_ui_build_form_url($form_state),
|
679
|
'event' => 'blur',
|
680
|
),
|
681
|
'#autocomplete_path' => 'webform/autocomplete',
|
682
|
'#description' => t('Enter the title or NID of the Webform whose values should be made available.'),
|
683
|
'#submit' => array('views_ui_config_item_form_submit_temporary'),
|
684
|
'#executes_submit_callback' => TRUE,
|
685
|
);
|
686
|
|
687
|
$components = array();
|
688
|
if (isset($node->webform['components'])) {
|
689
|
$components = $node->webform['components'];
|
690
|
}
|
691
|
|
692
|
$type_options = array();
|
693
|
foreach (webform_components() as $key => $component) {
|
694
|
$type_options[$key] = check_plain($component['label']);
|
695
|
}
|
696
|
|
697
|
$options = webform_component_list($node, NULL, 'path', TRUE);
|
698
|
$form['webform_cid'] = array(
|
699
|
'#title' => t('Component data'),
|
700
|
'#type' => 'select',
|
701
|
'#options' => $options,
|
702
|
'#default_value' => $cid,
|
703
|
'#access' => count($components),
|
704
|
'#description' => t('Select the component whose values should be made available.'),
|
705
|
);
|
706
|
}
|
707
|
|
708
|
/**
|
709
|
* Validate handler for webform_views_options_form().
|
710
|
*/
|
711
|
function _webform_views_options_validate(&$form, &$form_state) {
|
712
|
// Just store the checked components of the selected type.
|
713
|
if (empty($form_state['values']['options']['webform_nid'])) {
|
714
|
form_error($form['webform_nid'], t('Webform NID is required.'));
|
715
|
}
|
716
|
else {
|
717
|
$nid = preg_replace('/^.*?nid:([0-9]+).*?$/', '$1', $form_state['values']['options']['webform_nid']);
|
718
|
if (!($nid && ($node = node_load($nid)) && !empty($node->webform['components']))) {
|
719
|
form_error($form['webform_nid'], t('The specified node is not valid.'));
|
720
|
}
|
721
|
}
|
722
|
}
|
723
|
|
724
|
/**
|
725
|
* Submit handler for webform_views_options_form().
|
726
|
*/
|
727
|
function _webform_views_options_submit(&$form, &$form_state) {
|
728
|
// Save the NID as just the number instead of the title.
|
729
|
$nid = preg_replace('/^.*?nid:([0-9]+).*?$/', '$1', $form_state['values']['options']['webform_nid']);
|
730
|
$form_state['values']['options']['webform_nid'] = $nid;
|
731
|
}
|