1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Views handler to display the number of submissions in a webform.
|
5
|
*
|
6
|
* Field handler to present the submission count of a node to the user.
|
7
|
*/
|
8
|
class webform_handler_field_submission_count extends views_handler_field {
|
9
|
|
10
|
/**
|
11
|
* {@inheritdoc}
|
12
|
*/
|
13
|
public function construct() {
|
14
|
parent::construct();
|
15
|
$this->count_type = $this->definition['count_type'];
|
16
|
|
17
|
if ($this->count_type == 'node') {
|
18
|
$this->additional_fields['nid'] = 'nid';
|
19
|
$this->additional_fields['type'] = 'type';
|
20
|
}
|
21
|
elseif ($this->count_type == 'users') {
|
22
|
$this->additional_fields['uid'] = 'uid';
|
23
|
}
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* {@inheritdoc}
|
28
|
*/
|
29
|
public function option_definition() {
|
30
|
$options = parent::option_definition();
|
31
|
$options['label'] = array('default' => '# of Submissions', 'translatable' => TRUE);
|
32
|
return $options;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
*/
|
38
|
public function query() {
|
39
|
$this->ensure_my_table();
|
40
|
$this->add_additional_fields();
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
*
|
45
|
*/
|
46
|
public function render($values) {
|
47
|
global $user;
|
48
|
|
49
|
$output = NULL;
|
50
|
if ($this->count_type == 'node' && variable_get('webform_node_' . $values->{$this->aliases['type']}, FALSE)) {
|
51
|
module_load_include('inc', 'webform', 'includes/webform.submissions');
|
52
|
$node = node_load($values->{$this->aliases['nid']});
|
53
|
if (webform_results_access($node, $user)) {
|
54
|
$count = webform_get_submission_count($node->nid);
|
55
|
$output = l($count, "node/$node->nid/webform-results");
|
56
|
}
|
57
|
elseif (webform_submission_access($node, NULL, 'list', $user)) {
|
58
|
$count = webform_get_submission_count($node->nid, $user->uid);
|
59
|
$output = l($count, "node/$node->nid/submissions");
|
60
|
}
|
61
|
else {
|
62
|
$output = webform_get_submission_count($node->nid);
|
63
|
}
|
64
|
}
|
65
|
elseif ($this->count_type == 'users') {
|
66
|
$output = db_select('webform_submissions')
|
67
|
->condition('uid', $values->{$this->aliases['uid']})
|
68
|
->countQuery()->execute()->fetchField();
|
69
|
}
|
70
|
|
71
|
return $output;
|
72
|
}
|
73
|
|
74
|
}
|