ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules 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 {
19 
23  protected $dic;
27  protected $error;
32  public function __construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
33  {
34  global $DIC, $ilErr;
35  $this->dic = $DIC;
36  $this->error = $ilErr;
37  $this->type = "seas";
38  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
39 
40  $this->lng->loadLanguageModule('search');
41  }
42 
43  public function executeCommand()
44  {
45  $next_class = $this->ctrl->getNextClass($this);
46  $cmd = $this->ctrl->getCmd();
47  $this->prepareOutput();
48 
49  switch ($next_class) {
50  case 'ilpermissiongui':
51  $this->tabs_gui->setTabActive('perm_settings');
52  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
53  $perm_gui = new ilPermissionGUI($this);
54  $ret = &$this->ctrl->forwardCommand($perm_gui);
55  break;
56 
57  default:
58  if ($cmd == "" || $cmd == "view") {
59  $cmd = "settings";
60  }
61  $cmd .= "Object";
62  $this->$cmd();
63 
64  break;
65  }
66  return true;
67  }
68 
69  public function cancelObject()
70  {
71  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
72  $this->ctrl->redirect($this, "settings");
73  }
74 
79  public function settingsObject()
80  {
81  if (!$this->dic->rbac()->system()->checkAccess("visible,read", $this->object->getRefId())) {
82  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
83  }
84  $this->tabs_gui->setTabActive('settings');
85  $this->initFormSettings();
86  $this->tpl->setContent($this->form->getHTML());
87  return true;
88  }
89 
94  public function saveSettingsObject()
95  {
96  include_once 'Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
97 
98  global $DIC;
99 
100  $rbacsystem = $DIC['rbacsystem'];
101 
102  if (!$rbacsystem->checkAccess('write', $this->object->getRefId())) {
103  $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
104  }
105 
106  $this->object->initSettingsObject();
107  $this->object->settings_obj->setMaxHits((int) $_POST['max_hits']);
108  $this->object->settings_obj->enableIndex($_POST['search_index']);
109  $this->object->settings_obj->enableLucene($_POST['search_lucene']);
110  $this->object->settings_obj->setHideAdvancedSearch($_POST['hide_adv_search']);
111  $this->object->settings_obj->setAutoCompleteLength($_POST['auto_complete_length']);
112  $this->object->settings_obj->setDefaultOperator((int) $_POST['operator']);
113  $this->object->settings_obj->enableLuceneItemFilter((int) $_POST['if']);
114  $this->object->settings_obj->setLuceneItemFilter((array) $_POST['filter']);
115 
116 
117  $rpc_settings = ilRPCServerSettings::getInstance();
118  if ($this->object->settings_obj->enabledLucene() and !$rpc_settings->pingServer()) {
119  ilUtil::sendInfo($this->lng->txt('search_no_connection_lucene'), true);
120  $this->ctrl->redirect($this, 'settings');
121 
122  return false;
123  }
124 
125  $this->object->settings_obj->update();
126 
127  ilUtil::sendInfo($this->lng->txt('settings_saved'), true);
128  $this->ctrl->redirect($this, 'settings');
129 
130  return true;
131  }
132 
133  public function getAdminTabs()
134  {
135  $this->getTabs();
136  }
137 
143  public function getTabs()
144  {
145  global $DIC;
146 
147  $rbacsystem = $DIC['rbacsystem'];
148 
149  if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
150  $this->tabs_gui->addTarget(
151  "settings",
152  $this->ctrl->getLinkTarget($this, "settings"),
153  array("settings","", "view"),
154  "",
155  ""
156  );
157  }
158 
159  if ($rbacsystem->checkAccess('read', $this->object->getRefId())) {
160  $this->tabs_gui->addTarget(
161  'lucene_advanced_settings',
162  $this->ctrl->getLinkTarget($this, 'advancedLuceneSettings')
163  );
164  }
165 
166  if ($rbacsystem->checkAccess('read', $this->object->getRefId())) {
167  $this->tabs_gui->addTarget(
168  'lucene_settings_tab',
169  $this->ctrl->getLinkTarget($this, 'luceneSettings')
170  );
171  }
172 
173 
174  if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
175  $this->tabs_gui->addTarget(
176  "perm_settings",
177  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
178  array("perm","info","owner"),
179  'ilpermissiongui'
180  );
181  }
182  }
183 
188  protected function initFormSettings()
189  {
190  global $DIC;
191 
192  $lng = $DIC['lng'];
193  $ilDB = $DIC['ilDB'];
194 
195  $access = $GLOBALS['DIC']->access();
196 
197  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
198  include_once './Services/Search/classes/class.ilSearchSettings.php';
199 
200  $settings = new ilSearchSettings();
201 
202  $this->form = new ilPropertyFormGUI();
203  $this->form->setFormAction($this->ctrl->getFormAction($this, 'updateSettings'));
204 
205  if ($access->checkAccess('write', '', $this->object->getRefId())) {
206  $this->form->addCommandButton('updateSettings', $this->lng->txt('save'));
207  }
208  $this->form->setTitle($this->lng->txt('seas_settings'));
209 
210  // Max hits
211  $hits = new ilSelectInputGUI($this->lng->txt('seas_max_hits'), 'max_hits');
212  $hits->setValue($settings->getMaxHits());
213  $hits->setRequired(true);
214  for ($value = 5; $value <= 50; $value += 5) {
215  $values[$value] = $value;
216  }
217  $hits->setOptions($values);
218  $hits->setInfo($this->lng->txt('seas_max_hits_info'));
219  $this->form->addItem($hits);
220 
221 
222  // Search type
223  $type = new ilRadioGroupInputGUI($this->lng->txt('search_type'), 'search_type');
224 
225  if ($settings->enabledLucene()) {
227  } elseif ($settings->enabledIndex()) {
229  } else {
231  }
232  $type->setRequired(true);
233  $this->form->addItem($type);
234 
235  // Default operator
236  $operator = new ilRadioGroupInputGUI($this->lng->txt('lucene_default_operator'), 'operator');
237  $operator->setRequired(true);
238  $operator->setInfo($this->lng->txt('lucene_default_operator_info'));
239  $operator->setValue($settings->getDefaultOperator());
240 
241  $and = new ilRadioOption($this->lng->txt('lucene_and'), ilSearchSettings::OPERATOR_AND);
242  $operator->addOption($and);
243 
244  $or = new ilRadioOption($this->lng->txt('lucene_or'), ilSearchSettings::OPERATOR_OR);
245  $operator->addOption($or);
246  $this->form->addItem($operator);
247 
248  // user search
249  $us = new ilCheckboxInputGUI($this->lng->txt('search_user_search_form'), 'user_search_enabled');
250  $us->setInfo($this->lng->txt('search_user_search_info_form'));
251  $us->setValue(1);
252  $us->setChecked($settings->isLuceneUserSearchEnabled());
253  $this->form->addItem($us);
254 
255 
256  // Item filter
257  $if = new ilCheckboxInputGUI($this->lng->txt('search_item_filter_form'), 'if');
258  $if->setValue(1);
259  $if->setChecked($settings->isLuceneItemFilterEnabled());
260  $if->setInfo($this->lng->txt('search_item_filter_form_info'));
261  $this->form->addItem($if);
262 
263  $filter = $settings->getLuceneItemFilter();
264  foreach (ilSearchSettings::getLuceneItemFilterDefinitions() as $obj => $def) {
265  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']), 'filter[' . $obj . ']');
266  if (isset($filter[$obj]) and $filter[$obj]) {
267  $ch->setChecked(true);
268  }
269  $ch->setValue(1);
270  $if->addSubItem($ch);
271  }
272 
273  $cdate = new ilCheckboxInputGUI($this->lng->txt('search_cdate_filter'), 'cdate');
274  $cdate->setInfo($this->lng->txt('search_cdate_filter_info'));
275  $cdate->setChecked($settings->isDateFilterEnabled());
276  $cdate->setValue(1);
277  $this->form->addItem($cdate);
278 
279  // hide advanced search
280  $cb = new ilCheckboxInputGUI($lng->txt("search_hide_adv_search"), "hide_adv_search");
281  $cb->setChecked($settings->getHideAdvancedSearch());
282  $this->form->addItem($cb);
283 
284 
285 
286  $direct = new ilRadioOption($this->lng->txt('search_direct'), ilSearchSettings::LIKE_SEARCH, $this->lng->txt('search_like_info'));
287  $type->addOption($direct);
288 
289  if ($ilDB->supportsFulltext()) {
290  $index = new ilRadioOption($this->lng->txt('search_index'), ilSearchSettings::INDEX_SEARCH, $this->lng->txt('search_full_info'));
291  $type->addOption($index);
292  }
293 
294  $lucene = new ilRadioOption($this->lng->txt('search_lucene'), ilSearchSettings::LUCENE_SEARCH, $this->lng->txt('java_server_info'));
295  $type->addOption($lucene);
296 
297 
298  // number of auto complete entries
299  $options = array(
300  5 => 5,
301  10 => 10,
302  20 => 20,
303  30 => 30
304  );
305  $si = new ilSelectInputGUI($lng->txt("search_auto_complete_length"), "auto_complete_length");
306  $si->setOptions($options);
307  $val = ($settings->getAutoCompleteLength() > 0)
308  ? $settings->getAutoCompleteLength()
309  : 10;
310  $si->setValue($val);
311  $this->form->addItem($si);
312 
313  $inactive_user = new ilCheckboxInputGUI($this->lng->txt('search_show_inactive_user'), 'inactive_user');
314  $inactive_user->setInfo($this->lng->txt('search_show_inactive_user_info'));
315  $inactive_user->setChecked($settings->isInactiveUserVisible());
316  $this->form->addItem($inactive_user);
317 
318  $limited_user = new ilCheckboxInputGUI($this->lng->txt('search_show_limited_user'), 'limited_user');
319  $limited_user->setInfo($this->lng->txt('search_show_limited_user_info'));
320  $limited_user->setChecked($settings->isLimitedUserVisible());
321  $this->form->addItem($limited_user);
322  }
323 
324 
329  protected function updateSettingsObject()
330  {
331  global $DIC;
332 
333  $ilAccess = $DIC['ilAccess'];
334 
335  $this->initFormSettings();
336  $this->form->checkInput();
337 
338  if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
339  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
340  $GLOBALS['DIC']->ctrl()->redirect($this, 'settings');
341  }
342 
343  include_once './Services/Search/classes/class.ilSearchSettings.php';
345  $settings->setMaxHits((int) $_POST['max_hits']);
346 
347  switch ((int) $_POST['search_type']) {
349  $settings->enableIndex(false);
350  $settings->enableLucene(false);
351  break;
353  $settings->enableIndex(true);
354  $settings->enableLucene(false);
355  break;
357  $settings->enableIndex(false);
358  $settings->enableLucene(true);
359  break;
360  }
361 
362  $settings->setDefaultOperator((int) $_POST['operator']);
363  $settings->enableLuceneItemFilter((int) $_POST['if']);
364  $settings->setLuceneItemFilter((array) $_POST['filter']);
365 
366  $settings->setHideAdvancedSearch($_POST['hide_adv_search']);
367  $settings->setAutoCompleteLength($_POST['auto_complete_length']);
368  $settings->showInactiveUser($_POST["inactive_user"]);
369  $settings->showLimitedUser($_POST["limited_user"]);
370  $settings->enableDateFilter($_POST['cdate']);
371  $settings->enableLuceneUserSearch((int) $_POST['user_search_enabled']);
372  $settings->update();
373 
374 
375  // refresh lucene server
376  try {
377  $this->refreshLuceneSettings();
378  ilUtil::sendInfo($this->lng->txt('settings_saved'));
379  $this->settingsObject();
380  return true;
381  } catch (Exception $exception) {
382  ilUtil::sendFailure($exception->getMessage());
383  $this->settingsObject();
384  return false;
385  }
386 
387  unset($_SESSION['search_last_class']);
388  }
389 
395  protected function luceneSettingsObject(ilPropertyFormGUI $form = null)
396  {
397  $this->initSubTabs('lucene');
398  $this->tabs_gui->setTabActive('lucene_settings_tab');
399 
400  if (!$form instanceof ilPropertyFormGUI) {
401  $this->initFormLuceneSettings();
402  }
403  $this->tpl->setContent($this->form->getHTML());
404  }
405 
411  protected function initFormLuceneSettings()
412  {
413  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
414  include_once './Services/Search/classes/class.ilSearchSettings.php';
415 
417 
418  $this->form = new ilPropertyFormGUI();
419  $this->form->setFormAction($this->ctrl->getFormAction($this, 'cancel'));
420 
421  $this->form->setTitle($this->lng->txt('lucene_settings_title'));
422 
423  $access = $GLOBALS['DIC']->access();
424  if ($access->checkAccess('write', '', $this->object->getRefId())) {
425  $this->form->addCommandButton('saveLuceneSettings', $this->lng->txt('save'));
426  }
427 
428 
429 
430  // Item filter
431  $if = new ilCheckboxInputGUI($this->lng->txt('search_mime_filter_form'), 'mime_enabled');
432  $if->setValue(1);
433  $if->setChecked($this->settings->isLuceneMimeFilterEnabled());
434  $if->setInfo($this->lng->txt('search_mime_filter_form_info'));
435  $this->form->addItem($if);
436 
437  $mimes = $this->settings->getLuceneMimeFilter();
438  foreach (ilSearchSettings::getLuceneMimeFilterDefinitions() as $mime => $def) {
439  $ch = new ilCheckboxInputGUI($this->lng->txt($def['trans']), 'mime[' . $mime . ']');
440  if (isset($mimes[$mime]) and $mimes[$mime]) {
441  $ch->setChecked(true);
442  }
443  $ch->setValue(1);
444  $if->addSubItem($ch);
445  }
446 
447  $prefix = new ilCheckboxInputGUI($this->lng->txt('lucene_prefix_wildcard'), 'prefix');
448  $prefix->setValue(1);
449  $prefix->setInfo($this->lng->txt('lucene_prefix_wildcard_info'));
450  $prefix->setChecked($this->settings->isPrefixWildcardQueryEnabled());
451  $this->form->addItem($prefix);
452 
453 
454  $numFrag = new ilNumberInputGUI($this->lng->txt('lucene_num_fragments'), 'fragmentCount');
455  $numFrag->setRequired(true);
456  $numFrag->setSize(2);
457  $numFrag->setMaxLength(2);
458  $numFrag->setMinValue(1);
459  $numFrag->setMaxValue(10);
460  $numFrag->setInfo($this->lng->txt('lucene_num_frag_info'));
461  $numFrag->setValue($this->settings->getFragmentCount());
462  $this->form->addItem($numFrag);
463 
464  $sizeFrag = new ilNumberInputGUI($this->lng->txt('lucene_size_fragments'), 'fragmentSize');
465  $sizeFrag->setRequired(true);
466  $sizeFrag->setSize(2);
467  $sizeFrag->setMaxLength(4);
468  $sizeFrag->setMinValue(10);
469  $sizeFrag->setMaxValue(1000);
470  $sizeFrag->setInfo($this->lng->txt('lucene_size_frag_info'));
471  $sizeFrag->setValue($this->settings->getFragmentSize());
472  $this->form->addItem($sizeFrag);
473 
474  $maxSub = new ilNumberInputGUI($this->lng->txt('lucene_max_sub'), 'maxSubitems');
475  $maxSub->setRequired(true);
476  $maxSub->setSize(2);
477  $maxSub->setMaxLength(2);
478  $maxSub->setMinValue(1);
479  $maxSub->setMaxValue(10);
480  $maxSub->setInfo($this->lng->txt('lucene_max_sub_info'));
481  $maxSub->setValue($this->settings->getMaxSubitems());
482  $this->form->addItem($maxSub);
483 
484  $relevance = new ilCheckboxInputGUI($this->lng->txt('lucene_relevance'), 'relevance');
485  $relevance->setOptionTitle($this->lng->txt('lucene_show_relevance'));
486  $relevance->setInfo($this->lng->txt('lucene_show_relevance_info'));
487  $relevance->setValue(1);
488  $relevance->setChecked($this->settings->isRelevanceVisible());
489  $this->form->addItem($relevance);
490 
491  // begin-patch mime_filter
492  $subrel = new ilCheckboxInputGUI('', 'subrelevance');
493  $subrel->setOptionTitle($this->lng->txt('lucene_show_sub_relevance'));
494  $subrel->setValue(1);
495  $subrel->setChecked($this->settings->isSubRelevanceVisible());
496  $relevance->addSubItem($subrel);
497  // end-patch mime_filter
498 
499  $last_index = new ilDateTimeInputGUI($this->lng->txt('lucene_last_index_time'), 'last_index');
500  $last_index->setRequired(true);
501  $last_index->setShowTime(true);
502  $last_index->setDate($this->settings->getLastIndexTime());
503  $last_index->setInfo($this->lng->txt('lucene_last_index_time_info'));
504  $this->form->addItem($last_index);
505 
506  return true;
507  }
508 
513  protected function saveLuceneSettingsObject()
514  {
515  global $DIC;
516 
517  $ilBench = $DIC['ilBench'];
518  $ilLog = $DIC['ilLog'];
519  $ilSetting = $DIC['ilSetting'];
520 
521  $this->initFormLuceneSettings();
522 
524  $settings->setFragmentCount((int) $_POST['fragmentCount']);
525  $settings->setFragmentSize((int) $_POST['fragmentSize']);
526  $settings->setMaxSubitems((int) $_POST['maxSubitems']);
527  $settings->showRelevance((int) $_POST['relevance']);
528  $settings->enableLuceneOfflineFilter((int) $_POST['offline_filter']);
529  $settings->enableLuceneMimeFilter((int) $_POST['mime_enabled']);
530  $settings->setLuceneMimeFilter((array) $_POST['mime']);
531  $settings->showSubRelevance((int) $_POST['subrelevance']);
532  $settings->enablePrefixWildcardQuery((int) $_POST['prefix']);
533 
534  if ($this->form->checkInput()) {
535  $settings->setLastIndexTime($this->form->getItemByPostVar('last_index')->getDate());
536  $settings->update();
537 
538  // refresh lucene server
539  try {
540  $this->refreshLuceneSettings();
541  ilUtil::sendInfo($this->lng->txt('settings_saved'));
542  $this->luceneSettingsObject();
543  return true;
544  } catch (Exception $exception) {
545  ilUtil::sendFailure($exception->getMessage());
546  $this->luceneSettingsObject();
547  return false;
548  }
549  }
550 
551  ilUtil::sendInfo($this->lng->txt('err_check_input'));
552  $this->form->setValuesByPost();
553  $this->luceneSettingsObject($this->form);
554  return false;
555  }
556 
561  protected function refreshLuceneSettings()
562  {
563  global $DIC;
564 
565  $ilSetting = $DIC['ilSetting'];
566 
567  if (!ilSearchSettings::getInstance()->enabledLucene()) {
568  return true;
569  }
570 
571  try {
572  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
573  ilRpcClientFactory::factory('RPCAdministration')->refreshSettings(CLIENT_ID . '_' . $ilSetting->get('inst_id', 0));
574  } catch (Exception $exception) {
575  ilLoggerFactory::getLogger('src')->error('Refresh of lucene server settings failed with message: ' . $exception->getMessage());
576  throw $exception;
577  }
578  }
579 
583  protected function advancedLuceneSettingsObject()
584  {
585  $this->initSubTabs('lucene');
586  $this->tabs_gui->setTabActive('lucene_advanced_settings');
587 
588  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchActivationTableGUI.php';
589  include_once './Services/Search/classes/Lucene/class.ilLuceneAdvancedSearchSettings.php';
590 
591  $table = new ilLuceneAdvancedSearchActivationTableGUI($this, 'advancedLuceneSettings');
592  $table->setTitle($this->lng->txt('lucene_advanced_settings_table'));
594 
595  $this->tpl->setContent($table->getHTML());
596  }
597 
601  protected function saveAdvancedLuceneSettingsObject()
602  {
603  $access = $GLOBALS['DIC']->access();
604 
605  if (!$access->checkAccess('write', '', $this->object->getRefId())) {
606  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
607  $GLOBALS['DIC']->ctrl()->redirect($this, 'settings');
608  }
609 
610 
612  foreach (ilLuceneAdvancedSearchFields::getFields() as $field => $translation) {
613  $settings->setActive($field, in_array($field, (array) $_POST['fid']) ? true : false);
614  }
615  $settings->save();
616  ilUtil::sendInfo($this->lng->txt('settings_saved'));
618  }
619 
623  protected function initSubTabs($a_section)
624  {
625  switch ($a_section) {
626  case 'lucene':
627  $this->tabs_gui->addSubTabTarget(
628  'lucene_general_settings',
629  $this->ctrl->getLinkTarget($this, 'luceneSettings')
630  );
631 
632  break;
633  }
634  }
635 } // END class.ilObjSearchSettingsGUI
advancedLuceneSettingsObject()
show advanced settings
This class represents an option in a radio group.
settingsObject()
Show settings public.
static getLuceneItemFilterDefinitions()
Get lucene item filter definitions.
settings()
Definition: settings.php:2
$_SESSION["AccountId"]
This class represents a property form user interface.
saveLuceneSettingsObject()
Save Lucene settings.
$type
static factory($a_package, $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
initFormSettings()
Init settings form.
This class represents a checkbox property in a property form.
$index
Definition: metadata.php:128
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()
This class represents a number property in a property form.
Class ilObjectGUI Basic methods of all Output classes.
setValue($a_value)
Set Value.
const CLIENT_ID
Definition: constants.php:39
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
redirection script todo: (a better solution should control the processing via a xml file) ...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output=true)
Constructor public.
luceneSettingsObject(ilPropertyFormGUI $form=null)
Lucene settings.
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
global $ilBench
Definition: ilias.php:21
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.
saveAdvancedLuceneSettingsObject()
Save advanced settings.
static getInstance()
Get singelton instance.