ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 __construct($a_data,$a_id,$a_call_by_reference,$a_prepare_output = true)
24  {
25  $this->type = "seas";
26  parent::__construct($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()
127  {
128  $this->getTabs();
129  }
130 
136  function getTabs()
137  {
138  global $rbacsystem;
139 
140  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
141  {
142  $this->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  $this->tabs_gui->addTarget('lucene_advanced_settings',
149  $this->ctrl->getLinkTarget($this,'advancedLuceneSettings'));
150  }
151 
152  if($rbacsystem->checkAccess('read',$this->object->getRefId()))
153  {
154  $this->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  $this->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 <= 50; $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  // user search
230  $us = new ilCheckboxInputGUI($this->lng->txt('search_user_search_form'),'user_search_enabled');
231  $us->setInfo($this->lng->txt('search_user_search_info_form'));
232  $us->setValue(1);
233  $us->setChecked($settings->isLuceneUserSearchEnabled());
234  $this->form->addItem($us);
235 
236 
237  // Item filter
238  $if = new ilCheckboxInputGUI($this->lng->txt('search_item_filter_form'),'if');
239  $if->setValue(1);
240  $if->setChecked($settings->isLuceneItemFilterEnabled());
241  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
242  $this->form->addItem($if);
243 
244  $filter = $settings->getLuceneItemFilter();
245  foreach(ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def)
246  {
247  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']),'filter['.$obj.']');
248  if(isset($filter[$obj]) and $filter[$obj])
249  {
250  $ch->setChecked(true);
251  }
252  $ch->setValue(1);
253  $if->addSubItem($ch);
254  }
255 
256  $cdate = new ilCheckboxInputGUI($this->lng->txt('search_cdate_filter'), 'cdate');
257  $cdate->setInfo($this->lng->txt('search_cdate_filter_info'));
258  $cdate->setChecked($settings->isDateFilterEnabled());
259  $cdate->setValue(1);
260  $this->form->addItem($cdate);
261 
262  // hide advanced search
263  $cb = new ilCheckboxInputGUI($lng->txt("search_hide_adv_search"), "hide_adv_search");
264  $cb->setChecked($settings->getHideAdvancedSearch());
265  $this->form->addItem($cb);
266 
267  // number of auto complete entries
268  $options = array(
269  5 => 5,
270  10 => 10,
271  20 => 20,
272  30 => 30
273  );
274  $si = new ilSelectInputGUI($lng->txt("search_auto_complete_length"), "auto_complete_length");
275  $si->setOptions($options);
276  $val = ($settings->getAutoCompleteLength() > 0)
277  ? $settings->getAutoCompleteLength()
278  : 10;
279  $si->setValue($val);
280  $this->form->addItem($si);
281 
282 
283  $direct = new ilRadioOption($this->lng->txt('search_direct'),ilSearchSettings::LIKE_SEARCH,$this->lng->txt('search_like_info'));
284  $type->addOption($direct);
285 
286  if($ilDB->supportsFulltext())
287  {
288  $index = new ilRadioOption($this->lng->txt('search_index'),ilSearchSettings::INDEX_SEARCH,$this->lng->txt('search_full_info'));
289  $type->addOption($index);
290  }
291 
292  $lucene = new ilRadioOption($this->lng->txt('search_lucene'),ilSearchSettings::LUCENE_SEARCH,$this->lng->txt('java_server_info'));
293  $type->addOption($lucene);
294 
295  $inactive_user = new ilCheckboxInputGUI($this->lng->txt('search_show_inactive_user'), 'inactive_user');
296  $inactive_user->setInfo($this->lng->txt('search_show_inactive_user_info'));
297  $inactive_user->setChecked($settings->isInactiveUserVisible());
298  $this->form->addItem($inactive_user);
299 
300  $limited_user = new ilCheckboxInputGUI($this->lng->txt('search_show_limited_user'), 'limited_user');
301  $limited_user->setInfo($this->lng->txt('search_show_limited_user_info'));
302  $limited_user->setChecked($settings->isLimitedUserVisible());
303  $this->form->addItem($limited_user);
304  }
305 
306 
311  protected function updateSettingsObject()
312  {
313  global $ilAccess,$ilErr;
314 
315  $this->initFormSettings();
316  $this->form->checkInput();
317 
318  if(!$ilAccess->checkAccess('write','',$this->object->getRefId()))
319  {
320  $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->MESSAGE);
321  }
322 
323  include_once './Services/Search/classes/class.ilSearchSettings.php';
324  $settings = ilSearchSettings::getInstance();
325  $settings->setMaxHits((int) $_POST['max_hits']);
326 
327  switch((int) $_POST['search_type'])
328  {
330  $settings->enableIndex(false);
331  $settings->enableLucene(false);
332  break;
334  $settings->enableIndex(true);
335  $settings->enableLucene(false);
336  break;
338  $settings->enableIndex(false);
339  $settings->enableLucene(true);
340  break;
341  }
342 
343  $settings->setDefaultOperator((int) $_POST['operator']);
344  $settings->enableLuceneItemFilter((int) $_POST['if']);
345  $settings->setLuceneItemFilter((array) $_POST['filter']);
346 
347  $settings->setHideAdvancedSearch($_POST['hide_adv_search']);
348  $settings->setAutoCompleteLength($_POST['auto_complete_length']);
349  $settings->showInactiveUser($_POST["inactive_user"]);
350  $settings->showLimitedUser($_POST["limited_user"]);
351  $settings->enableDateFilter($_POST['cdate']);
352  $settings->enableLuceneUserSearch((int) $_POST['user_search_enabled']);
353  $settings->update();
354 
355 
356  // refresh lucene server
357  try {
358  $this->refreshLuceneSettings();
359  ilUtil::sendInfo($this->lng->txt('settings_saved'));
360  $this->settingsObject();
361  return true;
362  }
363  catch (Exception $exception)
364  {
365  ilUtil::sendFailure($exception->getMessage());
366  $this->settingsObject();
367  return false;
368  }
369 
370  unset($_SESSION['search_last_class']);
371  }
372 
378  protected function luceneSettingsObject(ilPropertyFormGUI $form = null)
379  {
380  $this->initSubTabs('lucene');
381  $this->tabs_gui->setTabActive('lucene_settings_tab');
382 
383  if(!$form instanceof ilPropertyFormGUI)
384  {
385  $this->initFormLuceneSettings();
386  }
387  $this->tpl->setContent($this->form->getHTML());
388  }
389 
395  protected function initFormLuceneSettings()
396  {
397  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
398  include_once './Services/Search/classes/class.ilSearchSettings.php';
399 
401 
402  $this->form = new ilPropertyFormGUI();
403  $this->form->setFormAction($this->ctrl->getFormAction($this,'cancel'));
404 
405  $this->form->setTitle($this->lng->txt('lucene_settings_title'));
406  $this->form->addCommandButton('saveLuceneSettings',$this->lng->txt('save'));
407  $this->form->addCommandButton('cancel',$this->lng->txt('cancel'));
408 
409 
410  // Offline filter
411  /*
412  $offline = new ilCheckboxInputGUI($this->lng->txt('lucene_offline_filter_setting'),'offline_filter');
413  $offline->setInfo($this->lng->txt('lucene_offline_filter_setting_info'));
414  $offline->setValue(1);
415  $offline->setChecked($this->settings->isLuceneOfflineFilterEnabled());
416  $this->form->addItem($offline);
417  */
418 
419 
420  // Item filter
421  $if = new ilCheckboxInputGUI($this->lng->txt('search_mime_filter_form'),'mime_enabled');
422  $if->setValue(1);
423  $if->setChecked($this->settings->isLuceneMimeFilterEnabled());
424  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
425  $this->form->addItem($if);
426 
427  $mimes = $this->settings->getLuceneMimeFilter();
428  foreach(ilSearchSettings::getLuceneMimeFilterDefinitions() as $mime => $def)
429  {
430  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']),'mime['.$mime.']');
431  if(isset($mimes[$mime]) and $mimes[$mime])
432  {
433  $ch->setChecked(true);
434  }
435  $ch->setValue(1);
436  $if->addSubItem($ch);
437  }
438 
439  $prefix = new ilCheckboxInputGUI($this->lng->txt('lucene_prefix_wildcard'),'prefix');
440  $prefix->setValue(1);
441  $prefix->setInfo($this->lng->txt('lucene_prefix_wildcard_info'));
442  $prefix->setChecked($this->settings->isPrefixWildcardQueryEnabled());
443  $this->form->addItem($prefix);
444 
445 
446  $numFrag = new ilNumberInputGUI($this->lng->txt('lucene_num_fragments'),'fragmentCount');
447  $numFrag->setRequired(true);
448  $numFrag->setSize(2);
449  $numFrag->setMaxLength(2);
450  $numFrag->setMinValue(1);
451  $numFrag->setMaxValue(10);
452  $numFrag->setInfo($this->lng->txt('lucene_num_frag_info'));
453  $numFrag->setValue($this->settings->getFragmentCount());
454  $this->form->addItem($numFrag);
455 
456  $sizeFrag = new ilNumberInputGUI($this->lng->txt('lucene_size_fragments'),'fragmentSize');
457  $sizeFrag->setRequired(true);
458  $sizeFrag->setSize(2);
459  $sizeFrag->setMaxLength(4);
460  $sizeFrag->setMinValue(10);
461  $sizeFrag->setMaxValue(1000);
462  $sizeFrag->setInfo($this->lng->txt('lucene_size_frag_info'));
463  $sizeFrag->setValue($this->settings->getFragmentSize());
464  $this->form->addItem($sizeFrag);
465 
466  $maxSub = new ilNumberInputGUI($this->lng->txt('lucene_max_sub'),'maxSubitems');
467  $maxSub->setRequired(true);
468  $maxSub->setSize(2);
469  $maxSub->setMaxLength(2);
470  $maxSub->setMinValue(1);
471  $maxSub->setMaxValue(10);
472  $maxSub->setInfo($this->lng->txt('lucene_max_sub_info'));
473  $maxSub->setValue($this->settings->getMaxSubitems());
474  $this->form->addItem($maxSub);
475 
476  $relevance = new ilCheckboxInputGUI($this->lng->txt('lucene_relevance'),'relevance');
477  $relevance->setOptionTitle($this->lng->txt('lucene_show_relevance'));
478  $relevance->setInfo($this->lng->txt('lucene_show_relevance_info'));
479  $relevance->setValue(1);
480  $relevance->setChecked($this->settings->isRelevanceVisible());
481  $this->form->addItem($relevance);
482 
483  // begin-patch mime_filter
484  $subrel = new ilCheckboxInputGUI('','subrelevance');
485  $subrel->setOptionTitle($this->lng->txt('lucene_show_sub_relevance'));
486  $subrel->setValue(1);
487  $subrel->setChecked($this->settings->isSubRelevanceVisible());
488  $relevance->addSubItem($subrel);
489  // end-patch mime_filter
490 
491  $last_index = new ilDateTimeInputGUI($this->lng->txt('lucene_last_index_time'),'last_index');
492  $last_index->setRequired(true);
493  $last_index->setShowTime(true);
494  $last_index->setDate($this->settings->getLastIndexTime());
495  $last_index->setInfo($this->lng->txt('lucene_last_index_time_info'));
496  $this->form->addItem($last_index);
497 
498  return true;
499  }
500 
505  protected function saveLuceneSettingsObject()
506  {
507  global $ilBench,$ilLog,$ilSetting;
508 
509  $this->initFormLuceneSettings();
510 
511  $settings = ilSearchSettings::getInstance();
512  $settings->setFragmentCount((int) $_POST['fragmentCount']);
513  $settings->setFragmentSize((int) $_POST['fragmentSize']);
514  $settings->setMaxSubitems((int) $_POST['maxSubitems']);
515  $settings->showRelevance((int) $_POST['relevance']);
516  $settings->enableLuceneOfflineFilter((int) $_POST['offline_filter']);
517  $settings->enableLuceneMimeFilter((int) $_POST['mime_enabled']);
518  $settings->setLuceneMimeFilter((array) $_POST['mime']);
519  $settings->showSubRelevance((int) $_POST['subrelevance']);
520  $settings->enablePrefixWildcardQuery((int) $_POST['prefix']);
521 
522  if($this->form->checkInput())
523  {
524  $settings->setLastIndexTime($this->form->getItemByPostVar('last_index')->getDate());
525  $settings->update();
526 
527  // refresh lucene server
528  try {
529  $this->refreshLuceneSettings();
530  ilUtil::sendInfo($this->lng->txt('settings_saved'));
531  $this->luceneSettingsObject();
532  return true;
533  }
534  catch (Exception $exception)
535  {
536  ilUtil::sendFailure($exception->getMessage());
537  $this->luceneSettingsObject();
538  return false;
539  }
540  }
541 
542  ilUtil::sendInfo($this->lng->txt('err_check_input'));
543  $this->form->setValuesByPost();
544  $this->luceneSettingsObject($this->form);
545  return false;
546  }
547 
552  protected function refreshLuceneSettings()
553  {
554  global $ilSetting;
555 
556  if(!ilSearchSettings::getInstance()->enabledLucene())
557  {
558  return true;
559  }
560 
561  try
562  {
563  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
564  ilRpcClientFactory::factory('RPCAdministration')->refreshSettings(CLIENT_ID.'_'.$ilSetting->get('inst_id',0));
565  }
566  catch (Exception $exception) {
567  ilLoggerFactory::getLogger('src')->error('Refresh of lucene server settings failed with message: ' . $exception->getMessage());
568  throw $exception;
569  }
570  }
571 
572  protected function advancedLuceneSettingsObject()
573  {
574  $this->initSubTabs('lucene');
575  $this->tabs_gui->setTabActive('lucene_advanced_settings');
576 
577  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchActivationTableGUI.php';
578  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
579 
580  $table = new ilLuceneAdvancedSearchActivationTableGUI($this,'advancedLuceneSettings');
581  $table->setTitle($this->lng->txt('lucene_advanced_settings_table'));
583 
584  $this->tpl->setContent($table->getHTML());
585  }
586 
587  protected function saveAdvancedLuceneSettingsObject()
588  {
589  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
590 
592  foreach(ilLuceneAdvancedSearchFields::getFields() as $field => $translation)
593  {
594  $settings->setActive($field,in_array($field,(array) $_POST['fid']) ? true : false);
595  }
596  $settings->save();
597  ilUtil::sendInfo($this->lng->txt('settings_saved'));
599  }
600 
604  protected function initSubTabs($a_section)
605  {
606  switch($a_section)
607  {
608  case 'lucene':
609  $this->tabs_gui->addSubTabTarget('lucene_general_settings',
610  $this->ctrl->getLinkTarget($this,'luceneSettings'));
611 
612  break;
613  }
614  }
615 
616 
617 } // END class.ilObjSearchSettingsGUI
618 ?>
global $ilErr
Definition: raiseError.php:16
This class represents an option in a radio group.
settingsObject()
Show settings public.
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
saveLuceneSettingsObject()
Save Lucene settings.
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
$cmd
Definition: sahs_server.php:35
initFormSettings()
Init settings form.
This class represents a checkbox property in a property form.
This class represents a date/time property in a property form.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
initFormLuceneSettings()
Show lucene settings form.
setChecked($a_checked)
Set Checked.
prepareOutput($a_show_subobjects=true)
prepare output
This class represents a property in a property form.
static getLuceneMimeFilterDefinitions()
if(!is_array($argv)) $options
setValue($a_value)
Set Value.
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
setValue($a_value)
Set Value.
redirection script todo: (a better solution should control the processing via a xml file) ...
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
settings()
Definition: settings.php:2
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor public.
Create new PHPExcel object
obj_idprivate
luceneSettingsObject(ilPropertyFormGUI $form=null)
Lucene settings.
global $ilSetting
Definition: privfeed.php:17
global $ilBench
Definition: ilias.php:18
global $ilDB
$ret
Definition: parser.php:6
static getFields()
Return an array of all meta data fields.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static getLogger($a_component_id)
Get component logger.
refreshLuceneSettings()
Refresh lucene server settings.
setOptionTitle($a_optiontitle)
Set Option Title (optional).
$_POST["username"]
saveSettingsObject()
Save settings public.
setRequired($a_required)
Set Required.
static getInstance()
Get singelton instance.