1 |
a45e4bc1
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Definition of webform_handler_filter_submission_data.
|
5 |
01f36513
|
Assos Assos
|
*
|
6 |
a45e4bc1
|
Assos Assos
|
* Extended version of the string filter handler specialized for Webform values.
|
7 |
|
|
*
|
8 |
|
|
* @ingroup views_filter_handlers
|
9 |
|
|
*/
|
10 |
|
|
class webform_handler_filter_submission_data extends views_handler_filter_string {
|
11 |
feca1e4a
|
Assos Assos
|
|
12 |
a45e4bc1
|
Assos Assos
|
/**
|
13 |
01f36513
|
Assos Assos
|
* Add to the list of operators.
|
14 |
|
|
*
|
15 |
|
|
* This kind of construct makes it relatively easy for a child class to add or
|
16 |
|
|
* remove functionality by overriding this function and adding/removing items
|
17 |
|
|
* from this array.
|
18 |
a45e4bc1
|
Assos Assos
|
*/
|
19 |
feca1e4a
|
Assos Assos
|
public function operators() {
|
20 |
a45e4bc1
|
Assos Assos
|
$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 |
feca1e4a
|
Assos Assos
|
* Build strings from the operators() for 'select' options.
|
41 |
a45e4bc1
|
Assos Assos
|
*/
|
42 |
feca1e4a
|
Assos Assos
|
public function operator_options($which = 'title') {
|
43 |
a45e4bc1
|
Assos Assos
|
$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 |
feca1e4a
|
Assos Assos
|
module_load_include('inc', 'webform', 'includes/webform.components');
|
52 |
a45e4bc1
|
Assos Assos
|
$component = $node->webform['components'][$cid];
|
53 |
|
|
if (webform_component_feature($component['type'], 'views_range')) {
|
54 |
|
|
$options['='] = t('Is');
|
55 |
|
|
$options['!='] = t('Is not');
|
56 |
|
|
$options['>'] = t('After');
|
57 |
|
|
$options['<'] = t('Before');
|
58 |
|
|
$options = array_intersect_key($options, array('=' => '=', '!=' => '!=', '>' => '>', '<' => '<'));
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
return $options;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
feca1e4a
|
Assos Assos
|
/**
|
67 |
|
|
*
|
68 |
|
|
*/
|
69 |
|
|
public function operator_values($values = 1) {
|
70 |
a45e4bc1
|
Assos Assos
|
$options = array();
|
71 |
|
|
foreach ($this->operators() as $id => $info) {
|
72 |
|
|
if (isset($info['values']) && $info['values'] == $values) {
|
73 |
|
|
$options[] = $id;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
return $options;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
/**
|
81 |
feca1e4a
|
Assos Assos
|
* Provide a simple textfield for equality.
|
82 |
a45e4bc1
|
Assos Assos
|
*/
|
83 |
feca1e4a
|
Assos Assos
|
public function value_form(&$form, &$form_state) {
|
84 |
01f36513
|
Assos Assos
|
// @todo: Adjust the exposed filter form based on component form.
|
85 |
a45e4bc1
|
Assos Assos
|
return parent::value_form($form, $form_state);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
feca1e4a
|
Assos Assos
|
/**
|
89 |
|
|
*
|
90 |
|
|
*/
|
91 |
|
|
public function op_greater_than($field) {
|
92 |
a45e4bc1
|
Assos Assos
|
$this->query->add_where($this->options['group'], $field, $this->value, '>');
|
93 |
|
|
}
|
94 |
|
|
|
95 |
feca1e4a
|
Assos Assos
|
/**
|
96 |
|
|
*
|
97 |
|
|
*/
|
98 |
|
|
public function op_less_than($field) {
|
99 |
a45e4bc1
|
Assos Assos
|
$this->query->add_where($this->options['group'], $field, $this->value, '<');
|
100 |
|
|
}
|
101 |
feca1e4a
|
Assos Assos
|
|
102 |
a45e4bc1
|
Assos Assos
|
} |