ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRepositorySearchGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\Refinery\Factory as RefineryFactory;
25
39{
40 private array $search_results = [];
41
42 protected array $add_options = [];
43 protected string $default_option = '';
44 protected bool $object_selection = false;
45
46 protected bool $searchable_check = true;
47 protected string $search_title = '';
48
49 private string $search_type = 'usr';
50 private string $string = '';
51 protected bool $user_limitations = true;
52
53 protected bool $stored = false;
54 protected array $callback = [];
55 protected array $role_callback = [];
56
59 protected ?ilPropertyFormGUI $form = null;
60
64 protected $user_filter = null;
65
67
68 protected ilTree $tree;
71 protected ilCtrl $ctrl;
73 protected ?ilObjUser $user = null;
75 protected ilTabsGUI $tabs;
76 protected ilLanguage $lng;
78 private RefineryFactory $refinery;
79
80 public function __construct()
81 {
82 global $DIC;
83
84
85
86 $this->ctrl = $DIC->ctrl();
87 $this->tpl = $DIC->ui()->mainTemplate();
88 $this->tree = $DIC->repositoryTree();
89 $this->ui_renderer = $DIC->ui()->renderer();
90 $this->ui_factory = $DIC->ui()->factory();
91 $this->lng = $DIC->language();
92 $this->rbacreview = $DIC->rbac()->review();
93 $this->refinery = $DIC->refinery();
94 $this->http = $DIC->http();
95 $this->user = $DIC->user();
96 $this->tabs = $DIC->tabs();
97
98 $this->lng->loadLanguageModule('search');
99 $this->lng->loadLanguageModule('crs');
100
101 $this->setTitle($this->lng->txt('add_members_header'));
102
103 $this->__setSearchType();
104 $this->__loadQueries();
105
106 $this->result_obj = new ilSearchResult();
107 $this->result_obj->setMaxHits(1000000);
108 $this->settings = new ilSearchSettings();
109 }
110
111 protected function initUserTypeFromQuery(): string
112 {
113 if ($this->http->wrapper()->query()->has('user_type')) {
114 return $this->http->wrapper()->query()->retrieve(
115 'user_type',
116 $this->refinery->kindlyTo()->string()
117 );
118 }
119 return '';
120 }
121
122 protected function initUserTypeFromPost(): string
123 {
124 if ($this->http->wrapper()->post()->has('user_type')) {
125 return $this->http->wrapper()->post()->retrieve(
126 'user_type',
127 $this->refinery->kindlyTo()->string()
128 );
129 }
130 return '';
131 }
132
141 public function addUserAccessFilterCallable(callable $user_filter): void
142 {
143 $this->user_filter = $user_filter;
144 }
145
146 public function setTitle(string $a_title): void
147 {
148 $this->search_title = $a_title;
149 }
150
151 public function getTitle(): string
152 {
153 return $this->search_title;
154 }
155
156 public function enableSearchableCheck(bool $a_status): void
157 {
158 $this->searchable_check = $a_status;
159 }
160
161 public function isSearchableCheckEnabled(): bool
162 {
164 }
165
166 public function setPrivacyMode(int $privacy_mode): void
167 {
168 $this->privacy_mode = $privacy_mode;
169 }
170
171 public function getPrivacyMode(): int
172 {
173 return $this->privacy_mode;
174 }
175
176 public function getSearchType(): string
177 {
178 return $this->search_type;
179 }
180
181 public function getRoleCallback(): array
182 {
184 }
185
186
195 public static function fillAutoCompleteToolbar(
196 object $parent_object,
197 ?ilToolbarGUI $toolbar = null,
198 array $a_options = [],
199 bool $a_sticky = false
200 ): ilToolbarGUI {
201 global $DIC;
202
203 $ilToolbar = $DIC->toolbar();
204 $lng = $DIC->language();
205 $ilCtrl = $DIC->ctrl();
206 $tree = $DIC->repositoryTree();
207 $user = $DIC->user();
208 $ui_factory = $DIC->ui()->factory();
209 $ui_renderer = $DIC->ui()->renderer();
210
211 if (!$toolbar instanceof ilToolbarGUI) {
212 $toolbar = $ilToolbar;
213 }
214
215 // Fill default options
216 if (!isset($a_options['auto_complete_name'])) {
217 $a_options['auto_complete_name'] = $lng->txt('obj_user');
218 }
219 if (!isset($a_options['auto_complete_size'])) {
220 $a_options['auto_complete_size'] = 15;
221 }
222 if (!isset($a_options['submit_name'])) {
223 $a_options['submit_name'] = $lng->txt('btn_add');
224 }
225 if (!isset($a_options['user_type_default'])) {
226 $a_options['user_type_default'] = null;
227 }
228
229 if (!isset($a_options['add_search'])) {
230 $a_options['add_search'] = false;
231 }
232 if (!isset($a_options['add_from_container'])) {
233 $a_options['add_from_container'] = null;
234 }
235
236 $ajax_url = $ilCtrl->getLinkTargetByClass(
237 array(get_class($parent_object),'ilRepositorySearchGUI'),
238 'doUserAutoComplete',
239 '',
240 true,
241 false
242 );
243
244 $ul = new ilTextInputGUI($a_options['auto_complete_name'], 'user_login');
245 $ul->setDataSource($ajax_url);
246 $ul->setSize($a_options['auto_complete_size']);
247 if (!$a_sticky) {
248 $toolbar->addInputItem($ul, true);
249 } else {
250 $toolbar->addStickyItem($ul, true);
251 }
252
253 if (isset($a_options['user_type']) && count((array) $a_options['user_type'])) {
254 $si = new ilSelectInputGUI("", "user_type");
255 $si->setOptions($a_options['user_type']);
256 $si->setValue($a_options['user_type_default']);
257 if (!$a_sticky) {
258 $toolbar->addInputItem($si);
259 } else {
260 $toolbar->addStickyItem($si);
261 }
262 }
263
265
266 $add_button = ilSubmitButton::getInstance();
267 $add_button->setCaption($a_options['submit_name'], false);
268 $add_button->setCommand('addUserFromAutoComplete');
269
270 if (!$a_sticky || $clip->hasContent()) {
271 $toolbar->addButtonInstance($add_button);
272 } else {
273 $toolbar->addStickyItem($add_button);
274 }
275
276 if ($clip->hasContent()) {
277 $clip_button = ilSubmitButton::getInstance();
278 $clip_button->addCSSClass('btn btndefault');
279 $lng->loadLanguageModule('user');
280 $clip_button->setCaption($lng->txt('clipboard_add_from_btn'), false);
281 $clip_button->setCommand('showClipboard');
282
283 $toolbar->addButtonInstance($clip_button);
284 }
285
286 if ($a_options['add_search'] ||
287 is_numeric($a_options['add_from_container'])) {
288 $lng->loadLanguageModule("search");
289
290 $toolbar->addSeparator();
291
292 if ($a_options['add_search']) {
293 $button = $ui_factory->button()->standard(
294 $lng->txt('search_users'),
295 $ilCtrl->getLinkTargetByClass(strtolower(self::class), '')
296 );
297 $toolbar->addComponent($button);
298 }
299
300 if (is_numeric($a_options['add_from_container'])) {
301 $parent_ref_id = (int) $a_options['add_from_container'];
302 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "grp");
303 $parent_container_type = "grp";
304 if (!$parent_container_ref_id) {
305 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "crs");
306 $parent_container_type = "crs";
307 }
308 if ($parent_container_ref_id) {
309 if ($a_options['add_search']) {
310 $toolbar->addSpacer();
311 }
312
313 $ilCtrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", ilObject::_lookupObjId($parent_container_ref_id));
314
315 $button = $ui_factory->button()->standard(
316 $lng->txt('search_add_members_from_container_' . $parent_container_type),
317 $ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'), 'listUsers')
318 );
319 $toolbar->addComponent($button);
320 }
321 }
322 }
323
324 $toolbar->setFormAction(
325 $ilCtrl->getFormActionByClass(
326 array(
327 get_class($parent_object),
328 'ilRepositorySearchGUI')
329 )
330 );
331 return $toolbar;
332 }
333
334 protected function doUserAutoComplete(): ?string
335 {
336 // hide anonymout request
337 if ($this->user->getId() == ANONYMOUS_USER_ID) {
338 echo json_encode(new stdClass(), JSON_THROW_ON_ERROR);
339 exit;
340 }
341 if (!$this->http->wrapper()->query()->has('autoCompleteField')) {
342 $a_fields = [
343 'login',
344 'firstname',
345 'lastname',
346 'email'
347 ];
348 $result_field = 'login';
349 } else {
350 $auto_complete_field = $this->http->wrapper()->query()->retrieve(
351 'autoCompleteField',
352 $this->refinery->kindlyTo()->string()
353 );
354 $a_fields = [$auto_complete_field];
355 $result_field = $auto_complete_field;
356 }
357 $auto = new ilUserAutoComplete();
358 $auto->setPrivacyMode($this->getPrivacyMode());
359
360 if ($this->http->wrapper()->query()->has('fetchall')) {
361 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
362 }
363
364 $auto->setMoreLinkAvailable(true);
365 $auto->setSearchFields($a_fields);
366 $auto->setResultField($result_field);
367 $auto->enableFieldSearchableCheck(true);
368 $auto->setUserLimitations($this->getUserLimitations());
369 if (is_callable($this->user_filter)) { // #0024249
370 $auto->addUserAccessFilterCallable(Closure::fromCallable($this->user_filter));
371 }
372
373 $query = '';
374 if ($this->http->wrapper()->post()->has('term')) {
375 $query = $this->http->wrapper()->post()->retrieve(
376 'term',
377 $this->refinery->kindlyTo()->string()
378 );
379 }
380 if ($query === "") {
381 if ($this->http->wrapper()->query()->has('term')) {
382 $query = $this->http->wrapper()->query()->retrieve(
383 'term',
384 $this->refinery->kindlyTo()->string()
385 );
386 }
387 }
388 echo $auto->getList($query);
389 exit;
390 }
391
392
393 public function setString(string $a_str): void
394 {
395 $search = ilSession::get('search');
396 $search['string'] = $this->string = $a_str;
397 ilSession::set('search', $search);
398 }
399 public function getString(): string
400 {
401 return $this->string;
402 }
403
404 public function executeCommand(): bool
405 {
406 $next_class = $this->ctrl->getNextClass($this);
407 $cmd = $this->ctrl->getCmd();
408 switch ($next_class) {
409 default:
410 if (!$cmd) {
411 $cmd = "showSearch";
412 }
413 $this->$cmd();
414 break;
415 }
416 return true;
417 }
418
419 public function __clearSession(): void
420 {
421 ilSession::clear('rep_search');
422 ilSession::clear('append_results');
423 ilSession::clear('rep_query');
424 ilSession::clear('rep_search_type');
425 }
426
427 public function cancel(): void
428 {
429 $this->ctrl->returnToParent($this);
430 }
431
432 public function start(): bool
433 {
434 // delete all session info
435 $this->__clearSession();
436 $this->showSearch();
437
438 return true;
439 }
440
441
442 public function addRole(): void
443 {
444 $class = $this->role_callback['class'];
445 $method = $this->role_callback['method'];
446
447 // call callback if that function does give a return value => show error message
448 // listener redirects if everything is ok.
449 $obj_ids = [];
450 if ($this->http->wrapper()->post()->has('obj')) {
451 $obj_ids = $this->http->wrapper()->post()->retrieve(
452 'obj',
453 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
454 );
455 }
456 $role_ids = array();
457 foreach ($obj_ids as $id) {
458 $obj_type = ilObject::_lookupType($id);
459 if ($obj_type == "crs" || $obj_type == "grp") {
461 $ref_id = end($refs);
463 $role_ids[] = $mem_role;
464 } else {
465 $role_ids[] = $id;
466 }
467 }
468 $class->$method($role_ids);
469
470 $this->showSearchResults();
471 }
472
473 public function addUser(): void
474 {
475 $class = $this->callback['class'];
476 $method = $this->callback['method'];
477
478 $users = [];
479 if ($this->http->wrapper()->post()->has('user')) {
480 $users = $this->http->wrapper()->post()->retrieve(
481 'user',
482 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
483 );
484 }
485
486 // call callback if that function does give a return value => show error message
487 // listener redirects if everything is ok.
488 $class->$method($users);
489
490 $this->showSearchResults();
491 }
492
493
494 protected function addUserFromAutoComplete(): void
495 {
496 $class = $this->callback['class'];
497 $method = $this->callback['method'];
498
499 $post_users = '';
500 if ($this->http->wrapper()->post()->has('user_login')) {
501 $post_users = $this->http->wrapper()->post()->retrieve(
502 'user_login',
503 $this->refinery->kindlyTo()->string()
504 );
505 }
506
507 $users = explode(',', $post_users);
508 $user_ids = array();
509 foreach ($users as $user) {
511 if ($user_id) {
512 $user_ids[] = $user_id;
513 }
514 }
515
516 $user_type = $this->initUserTypeFromPost();
517 if (!$class->$method($user_ids, $user_type)) {
518 $this->ctrl->returnToParent($this);
519 }
520 }
521
522 protected function showClipboard(): void
523 {
524 $user_type = $this->initUserTypeFromQuery();
525 if ($user_type === '') {
526 $user_type = $this->initUserTypeFromPost();
527 }
528 $this->ctrl->setParameter($this, 'user_type', $user_type);
529 $this->tabs->clearTargets();
530 $this->tabs->setBackTarget(
531 $this->lng->txt('back'),
532 $this->ctrl->getParentReturn($this)
533 );
534
535 $clip = new ilUserClipboardTableGUI($this, 'showClipboard', $this->user->getId());
536 $clip->setFormAction($this->ctrl->getFormAction($this));
537 $clip->init();
538 $clip->parse();
539
540 $this->tpl->setContent($clip->getHTML());
541 }
542
543
544 protected function addFromClipboard(): void
545 {
546 $user_type = $this->initUserTypeFromPost();
547 if ($user_type === '') {
548 $user_type = $this->initUserTypeFromQuery();
549 }
550 $this->ctrl->setParameter($this, 'user_type', $user_type);
551
552 $users = [];
553 if ($this->http->wrapper()->post()->has('uids')) {
554 $users = $this->http->wrapper()->post()->retrieve(
555 'uids',
556 $this->refinery->kindlyTo()->dictOf(
557 $this->refinery->kindlyTo()->int()
558 )
559 );
560 }
561 if (!count($users)) {
562 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
563 $this->ctrl->redirect($this, 'showClipboard');
564 }
565 $class = $this->callback['class'];
566 $method = $this->callback['method'];
567 if (!$class->$method($users, $user_type)) {
568 $this->ctrl->returnToParent($this);
569 }
570 }
571
572
573 protected function removeFromClipboard(): void
574 {
575 $users = [];
576 if ($this->http->wrapper()->post()->has('uids')) {
577 $users = $this->http->wrapper()->post()->retrieve(
578 'uids',
579 $this->refinery->kindlyTo()->listOf(
580 $this->refinery->kindlyTo()->int()
581 )
582 );
583 }
584
585 $this->ctrl->setParameter($this, 'user_type', $this->initUserTypeFromQuery());
586 if (!count($users)) {
587 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
588 $this->ctrl->redirect($this, 'showClipboard');
589 }
590
591 $clip = ilUserClipboard::getInstance($this->user->getId());
592 $clip->delete($users);
593 $clip->save();
594
595 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
596 $this->ctrl->redirect($this, 'showClipboard');
597 }
598
599
600 protected function emptyClipboard(): void
601 {
602 $clip = ilUserClipboard::getInstance($this->user->getId());
603 $clip->clear();
604 $clip->save();
605
606 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
607 $this->ctrl->returnToParent($this);
608 }
609
610
611 protected function handleMultiCommand(): void
612 {
613 $class = $this->callback['class'];
614 $method = $this->callback['method'];
615
616 $post_user = (array) ($this->http->request()->getParsedBody()['user'] ?? []);
617 $post_selected_command = '';
618 if (
619 $this->http->wrapper()->post()->has('table_top_cmd') &&
620 $this->http->wrapper()->post()->has('selectedCommand_2')
621 ) {
622 $post_selected_command = $this->http->wrapper()->post()->retrieve(
623 'selectedCommand_2',
624 $this->refinery->kindlyTo()->string()
625 );
626 } elseif ($this->http->wrapper()->post()->has('selectedCommand')) {
627 $post_selected_command = $this->http->wrapper()->post()->retrieve(
628 'selectedCommand',
629 $this->refinery->kindlyTo()->string()
630 );
631 }
632 // Redirects if everything is ok
633 if (!$class->$method($post_user, $post_selected_command)) {
634 $this->showSearchResults();
635 }
636 }
637
641 public function setCallback(
642 object $class,
643 string $method,
644 array $a_add_options = [],
645 string $default_option = ''
646 ): void {
647 $this->callback = array('class' => $class,'method' => $method);
648 $this->add_options = $a_add_options;
649 $this->default_option = $default_option;
650 }
651
655 public function setRoleCallback(
656 object $class,
657 string $method,
658 array $a_add_options = [],
659 string $default_option = ''
660 ): void {
661 $this->role_callback = array('class' => $class,'method' => $method);
662 $this->add_options = $a_add_options;
663 $this->default_option = $default_option;
664 }
665
666
667 public function setPermissionQueryCallback(object $class, string $method): void
668 {
669 }
670
671 public function showSearch(): void
672 {
673 // only autocomplete input field, no search form if user privay should be respected
674 // see bug 25481
675 if ($this->getPrivacyMode() == ilUserAutoComplete::PRIVACY_MODE_RESPECT_USER_SETTING) {
676 return;
677 }
678 $this->initFormSearch();
679 $this->tpl->setContent($this->form->getHTML());
680 }
681
682 public function showSearchSelected(): void
683 {
684 $selected = [];
685 if ($this->http->wrapper()->query()->has('selected_id')) {
686 $selected = $this->http->wrapper()->query()->retrieve(
687 'selected_id',
688 $this->refinery->kindlyTo()->int()
689 );
690 }
691 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'components/ILIAS/Search');
692 $this->addNewSearchButton();
693 $this->showSearchUserTable([$selected], 'showSearchResults');
694 }
695
696 public function initFormSearch(?ilObjUser $user = null): void
697 {
698 $this->form = new ilPropertyFormGUI();
699 $this->form->setFormAction($this->ctrl->getFormAction($this, 'showSearch'));
700 $this->form->setTitle($this->getTitle());
701 $this->form->addCommandButton('performSearch', $this->lng->txt('search'));
702 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
703
704
705 $kind = new ilRadioGroupInputGUI($this->lng->txt('search_type'), 'search_for');
706 $kind->setValue($this->search_type);
707 $this->form->addItem($kind);
708
709 // Users
710 $users = new ilRadioOption($this->lng->txt('search_for_users'), 'usr');
711
712 // UDF
713 foreach (ilUserSearchOptions::_getSearchableFieldsInfo(!$this->isSearchableCheckEnabled()) as $info) {
717
718 $sel = new ilSelectInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
719 $sel->setOptions($info['values']);
720 $users->addSubItem($sel);
721 break;
722
726
727 if (isset($info['autoComplete']) and $info['autoComplete']) {
728 $this->ctrl->setParameterByClass(get_class($this), 'autoCompleteField', $info['db']);
729 $ul = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
730 $ul->setDataSourceSubmitOnSelection(true);
731 $ul->setDataSourceSubmitUrl(
732 $this->ctrl->getLinkTarget(
733 $this,
734 'showSearchSelected',
735 '',
736 false,
737 false
738 )
739 );
740 $ul->setDataSource($this->ctrl->getLinkTarget(
741 $this,
742 "doUserAutoComplete",
743 "",
744 true
745 ));
746 $ul->setSize(30);
747 $ul->setMaxLength(120);
748
749 if ($user instanceof ilObjUser) {
750 switch ($info['db']) {
751 case 'firstname':
752 $ul->setValue($user->getFirstname());
753 break;
754 case 'lastname':
755 $ul->setValue($user->getLastname());
756 break;
757 case 'login':
758 $ul->setValue($user->getLogin());
759 break;
760 }
761 }
762
763
764
765 $users->addSubItem($ul);
766 } else {
767 $txt = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
768 $txt->setSize(30);
769 $txt->setMaxLength(120);
770 $users->addSubItem($txt);
771 }
772 break;
773 }
774 }
775 $kind->addOption($users);
776
777
778
779 // Role
780 $roles = new ilRadioOption($this->lng->txt('search_for_role_members'), 'role');
781 $role = new ilTextInputGUI($this->lng->txt('search_role_title'), 'rep_query[role][title]');
782 $role->setSize(30);
783 $role->setMaxLength(120);
784 $roles->addSubItem($role);
785 $kind->addOption($roles);
786
787 // Course
788 $groups = new ilRadioOption($this->lng->txt('search_for_crs_members'), 'crs');
789 $group = new ilTextInputGUI($this->lng->txt('search_crs_title'), 'rep_query[crs][title]');
790 $group->setSize(30);
791 $group->setMaxLength(120);
792 $groups->addSubItem($group);
793 $kind->addOption($groups);
794
795 // Group
796 $groups = new ilRadioOption($this->lng->txt('search_for_grp_members'), 'grp');
797 $group = new ilTextInputGUI($this->lng->txt('search_grp_title'), 'rep_query[grp][title]');
798 $group->setSize(30);
799 $group->setMaxLength(120);
800 $groups->addSubItem($group);
801 $kind->addOption($groups);
802
803 // Orgus
804 if (ilUserSearchOptions::_isEnabled("org_units")) {
805 $orgus = new ilRadioOption($this->lng->txt('search_for_orgu_members'), 'orgu');
807 $this->lng->txt('select_orgu'),
808 'rep_query_orgu',
809 true,
810 $this->form
811 );
812 $orgu->getExplorerGUI()->setSelectableTypes(["orgu"]);
813 $orgu->getExplorerGUI()->setTypeWhiteList(["root", "orgu"]);
814 $orgu->getExplorerGUI()->setRootId(ilObjOrgUnit::getRootOrgRefId());
815 $orgu->getExplorerGUI()->setAjax(false);
816 $orgus->addSubItem($orgu);
817 $kind->addOption($orgus);
818 }
819 }
820
821
822 public function show(): void
823 {
824 $this->showSearchResults();
825 }
826
827 public function appendSearch(): void
828 {
829 ilSession::set('search_append', true);
830 $this->performSearch();
831 }
832
833 public function performSearch(): bool
834 {
835 // only autocomplete input field, no search form if user privay should be respected
836 // see bug 25481
837 if ($this->getPrivacyMode() == ilUserAutoComplete::PRIVACY_MODE_RESPECT_USER_SETTING) {
838 return false;
839 }
840 $found_query = false;
841
842 $post_rep_query = (array) ($this->http->request()->getParsedBody()['rep_query'] ?? []);
843 $post_search_for = (string) ($this->http->request()->getParsedBody()['search_for'] ?? '');
844 if (isset($post_rep_query[$post_search_for])) {
845 foreach ((array) $post_rep_query[$post_search_for] as $field => $value) {
846 if (trim(ilUtil::stripSlashes($value))) {
847 $found_query = true;
848 break;
849 }
850 }
851 }
852 if ($this->http->wrapper()->post()->has('rep_query_orgu')) {
853 $found_query = true;
854 }
855 if (!$found_query) {
856 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_search_string'));
857 $this->start();
858 return false;
859 }
860
861 $post_cmd = (array) ($this->http->request()->getParsedBody()['cmd'] ?? []);
862 // unset search_append if called directly
863 if (isset($post_cmd['performSearch'])) {
864 ilSession::clear('search_append');
865 }
866
867 switch ($this->search_type) {
868 case 'usr':
869 $this->__performUserSearch();
870 break;
871
872 case 'grp':
873 $this->__performGroupSearch();
874 break;
875
876 case 'crs':
877 $this->__performCourseSearch();
878 break;
879
880 case 'role':
881 $this->__performRoleSearch();
882 break;
883 case 'orgu':
884 $post_rep_query_orgu = (array) ($this->http->request()->getParsedBody()['rep_query_orgu'] ?? []);
885 $selected_objects = array_map(
886 function ($ref_id) {
887 return ilObject::_lookupObjId((int) $ref_id);
888 },
889 $post_rep_query_orgu
890 );
891 return $this->listUsers($selected_objects);
892 default:
893 echo 'not defined';
894 }
895
896 $this->result_obj->setRequiredPermission('read');
897 $this->result_obj->addObserver($this, 'searchResultFilterListener');
898 $this->result_obj->filter(ROOT_FOLDER_ID, true);
899
900 // User access filter
901 if ($this->search_type == 'usr') {
902 $callable_name = '';
903 if (is_callable($this->user_filter, true, $callable_name)) {
904 $result_ids = call_user_func_array($this->user_filter, [$this->result_obj->getResultIds()]);
905 } else {
906 $result_ids = $this->result_obj->getResultIds();
907 }
908
909 $this->search_results = array_intersect(
910 $result_ids,
911 ilUserFilter::getInstance()->filter($result_ids)
912 );
913 } else {
914 $this->search_results = array();
915 foreach ($this->result_obj->getResults() as $res) {
916 $this->search_results[] = $res['obj_id'];
917 }
918 }
919
920 if (!count($this->search_results)) {
921 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('search_no_match'));
922 $this->showSearch();
923 return true;
924 }
925 $this->__updateResults();
926 if ($this->result_obj->isLimitReached()) {
927 $message = sprintf($this->lng->txt('search_limit_reached'), $this->settings->getMaxHits());
928 $this->tpl->setOnScreenMessage('info', $message);
929 return true;
930 }
931 // show results
932 $this->show();
933 return true;
934 }
935
936 public function __performUserSearch(): bool
937 {
938 foreach (ilUserSearchOptions::_getSearchableFieldsInfo(!$this->isSearchableCheckEnabled()) as $info) {
939 $name = $info['db'];
940
941 $rep_query = ilSession::get('rep_query');
942 $query_string = $rep_query['usr'][$name] ?? '';
943 // continue if no query string is given
944 if (!$query_string) {
945 continue;
946 }
947
948 if (!is_object($query_parser = $this->__parseQueryString($query_string, true, ($info['type'] == ilUserSearchOptions::FIELD_TYPE_SELECT)))) {
949 $this->tpl->setOnScreenMessage('info', $query_parser);
950 return false;
951 }
952 switch ($info['type']) {
954 $query_parser = $this->__parseQueryString($query_string);
955
956 // no break
959 $udf_search->setFields(array($name));
960 $result_obj = $udf_search->performSearch();
961
962 // Store entries
963 $this->__storeEntries($result_obj);
964 break;
965
967
968 if ($info['db'] == 'org_units') {
970 $result_obj = $user_search->performSearch();
971 $this->__storeEntries($result_obj);
972 break;
973 }
974 $query_parser = $this->__parseQueryString($query_string, true, true);
975
976 // no break
978 $user_search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
979 $user_search->setFields(array($name));
980 $result_obj = $user_search->performSearch();
981
982 // store entries
983 $this->__storeEntries($result_obj);
984 break;
985
987 $multi_search = ilObjectSearchFactory::getUserMultiFieldSearchInstance($query_parser);
988 $multi_search->setFields(array($name));
989 $result_obj = $multi_search->performSearch();
990 $this->__storeEntries($result_obj);
991 break;
992 }
993 }
994 return true;
995 }
996
997 public function __performGroupSearch(): bool
998 {
999 $rep_query = ilSession::get('rep_query');
1000 $query_string = $rep_query['grp']['title'] ?? '';
1001 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
1002 $this->tpl->setOnScreenMessage('info', $query_parser, true);
1003 return false;
1004 }
1005
1006 $object_search = new ilLikeObjectSearch($query_parser);
1007 $object_search->setFilter(array('grp'));
1008 $this->__storeEntries($object_search->performSearch());
1009
1010 return true;
1011 }
1012
1013 protected function __performCourseSearch(): bool
1014 {
1015 $rep_query = ilSession::get('rep_query');
1016 $query_string = $rep_query['crs']['title'] ?? '';
1017 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
1018 $this->tpl->setOnScreenMessage('info', $query_parser, true);
1019 return false;
1020 }
1021
1022 $object_search = new ilLikeObjectSearch($query_parser);
1023 $object_search->setFilter(array('crs'));
1024 $this->__storeEntries($object_search->performSearch());
1025
1026 return true;
1027 }
1028
1029 public function __performRoleSearch(): bool
1030 {
1031 $rep_query = ilSession::get('rep_query');
1032 $query_string = $rep_query['role']['title'] ?? '';
1033 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
1034 $this->tpl->setOnScreenMessage('info', $query_parser, true);
1035 return false;
1036 }
1037
1038 // Perform like search
1039 $object_search = new ilLikeObjectSearch($query_parser);
1040 $object_search->setFilter(array('role'));
1041 $this->__storeEntries($object_search->performSearch());
1042
1043 return true;
1044 }
1045
1049 public function __parseQueryString(string $a_string, bool $a_combination_or = true, bool $a_ignore_length = false)
1050 {
1051 $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
1052 $query_parser->setCombination($a_combination_or ? ilQueryParser::QP_COMBINATION_OR : ilQueryParser::QP_COMBINATION_AND);
1053 $query_parser->setMinWordLength(1);
1054
1055 // #17502
1056 if (!$a_ignore_length) {
1057 $query_parser->setGlobalMinLength(3); // #14768
1058 }
1059
1060 $query_parser->parse();
1061
1062 if (!$query_parser->validate()) {
1063 return $query_parser->getMessage();
1064 }
1065 return $query_parser;
1066 }
1067
1068 // Private
1069 public function __loadQueries(): void
1070 {
1071 if ($this->http->wrapper()->post()->has('rep_query')) {
1073 'rep_query',
1074 $this->http->request()->getParsedBody()['rep_query']
1075 );
1076 }
1077 }
1078
1079
1080 public function __setSearchType(): bool
1081 {
1082 // Update search type. Default to user search
1083 if ($this->http->wrapper()->post()->has('search_for')) {
1085 'rep_search_type',
1086 $this->http->request()->getParsedBody()['search_for']
1087 );
1088 } elseif (!ilSession::get('rep_search_type')) {
1089 ilSession::set('rep_search_type', 'usr');
1090 }
1091 $this->search_type = (string) ilSession::get('rep_search_type');
1092 return true;
1093 }
1094
1095
1096 public function __updateResults(): bool
1097 {
1098 if (!ilSession::get('search_append')) {
1099 ilSession::set('rep_search', []);
1100 }
1101 $rep_search = ilSession::get('rep_search') ?? [];
1102 foreach ($this->search_results as $result) {
1103 $rep_search[$this->search_type][] = $result;
1104 }
1105 if (!$rep_search[$this->search_type]) {
1106 $rep_search[$this->search_type] = [];
1107 } else {
1108 $rep_search[$this->search_type] = array_unique($rep_search[$this->search_type]);
1109 }
1110 ilSession::set('rep_search', $rep_search);
1111 return true;
1112 }
1113
1117 public function __appendToStoredResults(array $a_usr_ids): array
1118 {
1119 if (!ilSession::get('search_append')) {
1120 $rep_search = ilSession::get('rep_search') ?? [];
1121 $rep_search['usr'] = $a_usr_ids;
1122 ilSession::set('rep_search', $rep_search);
1123 return $a_usr_ids;
1124 }
1125 $rep_search = ilSession::get('rep_search') ?? [];
1126 foreach ($a_usr_ids as $usr_id) {
1127 $rep_search['usr'][] = $usr_id;
1128 }
1129 $rep_search['usr'] = array_unique($rep_search['usr'] ?? []);
1130 ilSession::set('rep_search', $rep_search);
1131 return $rep_search['usr'];
1132 }
1133
1134 public function __storeEntries(ilSearchResult $new_res): bool
1135 {
1136 if ($this->stored == false) {
1137 $this->result_obj->mergeEntries($new_res);
1138 $this->stored = true;
1139 return true;
1140 } else {
1141 $this->result_obj->intersectEntries($new_res);
1142 return true;
1143 }
1144 }
1145
1146 protected function addNewSearchButton(): void
1147 {
1148 $toolbar = new ilToolbarGUI();
1149 $toolbar->addButton(
1150 $this->lng->txt('search_new'),
1151 $this->ctrl->getLinkTarget($this, 'showSearch')
1152 );
1153 $this->tpl->setVariable('ACTION_BUTTONS', $toolbar->getHTML());
1154 }
1155
1156 public function showSearchResults(): void
1157 {
1158 $counter = 0;
1159 $f_result = array();
1160
1161 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'components/ILIAS/Search');
1162 $this->addNewSearchButton();
1163
1164 $rep_search = ilSession::get('rep_search');
1165
1166 switch ($this->search_type) {
1167 case "usr":
1168 $this->showSearchUserTable($rep_search['usr'] ?? [], 'showSearchResults');
1169 break;
1170
1171 case 'grp':
1172 $this->showSearchGroupTable($rep_search['grp'] ?? []);
1173 break;
1174
1175 case 'crs':
1176 $this->showSearchCourseTable($rep_search['crs'] ?? []);
1177 break;
1178
1179 case 'role':
1180 $this->showSearchRoleTable($rep_search['role'] ?? []);
1181 break;
1182 }
1183 }
1184
1185 protected function showSearchUserTable(array $a_usr_ids, string $a_parent_cmd): void
1186 {
1187 $base_class = '';
1188 if ($this->http->wrapper()->query()->has('baseClass')) {
1189 $base_class = $this->http->wrapper()->query()->retrieve(
1190 'baseClass',
1191 $this->refinery->kindlyTo()->string()
1192 );
1193 }
1194
1195 // String value of 'baseClass' is in lower case
1196 $is_in_admin = ($base_class === strtolower(ilAdministrationGUI::class));
1197
1198 if ($is_in_admin) {
1199 // remember link target to admin search gui (this)
1200 ilSession::set('usr_search_link', $this->ctrl->getLinkTarget($this, 'show'));
1201 }
1202
1203 $table = new ilRepositoryUserResultTableGUI($this, $a_parent_cmd, $is_in_admin);
1204 if (count($this->add_options)) {
1205 $table->addMultiItemSelectionButton(
1206 'selectedCommand',
1207 $this->add_options,
1208 'handleMultiCommand',
1209 $this->lng->txt('execute'),
1210 $this->default_option
1211 );
1212 } else {
1213 $table->addMultiCommand('addUser', $this->lng->txt('btn_add'));
1214 }
1215 $table->setUserLimitations($this->getUserLimitations());
1216 $table->parseUserIds($a_usr_ids);
1217
1218 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1219 }
1220
1221 protected function showSearchRoleTable(array $a_obj_ids): void
1222 {
1223 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1224 $table->parseObjectIds($a_obj_ids);
1225
1226 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1227 }
1228
1229 protected function showSearchGroupTable(array $a_obj_ids): void
1230 {
1231 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1232 $table->parseObjectIds($a_obj_ids);
1233
1234 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1235 }
1236
1237 protected function showSearchCourseTable(array $a_obj_ids): void
1238 {
1239 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1240 $table->parseObjectIds($a_obj_ids);
1241
1242 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1243 }
1244
1245 protected function listUsers(array $selected_entries = []): bool
1246 {
1247 // get parameter is used e.g. in exercises to provide
1248 // "add members of course" link
1249 if (
1250 $this->http->wrapper()->post()->has('obj') &&
1251 !count($selected_entries)
1252 ) {
1253 $selected_entries = $this->http->wrapper()->post()->retrieve(
1254 'obj',
1255 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
1256 );
1257 }
1258 if (
1259 $this->http->wrapper()->query()->has('list_obj') &&
1260 !count($selected_entries)
1261 ) {
1262 $selected_entries[] = $this->http->wrapper()->query()->retrieve(
1263 'list_obj',
1264 $this->refinery->kindlyTo()->int()
1265 );
1266 }
1267 if (!count($selected_entries)) {
1268 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1269 $this->showSearchResults();
1270 return false;
1271 }
1272 $rep_search = ilSession::get('rep_search') ?? [];
1273 $rep_search['objs'] = $selected_entries;
1274 ilSession::set('rep_search', $rep_search);
1275
1276 // Get all members
1277 $members = array();
1278 foreach ($selected_entries as $obj_id) {
1279 $type = ilObject::_lookupType($obj_id);
1280 switch ($type) {
1281 case 'crs':
1282 case 'grp':
1284 $part = [];
1285 if (is_callable($this->user_filter)) {
1286 $part = call_user_func_array(
1287 $this->user_filter,
1288 [
1289 ilParticipants::getInstanceByObjId($obj_id)->getParticipants()
1290 ]
1291 );
1292 } else {
1293 $part = ilParticipants::getInstanceByObjId($obj_id)->getParticipants();
1294 }
1295
1296 $members = array_merge((array) $members, $part);
1297 }
1298 break;
1299
1300 case 'role':
1301 $assigned = [];
1302 if (is_callable($this->user_filter)) {
1303 $assigned = call_user_func_array(
1304 $this->user_filter,
1305 [
1306 $this->rbacreview->assignedUsers($obj_id)
1307 ]
1308 );
1309 } else {
1310 $assigned = $this->rbacreview->assignedUsers($obj_id);
1311 }
1312
1313 $members = array_merge($members, ilUserFilter::getInstance()->filter($assigned));
1314 break;
1315 case 'orgu':
1316 if ($ref_ids = ilObject::_getAllReferences($obj_id)) {
1318 ->getUserIdsOfOrgUnit(array_shift($ref_ids));
1319 if (is_callable($this->user_filter)) {
1320 $assigned = call_user_func_array(
1321 $this->user_filter,
1322 [$assigned]
1323 );
1324 }
1325
1326 $members = array_merge(
1327 $members,
1328 $assigned
1329 );
1330 }
1331 break;
1332 }
1333 }
1334 $members = array_unique($members);
1335 $this->__appendToStoredResults($members);
1336
1337 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'components/ILIAS/Search');
1338
1339 $this->addNewSearchButton();
1340 $rep_search = ilSession::get('rep_search');
1341 $this->showSearchUserTable($rep_search['usr'] ?? [], 'storedUserList');
1342 return true;
1343 }
1344
1345 protected function storedUserList(): bool
1346 {
1347 $rep_search = ilSession::get('rep_search');
1348 $objects = $rep_search['objs'] ?? [];
1349 $this->listUsers($objects);
1350 return true;
1351 }
1352
1358 public function searchResultFilterListener(int $a_ref_id, array $a_data): bool
1359 {
1360 if ($a_data['type'] == 'usr') {
1361 if ($a_data['obj_id'] == ANONYMOUS_USER_ID) {
1362 return false;
1363 }
1364 }
1365 return true;
1366 }
1367
1368 public function allowObjectSelection(bool $a_value = false): void
1369 {
1370 $this->object_selection = $a_value;
1371 }
1372
1376 protected function selectObject(): bool
1377 {
1378 // get parameter is used e.g. in exercises to provide
1379 // "add members of course"
1380 $selected_entries = [];
1381 if ($this->http->wrapper()->post()->has('obj')) {
1382 $selected_entries = $this->http->wrapper()->post()->retrieve(
1383 'obj',
1384 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
1385 );
1386 }
1387 if (
1388 $this->http->wrapper()->query()->has('list_obj') &&
1389 !count($selected_entries)
1390 ) {
1391 $selected_entries[] = $this->http->wrapper()->query()->retrieve(
1392 'list_obj',
1393 $this->refinery->kindlyTo()->int()
1394 );
1395 }
1396
1397 if (!count($selected_entries)) {
1398 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
1399 $this->showSearchResults();
1400 return false;
1401 }
1402 $this->ctrl->setParameter($this->callback["class"], "obj", implode(";", $selected_entries));
1403 $this->ctrl->redirect($this->callback["class"], $this->callback["method"]);
1404 return true;
1405 }
1406
1410 public function setUserLimitations(bool $a_limitations): void
1411 {
1412 $this->user_limitations = $a_limitations;
1413 }
1414
1418 public function getUserLimitations(): bool
1419 {
1420 return $this->user_limitations;
1421 }
1422}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
show()
returns the content of IniFile
Class ilCtrl provides processing control methods.
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getRootOrgRefId()
User class.
static _lookupId(string|array $a_user_str)
static _getUserDefinedFieldSearchInstance(ilQueryParser $query_parser)
static getUserOrgUnitAssignmentInstance(ilQueryParser $query_parser)
static _getUserSearchInstance(ilQueryParser $query_parser)
static getUserMultiFieldSearchInstance(ilQueryParser $query_parser)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static getInstanceByObjId(int $a_obj_id)
Get instance by obj type.
static getDefaultMemberRole(int $a_ref_id)
static hasParticipantListAccess(int $a_obj_id, ?int $a_usr_id=null)
Check if (current) user has access to the participant list.
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.
class ilRbacReview Contains Review functions of core Rbac.
TableGUI class object (course,group and role) search results Used in member search.
selectObject()
Return selection of course/group/roles to calling script.
setPermissionQueryCallback(object $class, string $method)
showSearchUserTable(array $a_usr_ids, string $a_parent_cmd)
listUsers(array $selected_entries=[])
setRoleCallback(object $class, string $method, array $a_add_options=[], string $default_option='')
allowObjectSelection(bool $a_value=false)
searchResultFilterListener(int $a_ref_id, array $a_data)
Listener called from ilSearchResult Id is obj_id for role, usr Id is ref_id for crs grp.
initFormSearch(?ilObjUser $user=null)
addUserAccessFilterCallable(callable $user_filter)
Closure for filtering users e.g $rep_search_gui->addUserAccessFilterCallable(function($user_ids) use(...
static fillAutoCompleteToolbar(object $parent_object, ?ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
ilGlobalTemplateInterface $tpl
__storeEntries(ilSearchResult $new_res)
setCallback(object $class, string $method, array $a_add_options=[], string $default_option='')
getUserLimitations()
allow user limitations like inactive and access limitations
setUserLimitations(bool $a_limitations)
allow user limitations like inactive and access limitations
__parseQueryString(string $a_string, bool $a_combination_or=true, bool $a_ignore_length=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
static get(string $a_var)
static clear(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...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
checkForParentType(int $a_ref_id, string $a_type, bool $a_exclude_source_check=false)
Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentTyp...
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 getInstance(int $a_usr_id)
static _getSearchableFieldsInfo(bool $a_admin=false)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
const ANONYMOUS_USER_ID
Definition: constants.php:27
const ROOT_FOLDER_ID
Definition: constants.php:32
exit
$info
Definition: entry_point.php:21
$txt
Definition: error.php:31
Interface GlobalHttpState.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26
$counter
$message
Definition: xapiexit.php:31