ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSearchBaseGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\ILIASObject\Creation\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;
60 protected ?array $search_filter_data = null;
64
65 protected ilCtrl $ctrl;
66 protected ILIAS $ilias;
67 protected ilLanguage $lng;
70 protected ilObjUser $user;
71 protected ilTree $tree;
73 protected Factory $refinery;
74
75 protected ilLogger $logger;
76
77
78 protected string $prev_link = '';
79 protected string $next_link = '';
80
81 public function __construct()
82 {
83 global $DIC;
84
85
86 $this->logger = $DIC->logger()->src();
87 $this->ilias = $DIC['ilias'];
88 $this->locator = $DIC['ilLocator'];
89 $this->ctrl = $DIC->ctrl();
90 $this->lng = $DIC->language();
91 $this->tpl = $DIC->ui()->mainTemplate();
92 $this->tree = $DIC->repositoryTree();
93
94 $this->lng->loadLanguageModule('search');
95 $this->settings = new ilSearchSettings();
96 $this->favourites = new ilFavouritesManager();
97 $this->user = $DIC->user();
98 $this->clipboard = $DIC
99 ->repository()
100 ->internal()
101 ->domain()
102 ->clipboard();
103 $this->search_cache = ilUserSearchCache::_getInstance($this->user->getId());
104 $this->http = $DIC->http();
105 $this->refinery = $DIC->refinery();
106 }
107
108 protected function initPageNumberFromQuery(): int
109 {
110 if ($this->http->wrapper()->query()->has('page_number')) {
111 return $this->http->wrapper()->query()->retrieve(
112 'page_number',
113 $this->refinery->kindlyTo()->int()
114 );
115 }
116 return 0;
117 }
118
119
120 public function prepareOutput(): void
121 {
122 $this->tpl->loadStandardTemplate();
123
124 $this->tpl->setTitleIcon(
125 ilObject::_getIcon(0, "big", "src"),
126 ""
127 );
128 $this->tpl->setTitle($this->lng->txt("search"));
129 }
130
134 public function initStandardSearchForm(int $a_mode): ilPropertyFormGUI
135 {
136 $this->form = new ilPropertyFormGUI();
137 $this->form->setOpenTag(false);
138 $this->form->setCloseTag(false);
139
140 if (ilSearchSettings::getInstance()->isLuceneItemFilterEnabled()) {
141 $radg = new ilRadioGroupInputGUI($this->lng->txt("search_type"), "type");
142 if ($a_mode == self::SEARCH_FORM_STANDARD) {
143 // search type
144 $radg->setValue(
145 $this->getType() ==
146 self::SEARCH_FAST ?
147 (string) self::SEARCH_FAST :
148 (string) self::SEARCH_DETAILS
149 );
150 $op1 = new ilRadioOption($this->lng->txt("search_fast_info"), (string) self::SEARCH_FAST);
151 $radg->addOption($op1);
152 $op2 = new ilRadioOption($this->lng->txt("search_details_info"), (string) self::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 == self::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 public function handleCommand(string $a_cmd): void
204 {
205 if (method_exists($this, $a_cmd)) {
206 $this->$a_cmd();
207 } else {
208 $a_cmd .= 'Object';
209 $this->$a_cmd();
210 }
211 }
212
213 public function addToDeskObject(): void
214 {
215 if ($this->http->wrapper()->query()->has('item_ref_id')) {
216 $this->favourites->add(
217 $this->user->getId(),
218 $this->http->wrapper()->query()->retrieve(
219 'item_ref_id',
220 $this->refinery->kindlyTo()->int()
221 )
222 );
223 }
224 $this->showSavedResults();
225 }
226
227 public function removeFromDeskObject(): void
228 {
229 if ($this->http->wrapper()->query()->has('item_ref_id')) {
230 $this->favourites->remove(
231 $this->user->getId(),
232 $this->http->wrapper()->query()->retrieve(
233 'item_ref_id',
234 $this->refinery->kindlyTo()->int()
235 )
236 );
237 }
238 $this->showSavedResults();
239 }
240
241 public function delete(): void
242 {
243 $admin = new ilAdministrationCommandGUI($this);
244 $admin->delete();
245 }
246
247 public function cancelDelete(): void
248 {
249 $this->showSavedResults();
250 }
251
252 public function cancelObject(): void
253 {
254 $this->showSavedResults();
255 }
256
257 public function cancelMoveLinkObject(): void
258 {
259 $this->showSavedResults();
260 }
261
262 public function performDelete(): void
263 {
264 $admin = new ilAdministrationCommandGUI($this);
265 $admin->performDelete();
266 }
267
268 public function cut(): void
269 {
270 $admin = new ilAdministrationCommandGUI($this);
271 $admin->cut();
272 }
273
274
275 public function link(): void
276 {
277 $admin = new ilAdministrationCommandGUI($this);
278 $admin->link();
279 }
280
281 public function paste(): void
282 {
283 $admin = new ilAdministrationCommandGUI($this);
284 $admin->paste();
285 }
286
287 public function showLinkIntoMultipleObjectsTree(): void
288 {
289 $admin = new ilAdministrationCommandGUI($this);
290 $admin->showLinkIntoMultipleObjectsTree();
291 }
292
293 public function showPasteTree(): void
294 {
295 $admin = new ilAdministrationCommandGUI($this);
296 $admin->showPasteTree();
297 }
298
299
300 public function showMoveIntoObjectTree(): void
301 {
302 $admin = new ilAdministrationCommandGUI($this);
303 $admin->showMoveIntoObjectTree();
304 }
305
306 public function performPasteIntoMultipleObjects(): void
307 {
308 $admin = new ilAdministrationCommandGUI($this);
309 $admin->performPasteIntoMultipleObjects();
310 }
311
312 public function clear(): void
313 {
314 $this->clipboard->clear();
315 $this->ctrl->redirect($this);
316 }
317
318 public function enableAdministrationPanel(): void
319 {
320 }
321
322 public function disableAdministrationPanel(): void
323 {
324 }
325
329 public function keepObjectsInClipboardObject(): void
330 {
331 $this->ctrl->redirect($this);
332 }
333
334
335 public function addLocator(): void
336 {
337 $this->locator->addItem($this->lng->txt('search'), $this->ctrl->getLinkTarget($this));
338 $this->tpl->setLocator();
339 }
340
344 protected function addPager($result, string $a_session_key): bool
345 {
346 $max_page = max(ilSession::get($a_session_key), $this->search_cache->getResultPageNumber());
347 ilSession::set($a_session_key, $max_page);
348
349 if ($max_page == 1 and
350 (count($result->getResults()) < $result->getMaxHits())) {
351 return true;
352 }
353
354 if ($this->search_cache->getResultPageNumber() > 1) {
355 $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() - 1);
356 $this->prev_link = $this->ctrl->getLinkTarget($this, 'performSearch');
357 }
358 for ($i = 1;$i <= $max_page;$i++) {
359 if ($i == $this->search_cache->getResultPageNumber()) {
360 continue;
361 }
362
363 $this->ctrl->setParameter($this, 'page_number', $i);
364 $link = '<a href="' . $this->ctrl->getLinkTarget($this, 'performSearch') . '" /a>' . $i . '</a> ';
365 }
366 if (count($result->getResults()) >= $result->getMaxHits()) {
367 $this->ctrl->setParameter($this, 'page_number', $this->search_cache->getResultPageNumber() + 1);
368 $this->next_link = $this->ctrl->getLinkTarget($this, 'performSearch');
369 }
370 $this->ctrl->clearParameters($this);
371 return false;
372 }
373
374 protected function buildSearchAreaPath(int $a_root_node): string
375 {
376 $path_arr = $this->tree->getPathFull($a_root_node, ROOT_FOLDER_ID);
377 $counter = 0;
378 $path = '';
379 foreach ($path_arr as $data) {
380 if ($counter++) {
381 $path .= " > ";
382 $path .= $data['title'];
383 } else {
384 $path .= $this->lng->txt('repository');
385 }
386 }
387 return $path;
388 }
389
390 public function autoComplete(): void
391 {
392 $query = '';
393 if ($this->http->wrapper()->post()->has('term')) {
394 $query = $this->http->wrapper()->post()->retrieve(
395 'term',
396 $this->refinery->kindlyTo()->string()
397 );
398 }
399 $list = ilSearchAutoComplete::getList($query);
400 echo $list;
401 exit;
402 }
403
404 protected function getSearchCache(): ilUserSearchCache
405 {
406 return $this->search_cache;
407 }
408
412 protected function loadCreationFilter(): array
413 {
414 if (!$this->settings->isDateFilterEnabled()) {
415 return [];
416 }
417
418 $options = [];
419 if (isset($this->search_filter_data["search_date"])) {
420 $options["date_start"] = $this->search_filter_data["search_date"][0];
421 $options["date_end"] = $this->search_filter_data["search_date"][1];
422 }
423
424 return $options;
425 }
426
427 protected function renderSearch(string $term, int $root_node = 0)
428 {
429 $this->tpl->addJavascript("assets/js/Search.js");
430
431 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "performSearch"));
432 $this->tpl->setVariable("TERM", ilLegacyFormElementsUtil::prepareFormOutput($term));
433 $this->tpl->setVariable("SEARCH_LABEL", $this->lng->txt("search"));
435 $btn->setCommand("performSearch");
436 $btn->setCaption("search");
437 $this->tpl->setVariable("SUBMIT_BTN", $btn->render());
438
439 if ($root_node) {
440 $this->renderFilter($root_node);
441 }
442 }
443
444 protected function renderFilter(int $root_node)
445 {
446 $filter_html = $this->search_filter->getHTML();
447 preg_match('/id="([^"]+)"/', $filter_html, $matches);
448 $filter_id = $matches[1];
449 $this->tpl->setVariable("SEARCH_FILTER", $filter_html);
450 // scope in filter must be manipulated by JS if search is triggered in meta bar
451 $this->tpl->addOnLoadCode("il.Search.syncFilterScope('" . $filter_id . "', '" . $root_node . "');");
452 }
453
454 protected function initFilter(int $mode)
455 {
456 $this->search_filter = new ilSearchFilterGUI($this, $mode);
457 $this->search_filter_data = $this->search_filter->getData();
458 }
459
460 protected function getStringArrayTransformation(): ILIAS\Refinery\Transformation
461 {
462 return $this->refinery->custom()->transformation(
463 static function (array $arr): array {
464 // keep keys(!), transform all values to string
465 return array_map(
466 static function ($v): string {
467 return \ilUtil::stripSlashes((string) $v);
468 },
469 $arr
470 );
471 }
472 );
473 }
474}
Builds data types.
Definition: Factory.php:36
Manages items in repository clipboard.
Handles Administration commands (cut, delete paste)
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Class ilCtrl provides processing control methods.
Manages favourites, currently the interface for other components, needs discussion.
language handling
static prepareFormOutput($a_str, bool $a_strip=false)
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.
This class represents a property in a property form.
This class represents an option in a radio group.
static getList(string $a_str)
GlobalHttpState $http
ilFavouritesManager $favourites
ilSearchFilterGUI $search_filter
renderSearch(string $term, int $root_node=0)
renderFilter(int $root_node)
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)
cancelDelete()
Cancel delete.
ilPropertyFormGUI $form
buildSearchAreaPath(int $a_root_node)
clear()
clear clipboard
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Class for storing search result.
static _getInstance(int $a_usr_id)
const ROOT_FOLDER_ID
Definition: constants.php:32
exit
Interface GlobalHttpState.
Interface for GUI classes (PDGUI, LuceneSearchGUI...) that have to handle administration commands (cu...
$path
Definition: ltiservices.php:30
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
Class ilObjForumAdministration.
global $DIC
Definition: shib_login.php:26
$counter