Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_page_management.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
18 
30 {
31 
32 
37  function Search_Page_Management(&$pm)
38  {
39  $this->Asset_Management($pm);
40 
41  $this->vars['group_by'] = Array(
42  'added' => '0.1',
43  'type' => 'selection',
44  'default' => 'number',
45  'parameters' => Array(
46  'multiple' => FALSE,
47  'allow_empty' => FALSE,
48  'options' => Array(
49  'number' => 'Standard',
50  'grouped' => 'Custom Grouping',
51  ),
52  ),
53  );
54 
55  $this->vars['sis_button_text'] = Array(
56  'added' => '0.5',
57  'type' => 'text',
58  'default' => 'Search',
59  'description' => 'Text that would appear on the search in search submit button',
60  'is_contextable' => TRUE,
61  );
62 
63  $this->vars['fields'] = Array(
64  'added' => '0.1',
65  'type' => 'serialise',
66  'default' => Array(),
67  'description' => 'Search fields.',
68  );
69 
70  $this->vars['categories'] = Array(
71  'added' => '0.4',
72  'type' => 'serialise',
73  'default' => Array(),
74  'description' => 'Search categories.',
75  );
76 
77  $this->vars['no_category_text'] = Array(
78  'added' => '0.4',
79  'type' => 'text',
80  'default' => 'No Category Selected',
81  'description' => 'The text that appears for a "no category selected" options.',
82  'is_contextable' => TRUE,
83  );
84 
85  $this->vars['auto_synonym_search_field'] = Array(
86  'added' => '0.21',
87  'type' => 'text',
88  'default' => '',
89  'description' => 'Field to automatically search for synonyms on if the original search term(s) return no results. Empty string = auto synonym searching disabled',
90  );
91 
92  $this->vars['search_types'] = Array(
93  'added' => '0.1',
94  'type' => 'serialise',
95  'default' => Array(),
96  'description' => 'Searchable asset types',
97  );
98 
99  $this->vars['search_styles'] = Array(
100  'added' => '0.1',
101  'type' => 'serialise',
102  'default' => Array(),
103  'description' => 'Styles of the search fields',
104  );
105 
106  $this->vars['use_picker'] = Array(
107  'added' => '0.6',
108  'type' => 'boolean',
109  'default' => FALSE,
110  'description' => 'Use the JS date picker or not',
111  'parameters' => Array('allow_empty' => FALSE),
112  );
113 
114  $this->vars['logic'] = Array(
115  'added' => '0.1',
116  'type' => 'selection',
117  'default' => 'AND',
118  'description' => 'Whether to include all or any fields.',
119  'parameters' => Array(
120  'multiple' => FALSE,
121  'allow_empty' => FALSE,
122  'options' => Array(
123  'AND' => 'Match on ALL fields',
124  'OR' => 'Match on at least ONE field',
125  ),
126  ),
127  );
128 
129  $this->vars['allow_empty_search'] = Array(
130  'added' => '0.12',
131  'type' => 'boolean',
132  'default' => FALSE,
133  'description' => 'If true, empty search query will search for everything',
134  'parameters' => Array('allow_empty' => FALSE),
135  );
136  $this->vars['search_as_public_user'] = Array(
137  'added' => '0.12',
138  'type' => 'boolean',
139  'default' => FALSE,
140  'description' => 'If true, only look for assets which were granted public user read',
141  'parameters' => Array('allow_empty' => FALSE),
142  );
143  $this->vars['no_roles_check'] = Array(
144  'added' => '0.12',
145  'type' => 'boolean',
146  'default' => FALSE,
147  'description' => 'If true, search for assets without checking roles',
148  'parameters' => Array('allow_empty' => FALSE),
149  );
150  $this->vars['no_group_access_check'] = Array(
151  'added' => '0.12',
152  'type' => 'boolean',
153  'default' => FALSE,
154  'description' => 'If true, search for assets without checking groups access priviledge for current user',
155  'parameters' => Array('allow_empty' => FALSE),
156  );
157 
158 
159  $this->vars['spell_check_string'] = Array(
160  'added' => '0.19',
161  'type' => 'text',
162  'default' => 'Did you mean: %suggestions%',
163  'description' => 'String to use for the "spell check suggestions" keyword',
164  'is_contextable' => TRUE,
165  );
166 
167  $this->vars['synonym_string'] = Array(
168  'added' => '0.19',
169  'type' => 'text',
170  'default' => 'Did you mean: %suggestions%',
171  'description' => 'String to use for the "synonyms" keyword',
172  'is_contextable' => TRUE,
173  );
174 
175  $this->vars['auto_synonym_string'] = Array(
176  'added' => '0.21',
177  'type' => 'text',
178  'default' => '(and related terms)',
179  'description' => 'String to display for the "auto synonym search triggered" keyword',
180  'is_contextable' => TRUE,
181  );
182 
183  $this->vars['stored_query_session'] = Array(
184  'added' => '0.21',
185  'type' => 'parameter_map',
186  'default' => Array(),
187  'description' => 'Use saved variables to conduct the search query',
188  'parameters' => Array(
189  'parameters' => Array(
190  'stored_query' => 'Search all fields',
191  ),
192  ),
193  );
194 
195  $this->vars['stored_query_show_results'] = Array(
196  'added' => '0.21',
197  'type' => 'boolean',
198  'default' => FALSE,
199  'description' => 'Go directly to the results if the query is stored',
200  'parameters' => Array('allow_empty' => FALSE),
201  );
202 
203  // Default sort-by options are different for search page
204  $this->vars['sort_by'] = Array(
205  'added' => '0.1',
206  'type' => 'serialise',
207  'default' => Array(
208  0 => Array (
209  'params' => Array (
210  'field' => 'score',
211  ),
212  'type' => '',
213  'name' => 'Relevance',
214  ),
215  1 => Array (
216  'params' => Array (
217  'field' => 'name',
218  ),
219  'type' => 'field',
220  'name' => 'Name',
221  ),
222  2 => Array (
223  'params' => Array (
224  'field' => 'short_name',
225  ),
226  'type' => 'field',
227  'name' => 'Short Name',
228  ),
229  3 => Array (
230  'params' => Array (
231  'field' => 'created',
232  ),
233  'type' => 'field',
234  'name' => 'Created Date',
235  ),
236  4 => Array (
237  'params' => Array (
238  'field' => 'updated',
239  ),
240  'type' => 'field',
241  'name' => 'Last Updated Date',
242  ),
243  5 => Array (
244  'params' => Array (
245  'field' => 'published',
246  ),
247  'type' => 'field',
248  'name' => 'Last Published Date',
249  ),
250  6 => Array (
251  'params' => Array (
252  'field' => 'type_code',
253  ),
254  'name' => 'Asset Type',
255  'type' => 'field',
256  ),
257  7 => Array (
258  'params' => Array (
259  'field' => '',
260  ),
261  'name' => 'Random',
262  'type' => '',
263  ),
264  ),
265  );
266 
267  $this->vars['enable_multi_word_synonym_lookups'] = Array(
268  'added' => '0.22',
269  'type' => 'boolean',
270  'default' => FALSE,
271  'description' => 'If true, a Thesaurus lookup will be performed for matching synonyms based on combinations of words from the search string',
272  'parameters' => Array('allow_empty' => FALSE),
273  );
274 
275  $this->vars['exclude_self'] = Array(
276  'added' => '0.23',
277  'type' => 'boolean',
278  'default' => FALSE,
279  'description' => 'If true, only look for assets underneath root nodes',
280  'parameters' => Array('allow_empty' => FALSE),
281  );
282  $this->vars['restrict_date_field'] = Array(
283  'added' => '0.24',
284  'type' => 'selection',
285  'default' => 'updated',
286  'parameters' => Array(
287  'options' => Array(
288  'created' => 'Created Date',
289  'updated' => 'Last Updated Date',
290  'published' => 'Last Published Date',
291  ),
292  ),
293  'multiple' => FALSE,
294  'allow_empty' => FALSE,
295  );
296  $this->vars['restrict_date_range_from'] = Array(
297  'added' => '0.24',
298  'type' => 'datetime',
299  'default' => '---------- --:--:--',
300  'parameters' => Array(
301  'allow_null' => TRUE,
302  ),
303  );
304  $this->vars['restrict_date_range_to'] = Array(
305  'added' => '0.24',
306  'type' => 'datetime',
307  'default' => '---------- --:--:--',
308  'parameters' => Array(
309  'allow_null' => TRUE,
310  ),
311  );
312  $this->vars['page_link_format'] = Array(
313  'added' => '0.22',
314  'type' => 'text',
315  'default' => ' <a href="%page_link%">%page_number%</a>',
316  );
317 
318  $this->vars['current_page_format'] = Array(
319  'added' => '0.22',
320  'type' => 'text',
321  'default' => ' <b>%page_number%</b>',
322  );
323  $this->vars['disable_keyword_replacements'] = Array(
324  'added' => '0.25',
325  'type' => 'boolean',
326  'default' => TRUE,
327  'description' => 'If true, will not replace any keywords from the user input',
328  'parameters' => Array('allow_empty' => FALSE),
329  );
330 
331  }//end constructor
332 
333 
340  function getEventList()
341  {
342  return Array(
343  Array(
344  'event_name' => 'requestKeywords',
345  'broadcast_type_code' => 'content_type',
346  'broadcast_strict_type_code' => FALSE,
347  'options' => Array(
348  'side_of_link' => 'major',
349  'indirect' => TRUE,
350  'is_exclusive' => NULL,
351  'is_dependant' => 1,
352  'value' => '',
353  'link_type' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_1,
354  ),
355  ),
356  );
357 
358  }//end getEventList()
359 
360 
369  function _upgrade($current_version)
370  {
371  parent::_upgrade($current_version);
372 
373  if (version_compare($current_version, '0.26', '<')) {
374  echo('UPGRADING SEARCH PAGE FROM '.$current_version."\n");
375  // Version 0.26 ownwards the "exclude" search field is stored
376  // as regular search field having its own set of datasoruce settings.
377  // A flag in search field "exclude_field" tells if the search
378  // field is "exclude" or regular one.
379 
380  $count = 0;
381 
382  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
383  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
384 
385  pre_echo('Updating Search Pages...');
386 
387  // Get all Search Page assets
388  $search_pages = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('search_page', FALSE, TRUE);
389 
390  // Update assets
391  foreach ($search_pages as $id => $type) {
392  $search_page = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
393 
394  $old_fields = $search_page->attr('fields');
395  $new_fields = Array();
396  foreach($old_fields as $field_name => $field_data) {
397  // Update "exclude" fields
398  if (isset($field_data['data_sources'][0]['type']) && $field_data['data_sources'][0]['type'] == 'exclude') {
399  $new_fields[$field_name]['name'] = $field_name;
400  $new_fields[$field_name]['word_logic'] = 'OR';
401  $new_fields[$field_name]['exclude_field'] = TRUE;
402  $new_fields[$field_name]['data_sources'] = Array(
403  0 => Array(
404  'type' => 'include_all',
405  'params' => Array(),
406  ),
407  );
408  } else {
409  $new_fields[$field_name] = $field_data;
410  $new_fields[$field_name]['exclude_field'] = FALSE;
411  }
412  }//end foreach old_fields
413 
414  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
415  $search_page->setAttrValue('fields', $new_fields);
416 
417  if (!$search_page->saveAttributes()) {
418  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
419  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
420 
421  pre_echo('UPGRADE FAILED - Could not save attributes');
422  return FALSE;
423  }//end if
424  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
425 
426  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($search_pages, TRUE);
427  unset($search_pages);
428 
429  $count++;
430  }//end foreach search pages
431 
432  pre_echo('Updated - '.$count.' search page(s)...');
433 
434  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
435  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
436 
437  pre_echo('SEARCH PAGES SUCCESSFULLY UPGRADED TO VERSION 0.26');
438  }//end if
439  return TRUE;
440 
441  }//end _upgrade()
442 
443 
444 }//end class
445 
446 ?>