1 |
a45e4bc1
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of webform_handler_filter_submission_data.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Extended version of the string filter handler specialized for Webform values.
|
10 |
|
|
*
|
11 |
|
|
* @ingroup views_filter_handlers
|
12 |
|
|
*/
|
13 |
|
|
class webform_handler_filter_submission_data extends views_handler_filter_string {
|
14 |
|
|
/**
|
15 |
|
|
* This kind of construct makes it relatively easy for a child class
|
16 |
|
|
* to add or remove functionality by overriding this function and
|
17 |
|
|
* adding/removing items from this array.
|
18 |
|
|
*/
|
19 |
|
|
function operators() {
|
20 |
|
|
$operators = parent::operators();
|
21 |
|
|
|
22 |
|
|
// Add additional operators for date/time ranges.
|
23 |
|
|
$operators['>'] = array(
|
24 |
|
|
'title' => t('Greater than'),
|
25 |
|
|
'short' => t('>'),
|
26 |
|
|
'method' => 'op_greater_than',
|
27 |
|
|
'values' => 1,
|
28 |
|
|
);
|
29 |
|
|
$operators['<'] = array(
|
30 |
|
|
'title' => t('Less than'),
|
31 |
|
|
'short' => t('<'),
|
32 |
|
|
'method' => 'op_less_than',
|
33 |
|
|
'values' => 1,
|
34 |
|
|
);
|
35 |
|
|
|
36 |
|
|
return $operators;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
/**
|
40 |
|
|
* Build strings from the operators() for 'select' options
|
41 |
|
|
*/
|
42 |
|
|
function operator_options($which = 'title') {
|
43 |
|
|
$options = parent::operator_options($which);
|
44 |
|
|
|
45 |
|
|
// Adjust the exposed filter options based on the component selected.
|
46 |
|
|
if ($which === 'title') {
|
47 |
|
|
$nid = $this->view->relationship[$this->options['relationship']]->options['webform_nid'];
|
48 |
|
|
$cid = $this->view->relationship[$this->options['relationship']]->options['webform_cid'];
|
49 |
|
|
|
50 |
|
|
if ($nid && $node = $node = node_load($nid)) {
|
51 |
|
|
$component = $node->webform['components'][$cid];
|
52 |
|
|
if (webform_component_feature($component['type'], 'views_range')) {
|
53 |
|
|
$options['='] = t('Is');
|
54 |
|
|
$options['!='] = t('Is not');
|
55 |
|
|
$options['>'] = t('After');
|
56 |
|
|
$options['<'] = t('Before');
|
57 |
|
|
$options = array_intersect_key($options, array('=' => '=', '!=' => '!=', '>' => '>', '<' => '<'));
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
return $options;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
function operator_values($values = 1) {
|
66 |
|
|
$options = array();
|
67 |
|
|
foreach ($this->operators() as $id => $info) {
|
68 |
|
|
if (isset($info['values']) && $info['values'] == $values) {
|
69 |
|
|
$options[] = $id;
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
return $options;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Provide a simple textfield for equality
|
78 |
|
|
*/
|
79 |
|
|
function value_form(&$form, &$form_state) {
|
80 |
|
|
// TODO: Adjust the exposed filter form based on component form.
|
81 |
|
|
return parent::value_form($form, $form_state);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
function op_greater_than($field) {
|
85 |
|
|
$this->query->add_where($this->options['group'], $field, $this->value, '>');
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
function op_less_than($field) {
|
89 |
|
|
$this->query->add_where($this->options['group'], $field, $this->value, '<');
|
90 |
|
|
}
|
91 |
|
|
} |