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