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