Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/handlers/views_handler_filter_in_operator.inc | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Simple filter to handle matching of multiple options selectable via checkboxes
|
|
9 |
* Simple filter to handle matching of multiple options using checkboxes.
|
|
10 | 10 |
* |
11 | 11 |
* Definition items: |
12 |
* - options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used. |
|
12 |
* - options callback: The function to call in order to generate the value |
|
13 |
* options. If omitted, the options 'Yes' and 'No' will be used. |
|
13 | 14 |
* - options arguments: An array of arguments to pass to the options callback. |
14 | 15 |
* |
15 | 16 |
* @ingroup views_filter_handlers |
16 | 17 |
*/ |
17 | 18 |
class views_handler_filter_in_operator extends views_handler_filter { |
18 |
var $value_form_type = 'checkboxes'; |
|
19 |
|
|
20 |
/** |
|
21 |
* |
|
22 |
*/ |
|
23 |
public $value_form_type = 'checkboxes'; |
|
19 | 24 |
|
20 | 25 |
/** |
21 | 26 |
* @var array |
22 | 27 |
* Stores all operations which are available on the form. |
23 | 28 |
*/ |
24 |
var $value_options = NULL;
|
|
29 |
public $value_options = NULL;
|
|
25 | 30 |
|
26 |
function construct() { |
|
31 |
/** |
|
32 |
* {@inheritdoc} |
|
33 |
*/ |
|
34 |
public function construct() { |
|
27 | 35 |
parent::construct(); |
28 | 36 |
$this->value_title = t('Options'); |
29 | 37 |
$this->value_options = NULL; |
... | ... | |
40 | 48 |
* @return |
41 | 49 |
* Return the stored values in $this->value_options if someone expects it. |
42 | 50 |
*/ |
43 |
function get_value_options() { |
|
51 |
public function get_value_options() {
|
|
44 | 52 |
if (isset($this->value_options)) { |
45 | 53 |
return; |
46 | 54 |
} |
... | ... | |
60 | 68 |
return $this->value_options; |
61 | 69 |
} |
62 | 70 |
|
63 |
function expose_options() { |
|
71 |
/** |
|
72 |
* {@inheritdoc} |
|
73 |
*/ |
|
74 |
public function expose_options() { |
|
64 | 75 |
parent::expose_options(); |
65 | 76 |
$this->options['expose']['reduce'] = FALSE; |
66 | 77 |
} |
67 | 78 |
|
68 |
function expose_form(&$form, &$form_state) { |
|
79 |
/** |
|
80 |
* {@inheritdoc} |
|
81 |
*/ |
|
82 |
public function expose_form(&$form, &$form_state) { |
|
69 | 83 |
parent::expose_form($form, $form_state); |
70 | 84 |
$form['expose']['reduce'] = array( |
71 | 85 |
'#type' => 'checkbox', |
72 | 86 |
'#title' => t('Limit list to selected items'), |
73 | 87 |
'#description' => t('If checked, the only items presented to the user will be the ones selected here.'), |
74 |
'#default_value' => !empty($this->options['expose']['reduce']), // safety |
|
88 |
// Safety. |
|
89 |
'#default_value' => !empty($this->options['expose']['reduce']), |
|
75 | 90 |
); |
76 | 91 |
} |
77 | 92 |
|
78 |
function option_definition() { |
|
93 |
/** |
|
94 |
* {@inheritdoc} |
|
95 |
*/ |
|
96 |
public function option_definition() { |
|
79 | 97 |
$options = parent::option_definition(); |
80 | 98 |
|
81 | 99 |
$options['operator']['default'] = 'in'; |
... | ... | |
86 | 104 |
} |
87 | 105 |
|
88 | 106 |
/** |
89 |
* This kind of construct makes it relatively easy for a child class |
|
90 |
* to add or remove functionality by overriding this function and
|
|
91 |
* adding/removing items from this array.
|
|
107 |
* This kind of construct makes it relatively easy for a child class to add or
|
|
108 |
* remove functionality by overriding this function and adding/removing items
|
|
109 |
* from this array. |
|
92 | 110 |
*/ |
93 |
function operators() { |
|
111 |
public function operators() {
|
|
94 | 112 |
$operators = array( |
95 | 113 |
'in' => array( |
96 | 114 |
'title' => t('Is one of'), |
... | ... | |
129 | 147 |
} |
130 | 148 |
|
131 | 149 |
/** |
132 |
* Build strings from the operators() for 'select' options |
|
150 |
* Build strings from the operators() for 'select' options.
|
|
133 | 151 |
*/ |
134 |
function operator_options($which = 'title') { |
|
152 |
public function operator_options($which = 'title') {
|
|
135 | 153 |
$options = array(); |
136 | 154 |
foreach ($this->operators() as $id => $info) { |
137 | 155 |
$options[$id] = $info[$which]; |
... | ... | |
140 | 158 |
return $options; |
141 | 159 |
} |
142 | 160 |
|
143 |
function operator_values($values = 1) { |
|
161 |
/** |
|
162 |
* {@inheritdoc} |
|
163 |
*/ |
|
164 |
public function operator_values($values = 1) { |
|
144 | 165 |
$options = array(); |
145 | 166 |
foreach ($this->operators() as $id => $info) { |
146 | 167 |
if (isset($info['values']) && $info['values'] == $values) { |
... | ... | |
151 | 172 |
return $options; |
152 | 173 |
} |
153 | 174 |
|
154 |
function value_form(&$form, &$form_state) { |
|
175 |
/** |
|
176 |
* {@inheritdoc} |
|
177 |
*/ |
|
178 |
public function value_form(&$form, &$form_state) { |
|
155 | 179 |
$form['value'] = array(); |
156 | 180 |
$options = array(); |
157 | 181 |
|
... | ... | |
172 | 196 |
$identifier = $this->options['expose']['identifier']; |
173 | 197 |
|
174 | 198 |
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) { |
175 |
// exposed and locked.
|
|
199 |
// Exposed and locked.
|
|
176 | 200 |
$which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none'; |
177 | 201 |
} |
178 | 202 |
else { |
... | ... | |
229 | 253 |
/** |
230 | 254 |
* When using exposed filters, we may be required to reduce the set. |
231 | 255 |
*/ |
232 |
function reduce_value_options($input = NULL) { |
|
256 |
public function reduce_value_options($input = NULL) {
|
|
233 | 257 |
if (!isset($input)) { |
234 | 258 |
$input = $this->value_options; |
235 | 259 |
} |
... | ... | |
257 | 281 |
return $options; |
258 | 282 |
} |
259 | 283 |
|
260 |
function accept_exposed_input($input) { |
|
284 |
/** |
|
285 |
* {@inheritdoc} |
|
286 |
*/ |
|
287 |
public function accept_exposed_input($input) { |
|
261 | 288 |
// A very special override because the All state for this type of |
262 |
// filter could have a default:
|
|
289 |
// filter could have a default.
|
|
263 | 290 |
if (empty($this->options['exposed'])) { |
264 | 291 |
return TRUE; |
265 | 292 |
} |
... | ... | |
276 | 303 |
return parent::accept_exposed_input($input); |
277 | 304 |
} |
278 | 305 |
|
279 |
function value_submit($form, &$form_state) { |
|
306 |
/** |
|
307 |
* {@inheritdoc} |
|
308 |
*/ |
|
309 |
public function value_submit($form, &$form_state) { |
|
280 | 310 |
// Drupal's FAPI system automatically puts '0' in for any checkbox that |
281 | 311 |
// was not set, and the key to the checkbox if it is set. |
282 | 312 |
// Unfortunately, this means that if the key to that checkbox is 0, |
... | ... | |
289 | 319 |
$form_state['values']['options']['value'] = $form['value']['#value']; |
290 | 320 |
} |
291 | 321 |
|
292 |
function admin_summary() { |
|
322 |
/** |
|
323 |
* {@inheritdoc} |
|
324 |
*/ |
|
325 |
public function admin_summary() { |
|
293 | 326 |
if ($this->is_a_group()) { |
294 | 327 |
return t('grouped'); |
295 | 328 |
} |
... | ... | |
317 | 350 |
if (count($this->value) == 0) { |
318 | 351 |
$values = t('Unknown'); |
319 | 352 |
} |
320 |
else if (count($this->value) == 1) {
|
|
353 |
elseif (count($this->value) == 1) { |
|
321 | 354 |
// If any, use the 'single' short name of the operator instead. |
322 | 355 |
if (isset($info[$this->operator]['short_single'])) { |
323 | 356 |
$operator = check_plain($info[$this->operator]['short_single']); |
... | ... | |
351 | 384 |
return $operator . (($values !== '') ? ' ' . $values : ''); |
352 | 385 |
} |
353 | 386 |
|
354 |
function query() { |
|
387 |
/** |
|
388 |
* {@inheritdoc} |
|
389 |
*/ |
|
390 |
public function query() { |
|
355 | 391 |
$info = $this->operators(); |
356 | 392 |
if (!empty($info[$this->operator]['method'])) { |
357 | 393 |
$this->{$info[$this->operator]['method']}(); |
358 | 394 |
} |
359 | 395 |
} |
360 | 396 |
|
361 |
function op_simple() { |
|
397 |
/** |
|
398 |
* {@inheritdoc} |
|
399 |
*/ |
|
400 |
public function op_simple() { |
|
362 | 401 |
if (empty($this->value)) { |
363 | 402 |
return; |
364 | 403 |
} |
... | ... | |
369 | 408 |
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", array_values($this->value), $this->operator); |
370 | 409 |
} |
371 | 410 |
|
372 |
function op_empty() { |
|
411 |
/** |
|
412 |
* {@inheritdoc} |
|
413 |
*/ |
|
414 |
public function op_empty() { |
|
373 | 415 |
$this->ensure_my_table(); |
374 | 416 |
if ($this->operator == 'empty') { |
375 | 417 |
$operator = "IS NULL"; |
... | ... | |
381 | 423 |
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", NULL, $operator); |
382 | 424 |
} |
383 | 425 |
|
384 |
function validate() { |
|
426 |
/** |
|
427 |
* {@inheritdoc} |
|
428 |
*/ |
|
429 |
public function validate() { |
|
385 | 430 |
$this->get_value_options(); |
386 | 431 |
$errors = array(); |
387 | 432 |
|
... | ... | |
396 | 441 |
} |
397 | 442 |
if (is_array($this->value)) { |
398 | 443 |
if (!isset($this->value_options)) { |
399 |
// Don't validate if there are none value options provided, for example for special handlers. |
|
444 |
// Don't validate if there are none value options provided, for example |
|
445 |
// for special handlers. |
|
400 | 446 |
return $errors; |
401 | 447 |
} |
402 | 448 |
if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) { |
403 |
// Don't validate if the field is exposed and no default value is provided. |
|
449 |
// Don't validate if the field is exposed and no default value is |
|
450 |
// provided. |
|
404 | 451 |
return $errors; |
405 | 452 |
} |
406 | 453 |
|
... | ... | |
423 | 470 |
} |
424 | 471 |
return $errors; |
425 | 472 |
} |
473 |
|
|
426 | 474 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules