5 * Definition of handlers for using numeric submission data.
9 * Extended version of the numeric field handler specialized for Webform values.
11 * @ingroup views_field_handlers
13 class webform_handler_field_numeric_data extends views_handler_field_numeric {
20 function construct() {
22 $this->formula = TRUE;
26 * Get the formula for this argument.
28 * $this->ensure_my_table() MUST have been called prior to this.
30 function get_formula() {
31 return ("(0.0 + $this->table_alias.$this->real_field)");
35 * Called to add the field to a query.
38 $this->ensure_my_table();
40 $params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
41 $this->field_alias = $this->query->add_field(NULL, $this->get_formula(), $this->table_alias . '_' . $this->field, $params);
43 $this->add_additional_fields();
47 * Shortcut to get a handler's raw field value.
49 * This should be overridden for handlers with formulae or other
50 * non-standard fields. Because this takes an argument, fields
51 * overriding this can just call return parent::get_field($formula)
53 function get_field($field = NULL) {
54 return parent::get_field($this->get_formula());
60 * Numeric filter handler that works with Webform numeric submission data.
62 * @ingroup views_filter_handlers
64 class webform_handler_filter_numeric_data extends views_handler_filter_numeric {
67 * Get the formula for this argument.
69 * $this->ensure_my_table() MUST have been called prior to this.
71 function get_formula() {
72 return ("(0.0 + $this->table_alias.$this->real_field)");
76 * Called to add the filter to a query.
79 $this->ensure_my_table();
81 $info = $this->operators();
82 if (!empty($info[$this->operator]['method'])) {
83 $this->{$info[$this->operator]['method']}($this->get_formula());
88 * Adds a simple operator condition to the query.
90 function op_simple($field) {
92 $param = ":value" . $sequence++;
93 $this->query->add_where_expression($this->options['group'],
94 $field . $this->operator . $param,
95 array($param => $this->value['value']));
99 * Adds a between or not-between condition to the query.
101 function op_between($field) {
102 static $sequence = 1;
103 $min = ":min" . $sequence;
104 $max = ":max" . $sequence++;
105 if ($this->operator == 'between') {
106 $this->query->add_where_expression($this->options['group'],
107 "($min <= $field AND $field <= $max)",
108 array($min => $this->value['min'], $max => $this->value['max']));
111 $this->query->add_where_expression($this->options['group'],
112 "($min > $field OR $field > $max)",
113 array($min => $this->value['min'], $max => $this->value['max']));
118 * Adds an empty or not-empty condition to the query.
120 function op_empty($field) {
121 if ($this->operator == 'empty') {
122 $operator = "IS NULL";
125 $operator = "IS NOT NULL";
128 $this->query->add_where_expression($this->options['group'],
133 * Adds a regular expression condition to the query.
135 function op_regex($field) {
136 static $sequence = 1;
137 $param = ":expression" . $sequence++;
139 $this->query->add_where_expression($this->options['group'],
140 "$field RLIKE $param",
141 array($param => $this->value['value']));
147 * Sort handler that works with Webform numeric submission data.
149 * @ingroup views_sort_handlers
151 class webform_handler_sort_numeric_data extends views_handler_sort {
154 * Get the formula for this sort.
156 * $this->ensure_my_table() MUST have been called prior to this.
158 function get_formula() {
159 return ("(0.0 + $this->table_alias.$this->real_field)");
163 * Called to add the sort to a query.
166 $this->ensure_my_table();
168 $alias = $this->query->add_field(NULL, $this->get_formula(), $this->table_alias . '_' . $this->field . '_sort');
169 // Add the sort for the field using only the alias.
170 $this->query->add_orderby(NULL, NULL, $this->options['order'], $alias);