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