ILIAS  release_4-3 Revision
 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 
380  $numFrag = new ilNumberInputGUI($this->lng->txt('lucene_num_fragments'),'fragmentCount');
381  $numFrag->setRequired(true);
382  $numFrag->setSize(2);
383  $numFrag->setMaxLength(2);
384  $numFrag->setMinValue(1);
385  $numFrag->setMaxValue(10);
386  $numFrag->setInfo($this->lng->txt('lucene_num_frag_info'));
387  $numFrag->setValue($this->settings->getFragmentCount());
388  $this->form->addItem($numFrag);
389 
390  $sizeFrag = new ilNumberInputGUI($this->lng->txt('lucene_size_fragments'),'fragmentSize');
391  $sizeFrag->setRequired(true);
392  $sizeFrag->setSize(2);
393  $sizeFrag->setMaxLength(4);
394  $sizeFrag->setMinValue(10);
395  $sizeFrag->setMaxValue(1000);
396  $sizeFrag->setInfo($this->lng->txt('lucene_size_frag_info'));
397  $sizeFrag->setValue($this->settings->getFragmentSize());
398  $this->form->addItem($sizeFrag);
399 
400  $maxSub = new ilNumberInputGUI($this->lng->txt('lucene_max_sub'),'maxSubitems');
401  $maxSub->setRequired(true);
402  $maxSub->setSize(2);
403  $maxSub->setMaxLength(2);
404  $maxSub->setMinValue(1);
405  $maxSub->setMaxValue(10);
406  $maxSub->setInfo($this->lng->txt('lucene_max_sub_info'));
407  $maxSub->setValue($this->settings->getMaxSubitems());
408  $this->form->addItem($maxSub);
409 
410  $relevance = new ilCheckboxInputGUI($this->lng->txt('lucene_relevance'),'relevance');
411  $relevance->setOptionTitle($this->lng->txt('lucene_show_relevance'));
412  $relevance->setInfo($this->lng->txt('lucene_show_relevance_info'));
413  $relevance->setValue(1);
414  $relevance->setChecked($this->settings->isRelevanceVisible());
415  $this->form->addItem($relevance);
416 
417  $last_index = new ilDateTimeInputGUI($this->lng->txt('lucene_last_index_time'),'last_index');
418  $last_index->setShowTime(true);
419  $last_index->setDate($this->settings->getLastIndexTime());
420  $last_index->setInfo($this->lng->txt('lucene_last_index_time_info'));
421  $this->form->addItem($last_index);
422 
423  return true;
424  }
425 
430  protected function saveLuceneSettingsObject()
431  {
432  global $ilBench,$ilLog,$ilSetting;
433 
434  $this->initFormLuceneSettings();
435 
436  $settings = ilSearchSettings::getInstance();
437  $settings->setFragmentCount((int) $_POST['fragmentCount']);
438  $settings->setFragmentSize((int) $_POST['fragmentSize']);
439  $settings->setMaxSubitems((int) $_POST['maxSubitems']);
440  $settings->showRelevance((int) $_POST['relevance']);
441  $settings->enableLuceneOfflineFilter((int) $_POST['offline_filter']);
442 
443  if($this->form->checkInput())
444  {
445  $settings->setLastIndexTime($this->form->getItemByPostVar('last_index')->getDate());
446  $settings->update();
447 
448  // refresh lucene server
449  $ilBench->start('Lucene','LuceneRefreshSettings');
450 
451  try {
452  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
453  ilRpcClientFactory::factory('RPCAdministration')->refreshSettings(
454  CLIENT_ID.'_'.$ilSetting->get('inst_id',0));
455 
456  ilUtil::sendInfo($this->lng->txt('settings_saved'));
457  $this->luceneSettingsObject();
458  return true;
459  }
460  catch(Exception $e)
461  {
462  $ilLog->write(__METHOD__.': '.$e->getMessage());
463  ilUtil::sendFailure($e->getMessage());
464  $this->luceneSettingsObject();
465  return false;
466  }
467  }
468 
469  ilUtil::sendInfo($this->lng->txt('err_check_input'));
470  $this->luceneSettingsObject();
471  return false;
472  }
473 
474  protected function advancedLuceneSettingsObject()
475  {
476  $this->initSubTabs('lucene');
477  $this->tabs_gui->setTabActive('lucene_advanced_settings');
478 
479  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchActivationTableGUI.php';
480  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
481 
482  $table = new ilLuceneAdvancedSearchActivationTableGUI($this,'advancedLuceneSettings');
483  $table->setTitle($this->lng->txt('lucene_advanced_settings_table'));
485 
486  $this->tpl->setContent($table->getHTML());
487  }
488 
489  protected function saveAdvancedLuceneSettingsObject()
490  {
491  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
492 
494  foreach(ilLuceneAdvancedSearchFields::getFields() as $field => $translation)
495  {
496  $settings->setActive($field,in_array($field,(array) $_POST['fid']) ? true : false);
497  }
498  $settings->save();
499  ilUtil::sendInfo($this->lng->txt('settings_saved'));
501  }
502 
506  protected function initSubTabs($a_section)
507  {
508  switch($a_section)
509  {
510  case 'lucene':
511  $this->tabs_gui->addSubTabTarget('lucene_general_settings',
512  $this->ctrl->getLinkTarget($this,'luceneSettings'));
513 
514  break;
515  }
516  }
517 
518 
519 } // END class.ilObjSearchSettingsGUI
520 ?>