Mercurial > hg > rr-repo
comparison sites/all/modules/views/handlers/views_handler_argument_numeric.inc @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Definition of views_handler_argument_numeric. | |
6 */ | |
7 | |
8 /** | |
9 * Basic argument handler for arguments that are numeric. Incorporates | |
10 * break_phrase. | |
11 * | |
12 * @ingroup views_argument_handlers | |
13 */ | |
14 class views_handler_argument_numeric extends views_handler_argument { | |
15 /** | |
16 * The operator used for the query: or|and. | |
17 * @var string | |
18 */ | |
19 var $operator; | |
20 | |
21 /** | |
22 * The actual value which is used for querying. | |
23 * @var array | |
24 */ | |
25 var $value; | |
26 | |
27 function option_definition() { | |
28 $options = parent::option_definition(); | |
29 | |
30 $options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE); | |
31 $options['not'] = array('default' => FALSE, 'bool' => TRUE); | |
32 | |
33 return $options; | |
34 } | |
35 | |
36 function options_form(&$form, &$form_state) { | |
37 parent::options_form($form, $form_state); | |
38 | |
39 // allow + for or, , for and | |
40 $form['break_phrase'] = array( | |
41 '#type' => 'checkbox', | |
42 '#title' => t('Allow multiple values'), | |
43 '#description' => t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'), | |
44 '#default_value' => !empty($this->options['break_phrase']), | |
45 '#fieldset' => 'more', | |
46 ); | |
47 | |
48 $form['not'] = array( | |
49 '#type' => 'checkbox', | |
50 '#title' => t('Exclude'), | |
51 '#description' => t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'), | |
52 '#default_value' => !empty($this->options['not']), | |
53 '#fieldset' => 'more', | |
54 ); | |
55 } | |
56 | |
57 function title() { | |
58 if (!$this->argument) { | |
59 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); | |
60 } | |
61 | |
62 if (!empty($this->options['break_phrase'])) { | |
63 views_break_phrase($this->argument, $this); | |
64 } | |
65 else { | |
66 $this->value = array($this->argument); | |
67 $this->operator = 'or'; | |
68 } | |
69 | |
70 if (empty($this->value)) { | |
71 return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); | |
72 } | |
73 | |
74 if ($this->value === array(-1)) { | |
75 return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input'); | |
76 } | |
77 | |
78 return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query()); | |
79 } | |
80 | |
81 /** | |
82 * Override for specific title lookups. | |
83 * @return array | |
84 * Returns all titles, if it's just one title it's an array with one entry. | |
85 */ | |
86 function title_query() { | |
87 return $this->value; | |
88 } | |
89 | |
90 function query($group_by = FALSE) { | |
91 $this->ensure_my_table(); | |
92 | |
93 if (!empty($this->options['break_phrase'])) { | |
94 views_break_phrase($this->argument, $this); | |
95 } | |
96 else { | |
97 $this->value = array($this->argument); | |
98 } | |
99 | |
100 $placeholder = $this->placeholder(); | |
101 $null_check = empty($this->options['not']) ? '' : "OR $this->table_alias.$this->real_field IS NULL"; | |
102 | |
103 if (count($this->value) > 1) { | |
104 $operator = empty($this->options['not']) ? 'IN' : 'NOT IN'; | |
105 $this->query->add_where_expression(0, "$this->table_alias.$this->real_field $operator($placeholder) $null_check", array($placeholder => $this->value)); | |
106 } | |
107 else { | |
108 $operator = empty($this->options['not']) ? '=' : '!='; | |
109 $this->query->add_where_expression(0, "$this->table_alias.$this->real_field $operator $placeholder $null_check", array($placeholder => $this->argument)); | |
110 } | |
111 } | |
112 | |
113 function get_sort_name() { | |
114 return t('Numerical', array(), array('context' => 'Sort order')); | |
115 } | |
116 } |