Révision 5d12d676
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/views/modules/search/views_handler_filter_search.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Contains a search filter handler.
|
|
5 |
* Definition of views_handler_filter_search.
|
|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
... | ... | |
11 | 11 |
* @ingroup views_filter_handlers |
12 | 12 |
*/ |
13 | 13 |
class views_handler_filter_search extends views_handler_filter { |
14 |
var $always_multiple = TRUE; |
|
14 |
|
|
15 |
/** |
|
16 |
* |
|
17 |
*/ |
|
18 |
public $always_multiple = TRUE; |
|
15 | 19 |
|
16 | 20 |
/** |
17 | 21 |
* Stores a viewsSearchQuery object to be able to use the search.module "api". |
18 | 22 |
* |
19 | 23 |
* @var viewsSearchQuery |
20 | 24 |
*/ |
21 |
var $search_query = NULL;
|
|
25 |
public $search_query = NULL;
|
|
22 | 26 |
|
23 | 27 |
/** |
24 | 28 |
* Checks if the search query has been parsed. |
25 | 29 |
*/ |
26 |
var $parsed = FALSE;
|
|
30 |
public $parsed = FALSE;
|
|
27 | 31 |
|
28 |
function option_definition() { |
|
32 |
/** |
|
33 |
* {@inheritdoc} |
|
34 |
*/ |
|
35 |
public function option_definition() { |
|
29 | 36 |
$options = parent::option_definition(); |
30 | 37 |
|
31 | 38 |
$options['operator']['default'] = 'optional'; |
... | ... | |
35 | 42 |
} |
36 | 43 |
|
37 | 44 |
/** |
38 |
* Overrides views_handler_filter::options_form(). |
|
39 |
* |
|
40 |
* Add an option to remove search scores from the query. |
|
45 |
* {@inheritdoc} |
|
41 | 46 |
*/ |
42 |
function options_form(&$form, &$form_state) { |
|
47 |
public function options_form(&$form, &$form_state) {
|
|
43 | 48 |
parent::options_form($form, $form_state); |
44 | 49 |
|
50 |
// Add an option to remove search scores from the query. |
|
45 | 51 |
$form['remove_score'] = array( |
46 | 52 |
'#type' => 'checkbox', |
47 | 53 |
'#title' => t('Remove search score'), |
... | ... | |
50 | 56 |
); |
51 | 57 |
} |
52 | 58 |
|
53 |
|
|
54 | 59 |
/** |
55 |
* Provide simple equality operator |
|
60 |
* Provide simple equality operator.
|
|
56 | 61 |
*/ |
57 |
function operator_form(&$form, &$form_state) { |
|
62 |
public function operator_form(&$form, &$form_state) {
|
|
58 | 63 |
$form['operator'] = array( |
59 | 64 |
'#type' => 'radios', |
60 | 65 |
'#title' => t('On empty input'), |
... | ... | |
67 | 72 |
} |
68 | 73 |
|
69 | 74 |
/** |
70 |
* Provide a simple textfield for equality |
|
75 |
* Provide a simple textfield for equality.
|
|
71 | 76 |
*/ |
72 |
function value_form(&$form, &$form_state) { |
|
77 |
public function value_form(&$form, &$form_state) {
|
|
73 | 78 |
$form['value'] = array( |
74 | 79 |
'#type' => 'textfield', |
75 | 80 |
'#size' => 15, |
... | ... | |
82 | 87 |
/** |
83 | 88 |
* Validate the options form. |
84 | 89 |
*/ |
85 |
function exposed_validate(&$form, &$form_state) { |
|
90 |
public function exposed_validate(&$form, &$form_state) {
|
|
86 | 91 |
if (!isset($this->options['expose']['identifier'])) { |
87 | 92 |
return; |
88 | 93 |
} |
... | ... | |
97 | 102 |
} |
98 | 103 |
|
99 | 104 |
/** |
100 |
* Take sure that parseSearchExpression is runned and everything is set up for it.
|
|
105 |
* Make sure that parseSearchExpression is run and everything is set up.
|
|
101 | 106 |
* |
102 |
* @param $input |
|
107 |
* @param string $input
|
|
103 | 108 |
* The search phrase which was input by the user. |
104 | 109 |
*/ |
105 |
function query_parse_search_expression($input) { |
|
110 |
public function query_parse_search_expression($input) {
|
|
106 | 111 |
if (!isset($this->search_query)) { |
107 | 112 |
$this->parsed = TRUE; |
108 | 113 |
$this->search_query = db_select('search_index', 'i', array('target' => 'slave'))->extend('viewsSearchQuery'); |
... | ... | |
118 | 123 |
* level of indirection. You will find them in $this->operator |
119 | 124 |
* and $this->value respectively. |
120 | 125 |
*/ |
121 |
function query() { |
|
126 |
public function query() {
|
|
122 | 127 |
// Since attachment views don't validate the exposed input, parse the search |
123 | 128 |
// expression if required. |
124 | 129 |
if (!$this->parsed) { |
... | ... | |
145 | 150 |
$search_condition = db_and(); |
146 | 151 |
|
147 | 152 |
if (!$this->options['remove_score']) { |
148 |
// Create a new join to relate the 'serach_total' table to our current 'search_index' table. |
|
149 |
$join = new views_join; |
|
153 |
// Create a new join to relate the 'serach_total' table to our current |
|
154 |
// 'search_index' table. |
|
155 |
$join = new views_join(); |
|
150 | 156 |
$join->construct('search_total', $search_index, 'word', 'word'); |
151 | 157 |
$search_total = $this->query->add_relationship('search_total', $join, $search_index); |
152 | 158 |
|
... | ... | |
164 | 170 |
$search_dataset = $this->query->add_table('search_dataset'); |
165 | 171 |
$conditions = $this->search_query->conditions(); |
166 | 172 |
$condition_conditions =& $conditions->conditions(); |
167 |
foreach ($condition_conditions as $key => &$condition) {
|
|
173 |
foreach ($condition_conditions as $key => &$condition) { |
|
168 | 174 |
// Take sure we just look at real conditions. |
169 | 175 |
if (is_numeric($key)) { |
170 | 176 |
// Replace the conditions with the table alias of views. |
... | ... | |
193 | 199 |
// Set to NULL to prevent PDO exception when views object is cached. |
194 | 200 |
$this->search_query = NULL; |
195 | 201 |
} |
202 |
|
|
196 | 203 |
} |
197 | 204 |
|
198 | 205 |
/** |
199 | 206 |
* Extends the core SearchQuery. |
200 | 207 |
*/ |
201 | 208 |
class viewsSearchQuery extends SearchQuery { |
209 |
|
|
210 |
/** |
|
211 |
* {@inheritdoc} |
|
212 |
*/ |
|
202 | 213 |
public function &conditions() { |
203 | 214 |
return $this->conditions; |
204 | 215 |
} |
216 |
|
|
217 |
/** |
|
218 |
* {@inheritdoc} |
|
219 |
*/ |
|
205 | 220 |
public function words() { |
206 | 221 |
return $this->words; |
207 | 222 |
} |
208 | 223 |
|
224 |
/** |
|
225 |
* {@inheritdoc} |
|
226 |
*/ |
|
209 | 227 |
public function simple() { |
210 | 228 |
return $this->simple; |
211 | 229 |
} |
212 | 230 |
|
231 |
/** |
|
232 |
* {@inheritdoc} |
|
233 |
*/ |
|
213 | 234 |
public function matches() { |
214 | 235 |
return $this->matches; |
215 | 236 |
} |
216 | 237 |
|
238 |
/** |
|
239 |
* {@inheritdoc} |
|
240 |
*/ |
|
217 | 241 |
public function publicParseSearchExpression() { |
218 | 242 |
return $this->parseSearchExpression(); |
219 | 243 |
} |
220 | 244 |
|
221 |
function condition_replace_string($search, $replace, &$condition) { |
|
245 |
/** |
|
246 |
* {@inheritdoc} |
|
247 |
*/ |
|
248 |
public function condition_replace_string($search, $replace, &$condition) { |
|
222 | 249 |
if ($condition['field'] instanceof DatabaseCondition) { |
223 | 250 |
$conditions =& $condition['field']->conditions(); |
224 | 251 |
foreach ($conditions as $key => &$subcondition) { |
... | ... | |
231 | 258 |
$condition['field'] = str_replace($search, $replace, $condition['field']); |
232 | 259 |
} |
233 | 260 |
} |
261 |
|
|
234 | 262 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules