Projet

Général

Profil

Révision 5d12d676

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/views/handlers/views_handler_filter_string.inc
12 12
 * @ingroup views_filter_handlers
13 13
 */
14 14
class views_handler_filter_string extends views_handler_filter {
15
  // exposed filter options
16
  var $always_multiple = TRUE;
17 15

  
18
  function option_definition() {
16
  /**
17
   * Exposed filter options.
18
   */
19
  public $always_multiple = TRUE;
20

  
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function option_definition() {
19 25
    $options = parent::option_definition();
20 26

  
21 27
    $options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE);
......
24 30
  }
25 31

  
26 32
  /**
27
   * This kind of construct makes it relatively easy for a child class
28
   * to add or remove functionality by overriding this function and
29
   * adding/removing items from this array.
33
   * This kind of construct makes it relatively easy for a child class to add or
34
   * remove functionality by overriding this function and adding/removing items
35
   * from this array.
30 36
   */
31
  function operators() {
37
  public function operators() {
32 38
    $operators = array(
33 39
      '=' => array(
34 40
        'title' => t('Is equal to'),
......
103 109
        'values' => 1,
104 110
      ),
105 111
    );
106
    // if the definition allows for the empty operator, add it.
112
    // If the definition allows for the empty operator, add it.
107 113
    if (!empty($this->definition['allow empty'])) {
108 114
      $operators += array(
109 115
        'empty' => array(
......
136 142
  }
137 143

  
138 144
  /**
139
   * Build strings from the operators() for 'select' options
145
   * Build strings from the operators() for 'select' options.
140 146
   */
141
  function operator_options($which = 'title') {
147
  public function operator_options($which = 'title') {
142 148
    $options = array();
143 149
    foreach ($this->operators() as $id => $info) {
144 150
      $options[$id] = $info[$which];
......
147 153
    return $options;
148 154
  }
149 155

  
150
  function admin_summary() {
156
  /**
157
   * {@inheritdoc}
158
   */
159
  public function admin_summary() {
151 160
    if ($this->is_a_group()) {
152 161
      return t('grouped');
153 162
    }
......
157 166

  
158 167
    $options = $this->operator_options('short');
159 168
    $output = '';
160
    if(!empty($options[$this->operator])) {
169
    if (!empty($options[$this->operator])) {
161 170
      $output = check_plain($options[$this->operator]);
162 171
    }
163 172
    if (in_array($this->operator, $this->operator_values(1))) {
......
166 175
    return $output;
167 176
  }
168 177

  
169
  function operator_values($values = 1) {
178
  /**
179
   * {@inheritdoc}
180
   */
181
  public function operator_values($values = 1) {
170 182
    $options = array();
171 183
    foreach ($this->operators() as $id => $info) {
172 184
      if (isset($info['values']) && $info['values'] == $values) {
......
178 190
  }
179 191

  
180 192
  /**
181
   * Provide a simple textfield for equality
193
   * Provide a simple textfield for equality.
182 194
   */
183
  function value_form(&$form, &$form_state) {
184
    // We have to make some choices when creating this as an exposed
185
    // filter form. For example, if the operator is locked and thus
186
    // not rendered, we can't render dependencies; instead we only
187
    // render the form items we need.
195
  public function value_form(&$form, &$form_state) {
196
    // We have to make some choices when creating this as an exposed filter
197
    // form. For example, if the operator is locked and thus not rendered, we
198
    // can't render dependencies; instead we only render the form items we need.
188 199
    $which = 'all';
189 200
    if (!empty($form['operator'])) {
190 201
      $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
......
223 234
      // Ensure there is something in the 'value'.
224 235
      $form['value'] = array(
225 236
        '#type' => 'value',
226
        '#value' => NULL
237
        '#value' => NULL,
227 238
      );
228 239
    }
229 240
  }
230 241

  
231
  function operator() {
242
  /**
243
   * {@inheritdoc}
244
   */
245
  public function operator() {
232 246
    return $this->operator == '=' ? 'LIKE' : 'NOT LIKE';
233 247
  }
234 248

  
235 249
  /**
236 250
   * Add this filter to the query.
237 251
   *
238
   * Due to the nature of fapi, the value and the operator have an unintended
239
   * level of indirection. You will find them in $this->operator
240
   * and $this->value respectively.
252
   * Due to the nature of FAPI, the value and the operator have an unintended
253
   * level of indirection. You will find them in $this->operator and
254
   * $this->value respectively.
241 255
   */
242
  function query() {
256
  public function query() {
243 257
    $this->ensure_my_table();
244 258
    $field = "$this->table_alias.$this->real_field";
245 259

  
......
249 263
    }
250 264
  }
251 265

  
252
  function op_equal($field) {
266
  /**
267
   * {@inheritdoc}
268
   */
269
  public function op_equal($field) {
253 270
    $this->query->add_where($this->options['group'], $field, $this->value, $this->operator());
254 271
  }
255 272

  
256
  function op_contains($field) {
273
  /**
274
   * {@inheritdoc}
275
   */
276
  public function op_contains($field) {
257 277
    $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE');
258 278
  }
259 279

  
260
  function op_word($field) {
280
  /**
281
   * {@inheritdoc}
282
   */
283
  public function op_word($field) {
261 284
    $where = $this->operator == 'word' ? db_or() : db_and();
262 285

  
263 286
    // Don't filter on empty strings.
......
267 290

  
268 291
    preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
269 292
    foreach ($matches as $match) {
270
      $phrase = false;
293
      $phrase = FALSE;
271 294
      // Strip off phrase quotes
272 295
      if ($match[2]{0} == '"') {
273 296
        $match[2] = substr($match[2], 1, -1);
274
        $phrase = true;
297
        $phrase = TRUE;
275 298
      }
276 299
      $words = trim($match[2], ',?!();:-');
277 300
      $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
......
285 308
      return;
286 309
    }
287 310

  
288
    // previously this was a call_user_func_array but that's unnecessary
289
    // as views will unpack an array that is a single arg.
311
    // Previously this was a call_user_func_array but that's unnecessary as
312
    // Views will unpack an array that is a single arg.
290 313
    $this->query->add_where($this->options['group'], $where);
291 314
  }
292 315

  
293
  function op_starts($field) {
316
  /**
317
   * {@inheritdoc}
318
   */
319
  public function op_starts($field) {
294 320
    $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE');
295 321
  }
296 322

  
297
  function op_not_starts($field) {
323
  /**
324
   * {@inheritdoc}
325
   */
326
  public function op_not_starts($field) {
298 327
    $this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE');
299 328
  }
300 329

  
301
  function op_ends($field) {
330
  /**
331
   * {@inheritdoc}
332
   */
333
  public function op_ends($field) {
302 334
    $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'LIKE');
303 335
  }
304 336

  
305
  function op_not_ends($field) {
337
  /**
338
   * {@inheritdoc}
339
   */
340
  public function op_not_ends($field) {
306 341
    $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'NOT LIKE');
307 342
  }
308 343

  
309
  function op_not($field) {
344
  /**
345
   * {@inheritdoc}
346
   */
347
  public function op_not($field) {
310 348
    $this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'NOT LIKE');
311 349
  }
312 350

  
313
  function op_shorter($field) {
351
  /**
352
   * {@inheritdoc}
353
   */
354
  public function op_shorter($field) {
314 355
    $placeholder = $this->placeholder();
315 356
    $this->query->add_where_expression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => $this->value));
316 357
  }
317 358

  
318
  function op_longer($field) {
359
  /**
360
   * {@inheritdoc}
361
   */
362
  public function op_longer($field) {
319 363
    $placeholder = $this->placeholder();
320 364
    $this->query->add_where_expression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => $this->value));
321 365
  }
322 366

  
323
  function op_regex($field) {
367
  /**
368
   * {@inheritdoc}
369
   */
370
  public function op_regex($field) {
324 371
    $this->query->add_where($this->options['group'], $field, $this->value, 'RLIKE');
325 372
  }
326 373

  
327
  function op_empty($field) {
374
  /**
375
   * {@inheritdoc}
376
   */
377
  public function op_empty($field) {
328 378
    if ($this->operator == 'empty') {
329 379
      $operator = "IS NULL";
330 380
    }

Formats disponibles : Unified diff