Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / handlers / views_handler_filter_many_to_one.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_filter_many_to_one.
6
 */
7

    
8
/**
9
 * Complex filter to handle filtering for many to one relationships,
10
 * such as terms (many terms per node) or roles (many roles per user).
11
 *
12
 * The construct method needs to be overridden to provide a list of options;
13
 * alternately, the value_form and admin_summary methods need to be overriden
14
 * to provide something that isn't just a select list.
15
 *
16
 * @ingroup views_filter_handlers
17
 */
18
class views_handler_filter_many_to_one extends views_handler_filter_in_operator {
19
  /**
20
   * @var views_many_to_one_helper
21
   *
22
   * Stores the Helper object which handles the many_to_one complexity.
23
   */
24
  var $helper = NULL;
25

    
26
  function init(&$view, &$options) {
27
    parent::init($view, $options);
28
    $this->helper = new views_many_to_one_helper($this);
29
  }
30

    
31
  function option_definition() {
32
    $options = parent::option_definition();
33

    
34
    $options['operator']['default'] = 'or';
35
    $options['value']['default'] = array();
36

    
37
    if (isset($this->helper)) {
38
      $this->helper->option_definition($options);
39
    }
40
    else {
41
      $helper = new views_many_to_one_helper($this);
42
      $helper->option_definition($options);
43
    }
44

    
45
    return $options;
46
  }
47

    
48
  function operators() {
49
    $operators = array(
50
      'or' => array(
51
        'title' => t('Is one of'),
52
        'short' => t('or'),
53
        'short_single' => t('='),
54
        'method' => 'op_helper',
55
        'values' => 1,
56
        'ensure_my_table' => 'helper',
57
      ),
58
      'and' => array(
59
        'title' => t('Is all of'),
60
        'short' => t('and'),
61
        'short_single' => t('='),
62
        'method' => 'op_helper',
63
        'values' => 1,
64
        'ensure_my_table' => 'helper',
65
      ),
66
      'not' => array(
67
        'title' => t('Is none of'),
68
        'short' => t('not'),
69
        'short_single' => t('<>'),
70
        'method' => 'op_helper',
71
        'values' => 1,
72
        'ensure_my_table' => 'helper',
73
      ),
74
    );
75
    // if the definition allows for the empty operator, add it.
76
    if (!empty($this->definition['allow empty'])) {
77
      $operators += array(
78
        'empty' => array(
79
          'title' => t('Is empty (NULL)'),
80
          'method' => 'op_empty',
81
          'short' => t('empty'),
82
          'values' => 0,
83
        ),
84
        'not empty' => array(
85
          'title' => t('Is not empty (NOT NULL)'),
86
          'method' => 'op_empty',
87
          'short' => t('not empty'),
88
          'values' => 0,
89
        ),
90
      );
91
    }
92

    
93
    return $operators;
94
  }
95

    
96
  var $value_form_type = 'select';
97
  function value_form(&$form, &$form_state) {
98
    parent::value_form($form, $form_state);
99

    
100
    if (empty($form_state['exposed'])) {
101
      $this->helper->options_form($form, $form_state);
102
    }
103
  }
104

    
105
  /**
106
   * Override ensure_my_table so we can control how this joins in.
107
   * The operator actually has influence over joining.
108
   */
109
  function ensure_my_table() {
110
    // Defer to helper if the operator specifies it.
111
    $info = $this->operators();
112
    if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') {
113
      return $this->helper->ensure_my_table();
114
    }
115

    
116
    return parent::ensure_my_table();
117
  }
118

    
119
  function op_helper() {
120
    if (empty($this->value)) {
121
      return;
122
    }
123
    $this->helper->add_filter();
124
  }
125
}