1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains the submission view row style plugin.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Plugin which performs a webform_submission_render on the resulting object.
|
10
|
*
|
11
|
* Most of the code on this object is in the theme function.
|
12
|
*
|
13
|
* @ingroup views_row_plugins
|
14
|
*/
|
15
|
class webform_views_plugin_row_submission_view extends views_plugin_row {
|
16
|
// Basic properties that let the row style follow relationships.
|
17
|
public $base_table = 'webform_submissions';
|
18
|
public $base_field = 'sid';
|
19
|
|
20
|
// Stores the nodes loaded with pre_render.
|
21
|
private $submissions = array();
|
22
|
private $nodes = array();
|
23
|
|
24
|
function option_definition() {
|
25
|
$options = parent::option_definition();
|
26
|
|
27
|
$options['format'] = array('default' => 'html');
|
28
|
|
29
|
return $options;
|
30
|
}
|
31
|
|
32
|
function options_form(&$form, &$form_state) {
|
33
|
parent::options_form($form, $form_state);
|
34
|
|
35
|
$options = $this->options_form_summary_options();
|
36
|
$form['format'] = array(
|
37
|
'#type' => 'radios',
|
38
|
'#options' => $options,
|
39
|
'#title' => t('Display mode'),
|
40
|
'#default_value' => $this->options['format'],
|
41
|
);
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Return the main options, which are shown in the summary title.
|
46
|
*/
|
47
|
function options_form_summary_options() {
|
48
|
return array(
|
49
|
'html' => t('HTML'),
|
50
|
'text' => t('Plain text'),
|
51
|
);
|
52
|
}
|
53
|
|
54
|
function summary_title() {
|
55
|
$options = $this->options_form_summary_options();
|
56
|
return check_plain($options[$this->options['format']]);
|
57
|
}
|
58
|
|
59
|
function pre_render($values) {
|
60
|
$sids = array();
|
61
|
foreach ($values as $row) {
|
62
|
$sids[] = $row->{$this->field_alias};
|
63
|
}
|
64
|
module_load_include('inc', 'webform', 'includes/webform.submissions');
|
65
|
$this->submissions = $sids ? webform_get_submissions(array('sid' => $sids)) : array();
|
66
|
|
67
|
$nids = array();
|
68
|
foreach ($this->submissions as $sid => $submission) {
|
69
|
$nids[] = $submission->nid;
|
70
|
}
|
71
|
$nids = array_unique($nids);
|
72
|
$this->nodes = $nids ? node_load_multiple($nids) : array();
|
73
|
}
|
74
|
|
75
|
function render($row) {
|
76
|
if (isset($this->submissions[$row->{$this->field_alias}])) {
|
77
|
$submission = $this->submissions[$row->{$this->field_alias}];
|
78
|
$node = $this->nodes[$submission->nid];
|
79
|
$submission->view = $this->view;
|
80
|
$format = $this->options['format'];
|
81
|
$build = webform_submission_render($node, $submission, NULL, $format);
|
82
|
|
83
|
// Add extra theme functions:
|
84
|
$themes = array();
|
85
|
foreach ($build['#theme'] as $hook) {
|
86
|
$themes = array_merge($themes, _views_theme_functions($hook, $this->view, $this->view->display[$this->view->current_display]));
|
87
|
}
|
88
|
$build['#theme'] = $themes;
|
89
|
|
90
|
// Render built submission, and if unsanitized plain text is used, make it safe for display.
|
91
|
$render = drupal_render($build);
|
92
|
return $format == 'html' ? $render : nl2br(check_plain($render));
|
93
|
}
|
94
|
}
|
95
|
}
|