Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ldap / ldap_views / handlers / ldap_views_handler_filter_attribute.inc @ 32700c57

1
<?php
2

    
3
/**
4
 * @file
5
 * Basic textfield filter to handle string filtering commands for a generic ldap attribute
6
 * Includes new criterias.
7
 */
8

    
9
/**
10
 *
11
 */
12
class ldap_views_handler_filter_attribute extends ldap_views_handler_filter {
13

    
14
  /**
15
   * Determine if a filter can be exposed.
16
   */
17
  public function can_expose() {
18
    return TRUE;
19
  }
20

    
21
  /**
22
   *
23
   */
24
  public function option_definition() {
25
    $options = parent::option_definition();
26
    $options['attribute_name'] = ['default' => ''];
27
    return $options;
28
  }
29

    
30
  /**
31
   * This kind of construct makes it relatively easy for a child class
32
   * to add or remove functionality by overriding this function and
33
   * adding/removing items from this array.
34
   */
35
  public function operators() {
36
    $operators = [
37
      'exists' => [
38
        'title' => t('Exists'),
39
        'method' => 'op_exists',
40
        'short' => t('exists'),
41
        'values' => 0,
42
      ],
43
      'not exists' => [
44
        'title' => t('Not exists'),
45
        'method' => 'op_exists',
46
        'short' => t('not exists'),
47
        'values' => 0,
48
      ],
49
    ];
50

    
51
    return parent::operators() + $operators;
52
  }
53

    
54
  /**
55
   * Provide a simple textfield for equality.
56
   */
57
  public function value_form(&$form, &$form_state) {
58
    $ldap_data = new LdapQuery(ldap_views_get_qid($this->view));
59

    
60
    if (empty($ldap_data)) {
61
      $form['attribute_name'] = [
62
        '#markup' => 'You must select a valid LDAP search (Advanced::Query settings)',
63
      ];
64
      return;
65
    }
66

    
67
    $options = [];
68
    foreach ($ldap_data->attributes as $attribute) {
69
      $options[$attribute] = $attribute;
70
    }
71

    
72
    if (empty($form_state['exposed'])) {
73
      $form['attribute_name'] = [
74
        '#type' => 'select',
75
        '#title' => t('Attribute name'),
76
        '#description' => t('The attribute name from LDAP response'),
77
        '#options' => $options,
78
        '#default_value' => $this->options['attribute_name'],
79
        '#required' => TRUE,
80
      ];
81
    }
82

    
83
    parent::value_form($form, $form_state);
84
  }
85

    
86
  /**
87
   *
88
   */
89
  public function op_equal($field) {
90
    parent::op_equal($this->options['attribute_name']);
91
  }
92

    
93
  /**
94
   *
95
   */
96
  public function op_contains($field) {
97
    parent::op_contains($this->options['attribute_name']);
98
  }
99

    
100
  /**
101
   *
102
   */
103
  public function op_starts($field) {
104
    parent::op_starts($this->options['attribute_name']);
105
  }
106

    
107
  /**
108
   *
109
   */
110
  public function op_not_starts($field) {
111
    parent::op_not_starts($this->options['attribute_name']);
112
  }
113

    
114
  /**
115
   *
116
   */
117
  public function op_ends($field) {
118
    parent::op_ends($this->options['attribute_name']);
119
  }
120

    
121
  /**
122
   *
123
   */
124
  public function op_not_ends($field) {
125
    parent::op_not_ends($this->options['attribute_name']);
126
  }
127

    
128
  /**
129
   *
130
   */
131
  public function op_not($field) {
132
    parent::op_not($this->options['attribute_name']);
133
  }
134

    
135
  /**
136
   *
137
   */
138
  public function op_greater_eq($field) {
139
    parent::op_greater_eq($this->options['attribute_name']);
140
  }
141

    
142
  /**
143
   *
144
   */
145
  public function op_less_eq($field) {
146
    parent::op_less_eq($this->options['attribute_name']);
147
  }
148

    
149
  /**
150
   *
151
   */
152
  public function op_exists($field) {
153
    parent::op_exists($this->options['attribute_name']);
154
  }
155

    
156
}