ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSearchSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "./Services/Object/classes/class.ilObjectGUI.php";
5 
18 {
23  function ilObjSearchSettingsGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
24  {
25  $this->type = "seas";
26  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
27 
28  $this->lng->loadLanguageModule('search');
29  }
30 
31  function &executeCommand()
32  {
33  $next_class = $this->ctrl->getNextClass($this);
34  $cmd = $this->ctrl->getCmd();
35  $this->prepareOutput();
36 
37  switch($next_class)
38  {
39  case 'ilpermissiongui':
40  $this->tabs_gui->setTabActive('perm_settings');
41  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
42  $perm_gui =& new ilPermissionGUI($this);
43  $ret =& $this->ctrl->forwardCommand($perm_gui);
44  break;
45 
46  default:
47  if($cmd == "" || $cmd == "view")
48  {
49  $cmd = "settings";
50  }
51  $cmd .= "Object";
52  $this->$cmd();
53 
54  break;
55  }
56  return true;
57  }
58 
59  function cancelObject()
60  {
61  ilUtil::sendInfo($this->lng->txt("msg_cancel"),true);
62  $this->ctrl->redirect($this, "settings");
63  }
64 
69  function settingsObject()
70  {
71  global $ilAccess,$ilErr;
72 
73  if(!$ilAccess->checkAccess('read','',$this->object->getRefId()))
74  {
75  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
76  }
77  $this->tabs_gui->setTabActive('settings');
78  $this->initFormSettings();
79  $this->tpl->setContent($this->form->getHTML());
80  return true;
81  }
82 
87  function saveSettingsObject()
88  {
89  include_once 'Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
90 
91  global $rbacsystem;
92 
93  if(!$rbacsystem->checkAccess('write',$this->object->getRefId()))
94  {
95  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
96  }
97 
98  $this->object->initSettingsObject();
99  $this->object->settings_obj->setMaxHits((int) $_POST['max_hits']);
100  $this->object->settings_obj->enableIndex($_POST['search_index']);
101  $this->object->settings_obj->enableLucene($_POST['search_lucene']);
102  $this->object->settings_obj->setHideAdvancedSearch($_POST['hide_adv_search']);
103  $this->object->settings_obj->setAutoCompleteLength($_POST['auto_complete_length']);
104  $this->object->settings_obj->setDefaultOperator((int) $_POST['operator']);
105  $this->object->settings_obj->enableLuceneItemFilter((int) $_POST['if']);
106  $this->object->settings_obj->setLuceneItemFilter((array) $_POST['filter']);
107 
108 
109  $rpc_settings = ilRPCServerSettings::getInstance();
110  if($this->object->settings_obj->enabledLucene() and !$rpc_settings->pingServer())
111  {
112  ilUtil::sendInfo($this->lng->txt('search_no_connection_lucene'),true);
113  $this->ctrl->redirect($this,'settings');
114 
115  return false;
116  }
117 
118  $this->object->settings_obj->update();
119 
120  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
121  $this->ctrl->redirect($this,'settings');
122 
123  return true;
124  }
125 
126  function getAdminTabs(&$tabs_gui)
127  {
128  $this->getTabs($tabs_gui);
129  }
130 
136  function getTabs(&$tabs_gui)
137  {
138  global $rbacsystem;
139 
140  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
141  {
142  $tabs_gui->addTarget("settings",
143  $this->ctrl->getLinkTarget($this, "settings"), array("settings","", "view"), "", "");
144  }
145 
146  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
147  {
148  $tabs_gui->addTarget('lucene_advanced_settings',
149  $this->ctrl->getLinkTarget($this,'advancedLuceneSettings'));
150  }
151 
152  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
153  {
154  $tabs_gui->addTarget('lucene_settings_tab',
155  $this->ctrl->getLinkTarget($this,'luceneSettings'));
156  }
157 
158 
159  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
160  {
161  $tabs_gui->addTarget("perm_settings",
162  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
163  }
164 
165  }
166 
171  protected function initFormSettings()
172  {
173  global $lng,$ilDB;
174 
175  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
176  include_once './Services/Search/classes/class.ilSearchSettings.php';
177 
178  $settings = new ilSearchSettings();
179 
180  $this->form = new ilPropertyFormGUI();
181  $this->form->setFormAction($this->ctrl->getFormAction($this,'updateSettings'));
182  $this->form->addCommandButton('updateSettings',$this->lng->txt('save'));
183  $this->form->setTitle($this->lng->txt('seas_settings'));
184 
185  // Max hits
186  $hits = new ilSelectInputGUI($this->lng->txt('seas_max_hits'),'max_hits');
187  $hits->setValue($settings->getMaxHits());
188  $hits->setRequired(true);
189  for($value = 5; $value <= 15; $value += 5)
190  {
191  $values[$value] = $value;
192  }
193  $hits->setOptions($values);
194  $hits->setInfo($this->lng->txt('seas_max_hits_info'));
195  $this->form->addItem($hits);
196 
197 
198  // Search type
199  $type = new ilRadioGroupInputGUI($this->lng->txt('search_type'),'search_type');
200 
201  if($settings->enabledLucene())
202  {
204  }
205  elseif($settings->enabledIndex())
206  {
207  $type->setValue(ilSearchSettings::INDEX_SEARCH);
208  }
209  else
210  {
211  $type->setValue(ilSearchSettings::LIKE_SEARCH);
212  }
213  $type->setRequired(true);
214  $this->form->addItem($type);
215 
216  // Default operator
217  $operator = new ilRadioGroupInputGUI($this->lng->txt('lucene_default_operator'),'operator');
218  $operator->setRequired(true);
219  $operator->setInfo($this->lng->txt('lucene_default_operator_info'));
220  $operator->setValue($settings->getDefaultOperator());
221 
222  $and = new ilRadioOption($this->lng->txt('lucene_and'),ilSearchSettings::OPERATOR_AND);
223  $operator->addOption($and);
224 
225  $or = new ilRadioOption($this->lng->txt('lucene_or'),ilSearchSettings::OPERATOR_OR);
226  $operator->addOption($or);
227  $this->form->addItem($operator);
228 
229 
230  // Item filter
231  $if = new ilCheckboxInputGUI($this->lng->txt('search_item_filter_form'),'if');
232  $if->setValue(1);
233  $if->setChecked($settings->isLuceneItemFilterEnabled());
234  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
235  $this->form->addItem($if);
236 
237  $filter = $settings->getLuceneItemFilter();
238  foreach(ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def)
239  {
240  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']),'filter['.$obj.']');
241  if(isset($filter[$obj]) and $filter[$obj])
242  {
243  $ch->setChecked(true);
244  }
245  $ch->setValue(1);
246  $if->addSubItem($ch);
247  }
248 
249 
250  // hide advanced search
251  $cb = new ilCheckboxInputGUI($lng->txt("search_hide_adv_search"), "hide_adv_search");
252  $cb->setChecked($settings->getHideAdvancedSearch());
253  $this->form->addItem($cb);
254 
255  // number of auto complete entries
256  $options = array(
257  5 => 5,
258  10 => 10,
259  20 => 20,
260  30 => 30
261  );
262  $si = new ilSelectInputGUI($lng->txt("search_auto_complete_length"), "auto_complete_length");
263  $si->setOptions($options);
264  $val = ($settings->getAutoCompleteLength() > 0)
265  ? $settings->getAutoCompleteLength()
266  : 10;
267  $si->setValue($val);
268  $this->form->addItem($si);
269 
270 
271  $direct = new ilRadioOption($this->lng->txt('search_direct'),ilSearchSettings::LIKE_SEARCH,$this->lng->txt('search_like_info'));
272  $type->addOption($direct);
273 
274  if($ilDB->getDBType() == 'mysql')
275  {
276  $index = new ilRadioOption($this->lng->txt('search_index'),ilSearchSettings::INDEX_SEARCH,$this->lng->txt('search_full_info'));
277  $type->addOption($index);
278  }
279 
280  $lucene = new ilRadioOption($this->lng->txt('search_lucene'),ilSearchSettings::LUCENE_SEARCH,$this->lng->txt('java_server_info'));
281  $type->addOption($lucene);
282  }
283 
284 
289  protected function updateSettingsObject()
290  {
291  global $ilAccess,$ilErr;
292 
293  $this->initFormSettings();
294  $this->form->checkInput();
295 
296  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
297  {
298  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
299  }
300 
301  include_once './Services/Search/classes/class.ilSearchSettings.php';
302  $settings = new ilSearchSettings();
303  $settings->setMaxHits((int) $_POST['max_hits']);
304 
305  switch((int) $_POST['search_type'])
306  {
308  $settings->enableIndex(false);
309  $settings->enableLucene(false);
310  break;
312  $settings->enableIndex(true);
313  $settings->enableLucene(false);
314  break;
316  $settings->enableIndex(false);
317  $settings->enableLucene(true);
318  break;
319  }
320 
321  $settings->setDefaultOperator((int) $_POST['operator']);
322  $settings->enableLuceneItemFilter((int) $_POST['if']);
323  $settings->setLuceneItemFilter((array) $_POST['filter']);
324 
325  $settings->setHideAdvancedSearch($_POST['hide_adv_search']);
326  $settings->setAutoCompleteLength($_POST['auto_complete_length']);
327 
328  $settings->update();
329 
330  unset($_SESSION['search_last_class']);
331 
332  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
333  $this->settingsObject();
334  }
335 
341  protected function luceneSettingsObject()
342  {
343  $this->initSubTabs('lucene');
344  $this->tabs_gui->setTabActive('lucene_settings_tab');
345 
346  $this->initFormLuceneSettings();
347  $this->tpl->setContent($this->form->getHTML());
348  }
349 
355  protected function initFormLuceneSettings()
356  {
357  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
358  include_once './Services/Search/classes/class.ilSearchSettings.php';
359 
360  $this->settings = ilSearchSettings::getInstance();
361 
362  $this->form = new ilPropertyFormGUI();
363  $this->form->setFormAction($this->ctrl->getFormAction($this,'cancel'));
364 
365  $this->form->setTitle($this->lng->txt('lucene_settings_title'));
366  $this->form->addCommandButton('saveLuceneSettings',$this->lng->txt('save'));
367  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
368 
369 
370  // Offline filter
371  /*
372  $offline = new ilCheckboxInputGUI($this->lng->txt('lucene_offline_filter_setting'),'offline_filter');
373  $offline->setInfo($this->lng->txt('lucene_offline_filter_setting_info'));
374  $offline->setValue(1);
375  $offline->setChecked($this->settings->isLuceneOfflineFilterEnabled());
376  $this->form->addItem($offline);
377  */
378 
379  // user search
380  $us = new ilCheckboxInputGUI($this->lng->txt('search_user_search_form'),'user_search_enabled');
381  $us->setInfo($this->lng->txt('search_user_search_info_form'));
382  $us->setValue(1);
383  $us->setChecked($this->settings->isLuceneUserSearchEnabled());
384  $this->form->addItem($us);
385 
386 
387  // Item filter
388  $if = new ilCheckboxInputGUI($this->lng->txt('search_mime_filter_form'),'mime_enabled');
389  $if->setValue(1);
390  $if->setChecked($this->settings->isLuceneMimeFilterEnabled());
391  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
392  $this->form->addItem($if);
393 
394  $mimes = $this->settings->getLuceneMimeFilter();
395  foreach(ilSearchSettings::getLuceneMimeFilterDefinitions() as $mime => $def)
396  {
397  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']),'mime['.$mime.']');
398  if(isset($mimes[$mime]) and $mimes[$mime])
399  {
400  $ch->setChecked(true);
401  }
402  $ch->setValue(1);
403  $if->addSubItem($ch);
404  }
405 
406  $prefix = new ilCheckboxInputGUI($this->lng->txt('lucene_prefix_wildcard'),'prefix');
407  $prefix->setValue(1);
408  $prefix->setInfo($this->lng->txt('lucene_prefix_wildcard_info'));
409  $prefix->setChecked($this->settings->isPrefixWildcardQueryEnabled());
410  $this->form->addItem($prefix);
411 
412 
413  $numFrag = new ilNumberInputGUI($this->lng->txt('lucene_num_fragments'),'fragmentCount');
414  $numFrag->setRequired(true);
415  $numFrag->setSize(2);
416  $numFrag->setMaxLength(2);
417  $numFrag->setMinValue(1);
418  $numFrag->setMaxValue(10);
419  $numFrag->setInfo($this->lng->txt('lucene_num_frag_info'));
420  $numFrag->setValue($this->settings->getFragmentCount());
421  $this->form->addItem($numFrag);
422 
423  $sizeFrag = new ilNumberInputGUI($this->lng->txt('lucene_size_fragments'),'fragmentSize');
424  $sizeFrag->setRequired(true);
425  $sizeFrag->setSize(2);
426  $sizeFrag->setMaxLength(4);
427  $sizeFrag->setMinValue(10);
428  $sizeFrag->setMaxValue(1000);
429  $sizeFrag->setInfo($this->lng->txt('lucene_size_frag_info'));
430  $sizeFrag->setValue($this->settings->getFragmentSize());
431  $this->form->addItem($sizeFrag);
432 
433  $maxSub = new ilNumberInputGUI($this->lng->txt('lucene_max_sub'),'maxSubitems');
434  $maxSub->setRequired(true);
435  $maxSub->setSize(2);
436  $maxSub->setMaxLength(2);
437  $maxSub->setMinValue(1);
438  $maxSub->setMaxValue(10);
439  $maxSub->setInfo($this->lng->txt('lucene_max_sub_info'));
440  $maxSub->setValue($this->settings->getMaxSubitems());
441  $this->form->addItem($maxSub);
442 
443  $relevance = new ilCheckboxInputGUI($this->lng->txt('lucene_relevance'),'relevance');
444  $relevance->setOptionTitle($this->lng->txt('lucene_show_relevance'));
445  $relevance->setInfo($this->lng->txt('lucene_show_relevance_info'));
446  $relevance->setValue(1);
447  $relevance->setChecked($this->settings->isRelevanceVisible());
448  $this->form->addItem($relevance);
449 
450  // begin-patch mime_filter
451  $subrel = new ilCheckboxInputGUI('','subrelevance');
452  $subrel->setOptionTitle($this->lng->txt('lucene_show_sub_relevance'));
453  $subrel->setValue(1);
454  $subrel->setChecked($this->settings->isSubRelevanceVisible());
455  $relevance->addSubItem($subrel);
456  // end-patch mime_filter
457 
458  $last_index = new ilDateTimeInputGUI($this->lng->txt('lucene_last_index_time'),'last_index');
459  $last_index->setShowTime(true);
460  $last_index->setDate($this->settings->getLastIndexTime());
461  $last_index->setInfo($this->lng->txt('lucene_last_index_time_info'));
462  $this->form->addItem($last_index);
463 
464  return true;
465  }
466 
471  protected function saveLuceneSettingsObject()
472  {
473  global $ilBench,$ilLog,$ilSetting;
474 
475  $this->initFormLuceneSettings();
476 
477  $settings = ilSearchSettings::getInstance();
478  $settings->enableLuceneUserSearch((int) $_POST['user_search_enabled']);
479  $settings->setFragmentCount((int) $_POST['fragmentCount']);
480  $settings->setFragmentSize((int) $_POST['fragmentSize']);
481  $settings->setMaxSubitems((int) $_POST['maxSubitems']);
482  $settings->showRelevance((int) $_POST['relevance']);
483  $settings->enableLuceneOfflineFilter((int) $_POST['offline_filter']);
484  $settings->enableLuceneMimeFilter((int) $_POST['mime_enabled']);
485  $settings->setLuceneMimeFilter((array) $_POST['mime']);
486  $settings->showSubRelevance((int) $_POST['subrelevance']);
487  $settings->enablePrefixWildcardQuery((int) $_POST['prefix']);
488 
489  if($this->form->checkInput())
490  {
491  $settings->setLastIndexTime($this->form->getItemByPostVar('last_index')->getDate());
492  $settings->update();
493 
494  // refresh lucene server
495  $ilBench->start('Lucene','LuceneRefreshSettings');
496 
497  try {
498  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
499  ilRpcClientFactory::factory('RPCAdministration')->refreshSettings(
500  CLIENT_ID.'_'.$ilSetting->get('inst_id',0));
501 
502  ilUtil::sendInfo($this->lng->txt('settings_saved'));
503  $this->luceneSettingsObject();
504  return true;
505  }
506  catch(Exception $e)
507  {
508  $ilLog->write(__METHOD__.': '.$e->getMessage());
509  ilUtil::sendFailure($e->getMessage());
510  $this->luceneSettingsObject();
511  return false;
512  }
513  }
514 
515  ilUtil::sendInfo($this->lng->txt('err_check_input'));
516  $this->luceneSettingsObject();
517  return false;
518  }
519 
520  protected function advancedLuceneSettingsObject()
521  {
522  $this->initSubTabs('lucene');
523  $this->tabs_gui->setTabActive('lucene_advanced_settings');
524 
525  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchActivationTableGUI.php';
526  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
527 
528  $table = new ilLuceneAdvancedSearchActivationTableGUI($this,'advancedLuceneSettings');
529  $table->setTitle($this->lng->txt('lucene_advanced_settings_table'));
531 
532  $this->tpl->setContent($table->getHTML());
533  }
534 
535  protected function saveAdvancedLuceneSettingsObject()
536  {
537  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
538 
540  foreach(ilLuceneAdvancedSearchFields::getFields() as $field => $translation)
541  {
542  $settings->setActive($field,in_array($field,(array) $_POST['fid']) ? true : false);
543  }
544  $settings->save();
545  ilUtil::sendInfo($this->lng->txt('settings_saved'));
547  }
548 
552  protected function initSubTabs($a_section)
553  {
554  switch($a_section)
555  {
556  case 'lucene':
557  $this->tabs_gui->addSubTabTarget('lucene_general_settings',
558  $this->ctrl->getLinkTarget($this,'luceneSettings'));
559 
560  break;
561  }
562  }
563 
564 
565 } // END class.ilObjSearchSettingsGUI
566 ?>