ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSearchBaseGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
42 {
44 
45  public const SEARCH_FAST = 1;
46  public const SEARCH_DETAILS = 2;
47  public const SEARCH_AND = 'and';
48  public const SEARCH_OR = 'or';
49 
50  public const SEARCH_FORM_LUCENE = 1;
51  public const SEARCH_FORM_STANDARD = 2;
52  public const SEARCH_FORM_USER = 3;
53 
55  protected string $search_mode = '';
56 
58  protected ?ilPropertyFormGUI $form = null;
62 
63  protected ilCtrl $ctrl;
64  protected ILIAS $ilias;
65  protected ilLanguage $lng;
68  protected ilObjUser $user;
69  protected ilTree $tree;
71  protected Factory $refinery;
72 
73  protected ilLogger $logger;
74 
75 
76  protected string $prev_link = '';
77  protected string $next_link = '';
78 
79  public function __construct()
80  {
81  global $DIC;
82 
83 
84  $this->logger = $DIC->logger()->src();
85  $this->ilias = $DIC['ilias'];
86  $this->locator = $DIC['ilLocator'];
87  $this->ctrl = $DIC->ctrl();
88  $this->lng = $DIC->language();
89  $this->tpl = $DIC->ui()->mainTemplate();
90  $this->tree = $DIC->repositoryTree();
91 
92  $this->lng->loadLanguageModule('search');
93  $this->settings = new ilSearchSettings();
94  $this->favourites = new ilFavouritesManager();
95  $this->user = $DIC->user();
96  $this->clipboard = $DIC
97  ->repository()
98  ->internal()
99  ->domain()
100  ->clipboard();
101  $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
102  $this->http = $DIC->http();
103  $this->refinery = $DIC->refinery();
104  }
105 
106  protected function initPageNumberFromQuery(): int
107  {
108  if ($this->http->wrapper()->query()->has('page_number')) {
109  return $this->http->wrapper()->query()->retrieve(
110  'page_number',
111  $this->refinery->kindlyTo()->int()
112  );
113  }
114  return 0;
115  }
116 
117 
118  public function prepareOutput(): void
119  {
120  $this->tpl->loadStandardTemplate();
121 
122  $this->tpl->setTitleIcon(
123  ilObject::_getIcon(0, "big", "src"),
124  ""
125  );
126  $this->tpl->setTitle($this->lng->txt("search"));
127  }
128 
129  public function initStandardSearchForm(int $a_mode): ilPropertyFormGUI
130  {
131  $this->form = new ilPropertyFormGUI();
132  $this->form->setOpenTag(false);
133  $this->form->setCloseTag(false);
134 
135  // term combination
136  $radg = new ilHiddenInputGUI('search_term_combination');
137  $radg->setValue((string) ilSearchSettings::getInstance()->getDefaultOperator());
138  $this->form->addItem($radg);
139 
140  if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
141  if ($a_mode == self::SEARCH_FORM_STANDARD) {
142  // search type
143  $radg = new ilRadioGroupInputGUI($this->lng->txt("search_type"), "type");
144  $radg->setValue(
145  $this->getType() ==
149  );
150  $op1 = new ilRadioOption($this->lng->txt("search_fast_info"), (string) ilSearchBaseGUI::SEARCH_FAST);
151  $radg->addOption($op1);
152  $op2 = new ilRadioOption($this->lng->txt("search_details_info"), (string) ilSearchBaseGUI::SEARCH_DETAILS);
153  } else {
154  $op2 = new ilCheckboxInputGUI($this->lng->txt('search_filter_by_type'), 'item_filter_enabled');
155  $op2->setValue('1');
156  }
157 
158 
159  $cbgr = new ilCheckboxGroupInputGUI('', 'filter_type');
160  $cbgr->setUseValuesAsKeys(true);
161  $details = $this->getDetails();
162  $det = false;
163  foreach (ilSearchSettings::getInstance()->getEnabledLuceneItemFilterDefinitions() as $type => $data) {
164  $cb = new ilCheckboxOption($this->lng->txt($data['trans']), $type);
165  if (isset($details[$type])) {
166  $det = true;
167  }
168  $cbgr->addOption($cb);
169  }
170  $mimes = [];
171  if ($a_mode == self::SEARCH_FORM_LUCENE) {
172  if (ilSearchSettings::getInstance()->isLuceneMimeFilterEnabled()) {
173  $mimes = $this->getMimeDetails();
174  foreach (ilSearchSettings::getInstance()->getEnabledLuceneMimeFilterDefinitions() as $type => $data) {
175  $op3 = new ilCheckboxOption($this->lng->txt($data['trans']), $type);
176  if (isset($mimes[$type])) {
177  $det = true;
178  }
179  $cbgr->addOption($op3);
180  }
181  }
182  }
183 
184  $cbgr->setValue(array_merge((array) $details, (array) $mimes));
185  $op2->addSubItem($cbgr);
186 
187  if ($a_mode != self::SEARCH_FORM_STANDARD && $det) {
188  $op2->setChecked(true);
189  }
190 
191  if ($a_mode == ilSearchBaseGUI::SEARCH_FORM_STANDARD) {
192  $radg->addOption($op2);
193  $this->form->addItem($radg);
194  } else {
195  $this->form->addItem($op2);
196  }
197  }
198 
199  $this->form->setFormAction($this->ctrl->getFormAction($this, 'performSearch'));
200  return $this->form;
201  }
202 
203 
205  {
206  $form = new ilPropertyFormGUI();
207  $form->setOpenTag(false);
208  $form->setCloseTag(false);
209 
210  // term combination
211  $radg = new ilHiddenInputGUI('search_term_combination');
212  $radg->setValue((string) ilSearchSettings::getInstance()->getDefaultOperator());
213  $form->addItem($radg);
214 
215  // search area
216  $ti = new ilRepositorySelectorInputGUI($this->lng->txt("search_area"), "area");
217  $ti->setSelectText($this->lng->txt("search_select_search_area"));
218  $form->addItem($ti);
219  $ti->readFromSession();
220 
221  // alex, 15.8.2012: Added the following lines to get the value
222  // from the main menu top right input search form
223  if ($this->http->wrapper()->post()->has('root_id')) {
224  $ti->setValue(
225  $this->http->wrapper()->post()->retrieve(
226  'root_id',
227  $this->refinery->kindlyTo()->string()
228  )
229  );
230  $ti->writeToSession();
231  }
232  $form->setFormAction($this->ctrl->getFormAction($this, 'performSearch'));
233 
234  return $form;
235  }
236 
237 
238  public function handleCommand(string $a_cmd): void
239  {
240  if (method_exists($this, $a_cmd)) {
241  $this->$a_cmd();
242  } else {
243  $a_cmd .= 'Object';
244  $this->$a_cmd();
245  }
246  }
247 
248  public function addToDeskObject(): void
249  {
250  if ($this->http->wrapper()->query()->has('item_ref_id')) {
251  $this->favourites->add(
252  $this->user->getId(),
253  $this->http->wrapper()->query()->retrieve(
254  'item_ref_id',
255  $this->refinery->kindlyTo()->int()
256  )
257  );
258  }
259  $this->showSavedResults();
260  }
261 
262  public function removeFromDeskObject(): void
263  {
264  if ($this->http->wrapper()->query()->has('item_ref_id')) {
265  $this->favourites->remove(
266  $this->user->getId(),
267  $this->http->wrapper()->query()->retrieve(
268  'item_ref_id',
269  $this->refinery->kindlyTo()->int()
270  )
271  );
272  }
273  $this->showSavedResults();
274  }
275 
276  public function delete(): void
277  {
278  $admin = new ilAdministrationCommandGUI($this);
279  $admin->delete();
280  }
281 
282  public function cancelDelete(): void
283  {
284  $this->showSavedResults();
285  }
286 
287  public function cancelObject(): void
288  {
289  $this->showSavedResults();
290  }
291 
292  public function cancelMoveLinkObject(): void
293  {
294  $this->showSavedResults();
295  }
296 
297  public function performDelete(): void
298  {
299  $admin = new ilAdministrationCommandGUI($this);
300  $admin->performDelete();
301  }
302 
303  public function cut(): void
304  {
305  $admin = new ilAdministrationCommandGUI($this);
306  $admin->cut();
307  }
308 
309 
310  public function link(): void
311  {
312  $admin = new ilAdministrationCommandGUI($this);
313  $admin->link();
314  }
315 
316  public function paste(): void
317  {
318  $admin = new ilAdministrationCommandGUI($this);
319  $admin->paste();
320  }
321 
322  public function showLinkIntoMultipleObjectsTree(): void
323  {
324  $admin = new ilAdministrationCommandGUI($this);
325  $admin->showLinkIntoMultipleObjectsTree();
326  }
327 
328  public function showPasteTree(): void
329  {
330  $admin = new ilAdministrationCommandGUI($this);
331  $admin->showPasteTree();
332  }
333 
334 
335  public function showMoveIntoObjectTree(): void
336  {
337  $admin = new ilAdministrationCommandGUI($this);
338  $admin->showMoveIntoObjectTree();
339  }
340 
341  public function performPasteIntoMultipleObjects(): void
342  {
343  $admin = new ilAdministrationCommandGUI($this);
344  $admin->performPasteIntoMultipleObjects();
345  }
346 
347  public function clear(): void
348  {
349  $this->clipboard->clear();
350  $this->ctrl->redirect($this);
351  }
352 
353  public function enableAdministrationPanel(): void
354  {
355  }
356 
357  public function disableAdministrationPanel(): void
358  {
359  }
360 
364  public function keepObjectsInClipboardObject(): void
365  {
366  $this->ctrl->redirect($this);
367  }
368 
369 
370  public function addLocator(): void
371  {
372  $this->locator->addItem($this->lng->txt('search'), $this->ctrl->getLinkTarget($this));
373  $this->tpl->setLocator();
374  }
375 
379  protected function addPager($result, string $a_session_key): bool
380  {
381  $max_page = max(ilSession::get($a_session_key), $this->search_cache->getResultPageNumber());
382  ilSession::set($a_session_key, $max_page);
383 
384  if ($max_page == 1 and
385  (count($result->getResults()) < $result->getMaxHits())) {
386  return true;
387  }
388 
389  if ($this->search_cache->getResultPageNumber() > 1) {
390  $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() - 1);
391  $this->prev_link = $this->ctrl->getLinkTarget($this, 'performSearch');
392  }
393  for ($i = 1;$i <= $max_page;$i++) {
394  if ($i == $this->search_cache->getResultPageNumber()) {
395  continue;
396  }
397 
398  $this->ctrl->setParameter($this, 'page_number', $i);
399  $link = '<a href="' . $this->ctrl->getLinkTarget($this, 'performSearch') . '" /a>' . $i . '</a> ';
400  }
401  if (count($result->getResults()) >= $result->getMaxHits()) {
402  $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() + 1);
403  $this->next_link = $this->ctrl->getLinkTarget($this, 'performSearch');
404  }
405  $this->ctrl->clearParameters($this);
406  return false;
407  }
408 
409  protected function buildSearchAreaPath(int $a_root_node): string
410  {
411  $path_arr = $this->tree->getPathFull($a_root_node, ROOT_FOLDER_ID);
412  $counter = 0;
413  $path = '';
414  foreach ($path_arr as $data) {
415  if ($counter++) {
416  $path .= " > ";
417  $path .= $data['title'];
418  } else {
419  $path .= $this->lng->txt('repository');
420  }
421  }
422  return $path;
423  }
424 
425  public function autoComplete(): void
426  {
427  $query = '';
428  if ($this->http->wrapper()->post()->has('term')) {
429  $query = $this->http->wrapper()->post()->retrieve(
430  'term',
431  $this->refinery->kindlyTo()->string()
432  );
433  }
434  $list = ilSearchAutoComplete::getList($query);
435  echo $list;
436  exit;
437  }
438 
440  {
441  $options = $this->search_cache->getCreationFilter();
442 
443  $form = new ilPropertyFormGUI();
444  $form->setOpenTag(false);
445  $form->setCloseTag(false);
446 
447  $enabled = new ilCheckboxInputGUI($this->lng->txt('search_filter_cd'), 'screation');
448  $enabled->setValue('1');
449  $enabled->setChecked((bool) ($options['enabled'] ?? false));
450  $form->addItem($enabled);
451 
452 
453  $limit_sel = new ilSelectInputGUI('', 'screation_ontype');
454  $limit_sel->setValue($options['ontype'] ?? '');
455  $limit_sel->setOptions(
456  array(
457  1 => $this->lng->txt('search_created_after'),
458  2 => $this->lng->txt('search_created_before'),
459  3 => $this->lng->txt('search_created_on')
460  )
461  );
462  $enabled->addSubItem($limit_sel);
463 
464 
465  if ($options['date'] ?? false) {
466  $now = new ilDate($options['date'] ?? 0, IL_CAL_UNIX);
467  } else {
468  $now = new ilDate(time(), IL_CAL_UNIX);
469  }
470  $ds = new ilDateTimeInputGUI('', 'screation_date');
471  $ds->setRequired(true);
472  $ds->setDate($now);
473  $enabled->addSubItem($ds);
474 
475  $form->setFormAction($this->ctrl->getFormAction($this, 'performSearch'));
476 
477  return $form;
478  }
479 
480  protected function getSearchCache(): ilUserSearchCache
481  {
482  return $this->search_cache;
483  }
484 
488  protected function loadCreationFilter(): array
489  {
490  if (!$this->settings->isDateFilterEnabled()) {
491  return array();
492  }
493 
494 
495  $form = $this->getCreationDateForm();
496  $options = array();
497  if ($form->checkInput()) {
498  $options['enabled'] = $form->getInput('screation');
499  $options['type'] = $form->getInput('screation_type');
500  $options['ontype'] = $form->getInput('screation_ontype');
501  $options['date'] = $form->getItemByPostVar('screation_date')->getDate()->get(IL_CAL_UNIX);
502  $options['duration'] = $form->getInput('screation_duration');
503  }
504  return $options;
505  }
506 }
Interface GlobalHttpState.
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:29
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
This class represents a selection list property in a property form.
static getList(string $a_str)
getItemByPostVar(string $a_post_var)
const ROOT_FOLDER_ID
Definition: constants.php:32
ilPropertyFormGUI $form
Class ChatMainBarProvider .
Handles Administration commands (cut, delete paste)
setCloseTag(bool $a_val)
static _getInstance(int $a_usr_id)
ClipboardManager $clipboard
handleCommand(string $a_cmd)
const IL_CAL_UNIX
setOpenTag(bool $a_open)
Manages favourites, currently the interface for other components, needs discussion.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
$path
Definition: ltiservices.php:32
This class represents a date/time property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
array $details
Details for error message relating to last request processed.
Definition: System.php:109
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
setFormAction(string $a_formaction)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setValue(string $a_value)
cancelDelete()
Cancel delete.
header include for all ilias files.
Manages items in repository clipboard.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
form( $class_path, string $cmd, string $submit_caption="")
ilUserSearchCache $search_cache
clear()
clear clipboard
addPager($result, string $a_session_key)
initStandardSearchForm(int $a_mode)
Class for storing search result.
buildSearchAreaPath(int $a_root_node)
GlobalHttpState $http
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilFavouritesManager $favourites
static set(string $a_var, $a_val)
Set a value.
ilSearchSettings $settings
ViewManager $container_view_manager
ilGlobalTemplateInterface $tpl