Project

General

Profile

Paste
Download (2.76 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / webform / views / webform_handler_filter_submission_data.inc @ 389fb945

1
<?php
2

    
3
/**
4
 * Definition of webform_handler_filter_submission_data.
5
 *
6
 * 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

    
12
  /**
13
   * 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
   */
19
  public 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
  public 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
        module_load_include('inc', 'webform', 'includes/webform.components');
52
        $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
  /**
67
   *
68
   */
69
  public function operator_values($values = 1) {
70
    $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
   * Provide a simple textfield for equality.
82
   */
83
  public function value_form(&$form, &$form_state) {
84
    // @todo: Adjust the exposed filter form based on component form.
85
    return parent::value_form($form, $form_state);
86
  }
87

    
88
  /**
89
   *
90
   */
91
  public function op_greater_than($field) {
92
    $this->query->add_where($this->options['group'], $field, $this->value, '>');
93
  }
94

    
95
  /**
96
   *
97
   */
98
  public function op_less_than($field) {
99
    $this->query->add_where($this->options['group'], $field, $this->value, '<');
100
  }
101

    
102
}