Projet

Général

Profil

Paste
Télécharger (4,4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / views / webform_handler_numeric_data.inc @ 8c72e82a

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of handlers for using numeric submission data.
6
 */
7

    
8
/**
9
 * Extended version of the numeric field handler specialized for Webform values.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class webform_handler_field_numeric_data extends views_handler_field_numeric {
14

    
15
  var $formula = NULL;
16

    
17
  /**
18
   * Constructor
19
   */
20
  function construct() {
21
    parent::construct();
22
    $this->formula = TRUE;
23
  }
24

    
25
  /**
26
   * Get the formula for this argument.
27
   *
28
   * $this->ensure_my_table() MUST have been called prior to this.
29
   */
30
  function get_formula() {
31
    return ("(0.0 + $this->table_alias.$this->real_field)");
32
  }
33

    
34
  /**
35
   * Called to add the field to a query.
36
   */
37
  function query() {
38
    $this->ensure_my_table();
39
    // Add the field.
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);
42

    
43
    $this->add_additional_fields();
44
  }
45

    
46
    /**
47
   * Shortcut to get a handler's raw field value.
48
   *
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)
52
   */
53
  function get_field($field = NULL) {
54
    return parent::get_field($this->get_formula());
55
  }
56

    
57
}
58

    
59
/**
60
 * Numeric filter handler that works with Webform numeric submission data.
61
 *
62
 * @ingroup views_filter_handlers
63
 */
64
class webform_handler_filter_numeric_data extends views_handler_filter_numeric {
65

    
66
  /**
67
   * Get the formula for this argument.
68
   *
69
   * $this->ensure_my_table() MUST have been called prior to this.
70
   */
71
  function get_formula() {
72
    return ("(0.0 + $this->table_alias.$this->real_field)");
73
  }
74

    
75
  /**
76
   * Called to add the filter to a query.
77
   */
78
  function query() {
79
    $this->ensure_my_table();
80

    
81
    $info = $this->operators();
82
    if (!empty($info[$this->operator]['method'])) {
83
      $this->{$info[$this->operator]['method']}($this->get_formula());
84
    }
85
  }
86

    
87
  /**
88
   * Adds a simple operator condition to the query.
89
   */
90
  function op_simple($field) {
91
    static $sequence = 1;
92
    $param =  ":value" . $sequence++;
93
    $this->query->add_where_expression($this->options['group'],
94
      $field . $this->operator . $param,
95
      array($param =>  $this->value['value']));
96
  }
97

    
98
  /**
99
   * Adds a between or not-between condition to the query.
100
   */
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']));
109
    }
110
    else {
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']));
114
    }
115
  }
116

    
117
  /**
118
   * Adds an empty or not-empty condition to the query.
119
   */
120
  function op_empty($field) {
121
    if ($this->operator == 'empty') {
122
      $operator = "IS NULL";
123
    }
124
    else {
125
      $operator = "IS NOT NULL";
126
    }
127

    
128
    $this->query->add_where_expression($this->options['group'],
129
                                       "$field $operator");
130
  }
131

    
132
  /**
133
   * Adds a regular expression condition to the query.
134
   */
135
  function op_regex($field) {
136
    static $sequence = 1;
137
    $param =  ":expression" . $sequence++;
138

    
139
    $this->query->add_where_expression($this->options['group'],
140
      "$field RLIKE $param",
141
      array($param => $this->value['value']));
142
  }
143

    
144
}
145

    
146
/**
147
 * Sort handler that works with Webform numeric submission data.
148
 *
149
 * @ingroup views_sort_handlers
150
 */
151
class webform_handler_sort_numeric_data extends views_handler_sort {
152

    
153
  /**
154
   * Get the formula for this sort.
155
   *
156
   * $this->ensure_my_table() MUST have been called prior to this.
157
   */
158
  function get_formula() {
159
    return ("(0.0 + $this->table_alias.$this->real_field)");
160
  }
161

    
162
  /**
163
   * Called to add the sort to a query.
164
   */
165
  function query() {
166
    $this->ensure_my_table();
167
    // Add the field.
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);
171
  }
172

    
173
}