ILIAS  Release_4_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 "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 
105  $rpc_settings = ilRPCServerSettings::getInstance();
106  if($this->object->settings_obj->enabledLucene() and !$rpc_settings->pingServer())
107  {
108  ilUtil::sendInfo($this->lng->txt('search_no_connection_lucene'),true);
109  $this->ctrl->redirect($this,'settings');
110 
111  return false;
112  }
113 
114  $this->object->settings_obj->update();
115 
116  ilUtil::sendInfo($this->lng->txt('settings_saved'),true);
117  $this->ctrl->redirect($this,'settings');
118 
119  return true;
120  }
121 
122  function getAdminTabs(&$tabs_gui)
123  {
124  $this->getTabs($tabs_gui);
125  }
126 
132  function getTabs(&$tabs_gui)
133  {
134  global $rbacsystem;
135 
136  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
137  {
138  $tabs_gui->addTarget("settings",
139  $this->ctrl->getLinkTarget($this, "settings"), array("settings","", "view"), "", "");
140  }
141 
142  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
143  {
144  $tabs_gui->addTarget('lucene_advanced_settings',
145  $this->ctrl->getLinkTarget($this,'advancedLuceneSettings'));
146  }
147 
148  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
149  {
150  $tabs_gui->addTarget('lucene_settings_tab',
151  $this->ctrl->getLinkTarget($this,'luceneSettings'));
152  }
153 
154 
155  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
156  {
157  $tabs_gui->addTarget("perm_settings",
158  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
159  }
160 
161  }
162 
167  protected function initFormSettings()
168  {
169  global $lng,$ilDB;
170 
171  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
172  include_once './Services/Search/classes/class.ilSearchSettings.php';
173 
174  $settings = new ilSearchSettings();
175 
176  $this->form = new ilPropertyFormGUI();
177  $this->form->setFormAction($this->ctrl->getFormAction($this,'updateSettings'));
178  $this->form->addCommandButton('updateSettings',$this->lng->txt('save'));
179  $this->form->setTitle($this->lng->txt('seas_settings'));
180 
181  // Max hits
182  $hits = new ilSelectInputGUI($this->lng->txt('seas_max_hits'),'max_hits');
183  $hits->setValue($settings->getMaxHits());
184  $hits->setRequired(true);
185  for($value = 5; $value <= 15; $value += 5)
186  {
187  $values[$value] = $value;
188  }
189  $hits->setOptions($values);
190  $hits->setInfo($this->lng->txt('seas_max_hits_info'));
191  $this->form->addItem($hits);
192 
193  // Search type
194  $type = new ilRadioGroupInputGUI($this->lng->txt('search_type'),'search_type');
195 
196  if($settings->enabledLucene())
197  {
199  }
200  elseif($settings->enabledIndex())
201  {
203  }
204  else
205  {
207  }
208  $type->setRequired(true);
209  $this->form->addItem($type);
210 
211  // hide advanced search
212  $cb = new ilCheckboxInputGUI($lng->txt("search_hide_adv_search"), "hide_adv_search");
213  $cb->setChecked($settings->getHideAdvancedSearch());
214  $this->form->addItem($cb);
215 
216  // number of auto complete entries
217  $options = array(
218  5 => 5,
219  10 => 10,
220  20 => 20,
221  30 => 30
222  );
223  $si = new ilSelectInputGUI($lng->txt("search_auto_complete_length"), "auto_complete_length");
224  $si->setOptions($options);
225  $val = ($settings->getAutoCompleteLength() > 0)
226  ? $settings->getAutoCompleteLength()
227  : 10;
228  $si->setValue($val);
229  $this->form->addItem($si);
230 
231 
232  $direct = new ilRadioOption($this->lng->txt('search_direct'),ilSearchSettings::LIKE_SEARCH,$this->lng->txt('search_like_info'));
233  $type->addOption($direct);
234 
235  if($ilDB->getDBType() == 'mysql')
236  {
237  $index = new ilRadioOption($this->lng->txt('search_index'),ilSearchSettings::INDEX_SEARCH,$this->lng->txt('search_full_info'));
238  $type->addOption($index);
239  }
240 
241  $lucene = new ilRadioOption($this->lng->txt('search_lucene'),ilSearchSettings::LUCENE_SEARCH,$this->lng->txt('java_server_info'));
242  $type->addOption($lucene);
243  }
244 
245 
250  protected function updateSettingsObject()
251  {
252  global $ilAccess,$ilErr;
253 
254  $this->initFormSettings();
255  $this->form->checkInput();
256 
257  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
258  {
259  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
260  }
261 
262  include_once './Services/Search/classes/class.ilSearchSettings.php';
263  $settings = new ilSearchSettings();
264  $settings->setMaxHits((int) $_POST['max_hits']);
265 
266  switch((int) $_POST['search_type'])
267  {
269  $settings->enableIndex(false);
270  $settings->enableLucene(false);
271  break;
273  $settings->enableIndex(true);
274  $settings->enableLucene(false);
275  break;
277  $settings->enableIndex(false);
278  $settings->enableLucene(true);
279  break;
280  }
281 
282  $settings->setHideAdvancedSearch($_POST['hide_adv_search']);
283  $settings->setAutoCompleteLength($_POST['auto_complete_length']);
284 
285  $settings->update();
286 
287  unset($_SESSION['search_last_class']);
288 
289  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
290  $this->settingsObject();
291  }
292 
298  protected function luceneSettingsObject()
299  {
300  $this->initSubTabs('lucene');
301  $this->tabs_gui->setTabActive('lucene_settings_tab');
302 
303  $this->initFormLuceneSettings();
304  $this->tpl->setContent($this->form->getHTML());
305  }
306 
312  protected function initFormLuceneSettings()
313  {
314  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
315  include_once './Services/Search/classes/class.ilSearchSettings.php';
316 
317  $this->settings = ilSearchSettings::getInstance();
318 
319  $this->form = new ilPropertyFormGUI();
320  $this->form->setFormAction($this->ctrl->getFormAction($this,'cancel'));
321 
322  $this->form->setTitle($this->lng->txt('lucene_settings_title'));
323  $this->form->addCommandButton('saveLuceneSettings',$this->lng->txt('save'));
324  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
325 
326  $operator = new ilRadioGroupInputGUI($this->lng->txt('lucene_default_operator'),'operator');
327  $operator->setRequired(true);
328  $operator->setInfo($this->lng->txt('lucene_default_operator_info'));
329  $operator->setValue($this->settings->getDefaultOperator());
330 
331  $and = new ilRadioOption($this->lng->txt('lucene_and'),ilSearchSettings::OPERATOR_AND);
332  $operator->addOption($and);
333 
334  $or = new ilRadioOption($this->lng->txt('lucene_or'),ilSearchSettings::OPERATOR_OR);
335  $operator->addOption($or);
336  $this->form->addItem($operator);
337 
338  // Item filter
339  $if = new ilCheckboxInputGUI($this->lng->txt('search_item_filter_form'),'if');
340  $if->setValue(1);
341  $if->setChecked($this->settings->isLuceneItemFilterEnabled());
342  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
343  $this->form->addItem($if);
344 
345  $filter = $this->settings->getLuceneItemFilter();
346  foreach(ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def)
347  {
348  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']),'filter['.$obj.']');
349  if(isset($filter[$obj]) and $filter[$obj])
350  {
351  $ch->setChecked(true);
352  }
353  $ch->setValue(1);
354  $if->addSubItem($ch);
355  }
356 
357  $numFrag = new ilNumberInputGUI($this->lng->txt('lucene_num_fragments'),'fragmentCount');
358  $numFrag->setRequired(true);
359  $numFrag->setSize(2);
360  $numFrag->setMaxLength(2);
361  $numFrag->setMinValue(1);
362  $numFrag->setMaxValue(10);
363  $numFrag->setInfo($this->lng->txt('lucene_num_frag_info'));
364  $numFrag->setValue($this->settings->getFragmentCount());
365  $this->form->addItem($numFrag);
366 
367  $sizeFrag = new ilNumberInputGUI($this->lng->txt('lucene_size_fragments'),'fragmentSize');
368  $sizeFrag->setRequired(true);
369  $sizeFrag->setSize(2);
370  $sizeFrag->setMaxLength(4);
371  $sizeFrag->setMinValue(10);
372  $sizeFrag->setMaxValue(1000);
373  $sizeFrag->setInfo($this->lng->txt('lucene_size_frag_info'));
374  $sizeFrag->setValue($this->settings->getFragmentSize());
375  $this->form->addItem($sizeFrag);
376 
377  $maxSub = new ilNumberInputGUI($this->lng->txt('lucene_max_sub'),'maxSubitems');
378  $maxSub->setRequired(true);
379  $maxSub->setSize(2);
380  $maxSub->setMaxLength(2);
381  $maxSub->setMinValue(1);
382  $maxSub->setMaxValue(10);
383  $maxSub->setInfo($this->lng->txt('lucene_max_sub_info'));
384  $maxSub->setValue($this->settings->getMaxSubitems());
385  $this->form->addItem($maxSub);
386 
387  $relevance = new ilCheckboxInputGUI($this->lng->txt('lucene_relevance'),'relevance');
388  $relevance->setOptionTitle($this->lng->txt('lucene_show_relevance'));
389  $relevance->setInfo($this->lng->txt('lucene_show_relevance_info'));
390  $relevance->setValue(1);
391  $relevance->setChecked($this->settings->isRelevanceVisible());
392  $this->form->addItem($relevance);
393 
394  $last_index = new ilDateTimeInputGUI($this->lng->txt('lucene_last_index_time'),'last_index');
395  $last_index->setShowTime(true);
396  $last_index->setDate($this->settings->getLastIndexTime());
397  $last_index->setInfo($this->lng->txt('lucene_last_index_time_info'));
398  $this->form->addItem($last_index);
399 
400  return true;
401  }
402 
407  protected function saveLuceneSettingsObject()
408  {
409  global $ilBench,$ilLog,$ilSetting;
410 
411  $this->initFormLuceneSettings();
412 
413  $settings = ilSearchSettings::getInstance();
414  $settings->setDefaultOperator((int) $_POST['operator']);
415  $settings->setFragmentCount((int) $_POST['fragmentCount']);
416  $settings->setFragmentSize((int) $_POST['fragmentSize']);
417  $settings->setMaxSubitems((int) $_POST['maxSubitems']);
418  $settings->showRelevance((int) $_POST['relevance']);
419  $settings->enableLuceneItemFilter((int) $_POST['if']);
420  $settings->setLuceneItemFilter((array) $_POST['filter']);
421 
422  if($this->form->checkInput())
423  {
424  $settings->setLastIndexTime($this->form->getItemByPostVar('last_index')->getDate());
425  $settings->update();
426 
427  // refresh lucene server
428  $ilBench->start('Lucene','LuceneRefreshSettings');
429 
430  try {
431  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
432  ilRpcClientFactory::factory('RPCAdministration')->refreshSettings(
433  CLIENT_ID.'_'.$ilSetting->get('inst_id',0));
434 
435  ilUtil::sendInfo($this->lng->txt('settings_saved'));
436  $this->luceneSettingsObject();
437  return true;
438  }
439  catch(Exception $e)
440  {
441  $ilLog->write(__METHOD__.': '.$e->getMessage());
442  ilUtil::sendFailure($e->getMessage());
443  $this->luceneSettingsObject();
444  return false;
445  }
446  }
447 
448  ilUtil::sendInfo($this->lng->txt('err_check_input'));
449  $this->luceneSettingsObject();
450  return false;
451  }
452 
453  protected function advancedLuceneSettingsObject()
454  {
455  $this->initSubTabs('lucene');
456  $this->tabs_gui->setTabActive('lucene_advanced_settings');
457 
458  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchActivationTableGUI.php';
459  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
460 
461  $table = new ilLuceneAdvancedSearchActivationTableGUI($this,'advancedLuceneSettings');
462  $table->setTitle($this->lng->txt('lucene_advanced_settings_table'));
464 
465  $this->tpl->setContent($table->getHTML());
466  }
467 
468  protected function saveAdvancedLuceneSettingsObject()
469  {
470  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
471 
473  foreach(ilLuceneAdvancedSearchFields::getFields() as $field => $translation)
474  {
475  $settings->setActive($field,in_array($field,(array) $_POST['fid']) ? true : false);
476  }
477  $settings->save();
478  ilUtil::sendInfo($this->lng->txt('settings_saved'));
480  }
481 
485  protected function initSubTabs($a_section)
486  {
487  switch($a_section)
488  {
489  case 'lucene':
490  $this->tabs_gui->addSubTabTarget('lucene_general_settings',
491  $this->ctrl->getLinkTarget($this,'luceneSettings'));
492 
493  break;
494  }
495  }
496 
497 
498 } // END class.ilObjSearchSettingsGUI
499 ?>