ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilRepositorySearchGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
36include_once 'Services/Search/classes/class.ilSearchResult.php';
37include_once 'Services/Search/classes/class.ilSearchSettings.php';
38include_once './Services/User/classes/class.ilUserAccountSettings.php';
39include_once 'Services/Search/classes/class.ilQueryParser.php';
40include_once("./Services/User/classes/class.ilUserAutoComplete.php");
41
42
44{
45 private $search_results = array();
46
47 protected $add_options = array();
48 protected $default_option = '';
49 protected $object_selection = false;
50
51 protected $searchable_check = true;
52 protected $search_title = '';
53
54 public $search_type = 'usr';
55 protected $user_limitations = true;
56
60 protected $user_filter = null;
61
66
67
71 protected $tree;
75 protected $ui_renderer;
79 protected $ui_factory;
80
85 public function __construct()
86 {
87 global $DIC;
88
89 $ilCtrl = $DIC['ilCtrl'];
90 $tpl = $DIC['tpl'];
91 $lng = $DIC['lng'];
92 $tree = $DIC['tree'];
93 $ui_renderer = $DIC["ui.renderer"];
94 $ui_factory = $DIC["ui.factory"];
95
96 $this->ctrl = $ilCtrl;
97 $this->tpl = $tpl;
98 $this->tree = $tree;
99 $this->ui_renderer = $ui_renderer;
100 $this->ui_factory = $ui_factory;
101
102 $this->lng = $lng;
103 $this->lng->loadLanguageModule('search');
104 $this->lng->loadLanguageModule('crs');
105
106 $this->setTitle($this->lng->txt('add_members_header'));
107
108 $this->__setSearchType();
109 $this->__loadQueries();
110
111 $this->result_obj = new ilSearchResult();
112 $this->result_obj->setMaxHits(1000000);
113 $this->settings = new ilSearchSettings();
114 }
115
126 {
127 $this->user_filter = $user_filter;
128 }
129
134 public function setTitle($a_title)
135 {
136 $this->search_title = $a_title;
137 }
138
143 public function getTitle()
144 {
145 return $this->search_title;
146 }
147
152 public function enableSearchableCheck($a_status)
153 {
154 $this->searchable_check = $a_status;
155 }
156
161 public function isSearchableCheckEnabled()
162 {
164 }
165
170 {
171 $this->privacy_mode = $privacy_mode;
172 }
173
177 public function getPrivacyMode()
178 {
179 return $this->privacy_mode;
180 }
181
182
196 public static function fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar = null, $a_options = array(), $a_sticky = false)
197 {
198 global $DIC;
199
200 $ilToolbar = $DIC['ilToolbar'];
201 $lng = $DIC['lng'];
202 $ilCtrl = $DIC['ilCtrl'];
203 $tree = $DIC['tree'];
204
205 if (!$toolbar instanceof ilToolbarGUI) {
206 $toolbar = $ilToolbar;
207 }
208
209 // Fill default options
210 if (!isset($a_options['auto_complete_name'])) {
211 $a_options['auto_complete_name'] = $lng->txt('obj_user');
212 }
213 if (!isset($a_options['auto_complete_size'])) {
214 $a_options['auto_complete_size'] = 15;
215 }
216 if (!isset($a_options['submit_name'])) {
217 $a_options['submit_name'] = $lng->txt('btn_add');
218 }
219 if (!isset($a_options['user_type_default'])) {
220 $a_options['user_type_default'] = null;
221 }
222
223 $ajax_url = $ilCtrl->getLinkTargetByClass(
224 array(get_class($parent_object),'ilRepositorySearchGUI'),
225 'doUserAutoComplete',
226 '',
227 true,
228 false
229 );
230
231 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
232 $ul = new ilTextInputGUI($a_options['auto_complete_name'], 'user_login');
233 $ul->setDataSource($ajax_url);
234 $ul->setSize($a_options['auto_complete_size']);
235 if (!$a_sticky) {
236 $toolbar->addInputItem($ul, true);
237 } else {
238 $toolbar->addStickyItem($ul, true);
239 }
240
241 if (count((array) $a_options['user_type'])) {
242 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
243 $si = new ilSelectInputGUI("", "user_type");
244 $si->setOptions($a_options['user_type']);
245 $si->setValue($a_options['user_type_default']);
246 if (!$a_sticky) {
247 $toolbar->addInputItem($si);
248 } else {
249 $toolbar->addStickyItem($si);
250 }
251 }
252
253 include_once './Services/User/classes/class.ilUserClipboard.php';
254 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
255 if ($clip->hasContent()) {
256 include_once './Services/UIComponent/SplitButton/classes/class.ilSplitButtonGUI.php';
257 $action_button = ilSplitButtonGUI::getInstance();
258
259 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
260 $add_button = ilSubmitButton::getInstance();
261 $add_button->setCaption($a_options['submit_name'], false);
262 $add_button->setCommand('addUserFromAutoComplete');
263
264 $action_button->setDefaultButton($add_button);
265
266 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
267 $clip_button = ilSubmitButton::getInstance();
268 $clip_button->addCSSClass('btn btndefault');
269 $GLOBALS['DIC']->language()->loadLanguageModule('user');
270 $clip_button->setCaption($GLOBALS['DIC']->language()->txt('clipboard_add_from_btn'), false);
271 $clip_button->setCommand('showClipboard');
272
273 $action_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($clip_button));
274
275 $toolbar->addButtonInstance($action_button);
276 } else {
277 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
278 $button = ilSubmitButton::getInstance();
279 $button->setCaption($a_options['submit_name'], false);
280 $button->setCommand('addUserFromAutoComplete');
281 if (!$a_sticky) {
282 $toolbar->addButtonInstance($button);
283 } else {
284 $toolbar->addStickyItem($button);
285 }
286 }
287
288 if ((bool) $a_options['add_search'] ||
289 is_numeric($a_options['add_from_container'])) {
290 $lng->loadLanguageModule("search");
291
292 $toolbar->addSeparator();
293
294 if ((bool) $a_options['add_search']) {
295 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
296 $button = ilLinkButton::getInstance();
297 $button->setCaption("search_users");
298 $button->setUrl($ilCtrl->getLinkTargetByClass('ilRepositorySearchGUI', ''));
299 $toolbar->addButtonInstance($button);
300 }
301
302 if (is_numeric($a_options['add_from_container'])) {
303 $parent_ref_id = (int) $a_options['add_from_container'];
304 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "grp");
305 $parent_container_type = "grp";
306 if (!$parent_container_ref_id) {
307 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "crs");
308 $parent_container_type = "crs";
309 }
310 if ($parent_container_ref_id) {
311 if ((bool) $a_options['add_search']) {
312 $toolbar->addSpacer();
313 }
314
315 $ilCtrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", ilObject::_lookupObjId($parent_container_ref_id));
316
317 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
318 $button = ilLinkButton::getInstance();
319 $button->setCaption("search_add_members_from_container_" . $parent_container_type);
320 $button->setUrl($ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'), 'listUsers'));
321 $toolbar->addButtonInstance($button);
322 }
323 }
324 }
325
326 $toolbar->setFormAction(
327 $ilCtrl->getFormActionByClass(
328 array(
329 get_class($parent_object),
330 'ilRepositorySearchGUI')
331 )
332 );
333 return $toolbar;
334 }
335
340 protected function doUserAutoComplete()
341 {
342 // hide anonymout request
343 if ($GLOBALS['DIC']['ilUser']->getId() == ANONYMOUS_USER_ID) {
344 include_once './Services/JSON/classes/class.ilJsonUtil.php';
345 return ilJsonUtil::encode(new stdClass());
346 exit;
347 }
348
349
350 if (!isset($_GET['autoCompleteField'])) {
351 $a_fields = array('login','firstname','lastname','email');
352 $result_field = 'login';
353 } else {
354 $a_fields = array((string) $_GET['autoCompleteField']);
355 $result_field = (string) $_GET['autoCompleteField'];
356 }
357
358 include_once './Services/User/classes/class.ilUserAutoComplete.php';
359 $auto = new ilUserAutoComplete();
360 $auto->setPrivacyMode($this->getPrivacyMode());
361
362 if (($_REQUEST['fetchall'])) {
363 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
364 }
365
366 $auto->setMoreLinkAvailable(true);
367 $auto->setSearchFields($a_fields);
368 $auto->setResultField($result_field);
369 $auto->enableFieldSearchableCheck(true);
370 $auto->setUserLimitations($this->getUserLimitations());
371 if (is_callable($this->user_filter)) { // #0024249
372 $auto->addUserAccessFilterCallable($this->user_filter);
373 }
374
375 echo $auto->getList($_REQUEST['term']);
376 exit();
377 }
378
379
384 public function setString($a_str)
385 {
386 $_SESSION['search']['string'] = $this->string = $a_str;
387 }
388 public function getString()
389 {
390 return $this->string;
391 }
392
397 public function executeCommand()
398 {
399 global $DIC;
400
401 $rbacsystem = $DIC['rbacsystem'];
402
403 $next_class = $this->ctrl->getNextClass($this);
404 $cmd = $this->ctrl->getCmd();
405
406 $this->ctrl->setReturn($this, '');
407
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()
420 {
421 unset($_SESSION['rep_search']);
422 unset($_SESSION['append_results']);
423 unset($_SESSION['rep_query']);
424 unset($_SESSION['rep_search_type']);
425 }
426
427 public function cancel()
428 {
429 $this->ctrl->returnToParent($this);
430 }
431
432 public function start()
433 {
434 // delete all session info
435 $this->__clearSession();
436 $this->showSearch();
437
438 return true;
439 }
440
441
442 public function addRole()
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 = (array) $_POST['obj'];
450 $role_ids = array();
451 foreach ($obj_ids as $id) {
452 $obj_type = ilObject::_lookupType($id);
453 if ($obj_type == "crs" || $obj_type == "grp") {
454 $refs = ilObject::_getAllReferences($id);
455 $ref_id = end($refs);
456 $mem_role = ilParticipants::getDefaultMemberRole($ref_id);
457 $role_ids[] = $mem_role;
458 } else {
459 $role_ids[] = $id;
460 }
461 }
462 $class->$method((array) $role_ids);
463
464 $this->showSearchResults();
465 }
466
467 public function addUser()
468 {
469 $class = $this->callback['class'];
470 $method = $this->callback['method'];
471
472 // call callback if that function does give a return value => show error message
473 // listener redirects if everything is ok.
474 $class->$method((array) $_POST['user']);
475
476 $this->showSearchResults();
477 }
478
482 protected function addUserFromAutoComplete()
483 {
484 $class = $this->callback['class'];
485 $method = $this->callback['method'];
486
487 $users = explode(',', $_POST['user_login']);
488 $user_ids = array();
489 foreach ($users as $user) {
490 $user_id = ilObjUser::_lookupId($user);
491 if ($user_id) {
492 $user_ids[] = $user_id;
493 }
494 }
495
496 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
497
498 if (!$class->$method($user_ids, $user_type)) {
499 $GLOBALS['DIC']['ilCtrl']->returnToParent($this);
500 }
501 }
502
503 protected function showClipboard()
504 {
505 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
506
507 ilLoggerFactory::getLogger('crs')->dump($_REQUEST);
508
509 $GLOBALS['DIC']['ilTabs']->clearTargets();
510 $GLOBALS['DIC']['ilTabs']->setBackTarget(
511 $GLOBALS['DIC']['lng']->txt('back'),
512 $GLOBALS['DIC']['ilCtrl']->getParentReturn($this)
513 );
514
515 include_once './Services/User/classes/class.ilUserClipboardTableGUI.php';
516 $clip = new ilUserClipboardTableGUI($this, 'showClipboard', $GLOBALS['DIC']['ilUser']->getId());
517 $clip->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this));
518 $clip->init();
519 $clip->parse();
520
521 $GLOBALS['DIC']['tpl']->setContent($clip->getHTML());
522 }
523
527 protected function addFromClipboard()
528 {
529 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
530 $users = (array) $_POST['uids'];
531 if (!count($users)) {
532 ilUtil::sendFailure($this->lng->txt('select_one'), true);
533 $GLOBALS['DIC']['ilCtrl']->redirect($this, 'showClipboard');
534 }
535 $class = $this->callback['class'];
536 $method = $this->callback['method'];
537 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
538
539 if (!$class->$method($users, $user_type)) {
540 $GLOBALS['DIC']['ilCtrl']->returnToParent($this);
541 }
542 }
543
547 protected function removeFromClipboard()
548 {
549 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
550 $users = (array) $_POST['uids'];
551 if (!count($users)) {
552 ilUtil::sendFailure($this->lng->txt('select_one'), true);
553 $GLOBALS['DIC']['ilCtrl']->redirect($this, 'showClipboard');
554 }
555
556 include_once './Services/User/classes/class.ilUserClipboard.php';
557 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
558 $clip->delete($users);
559 $clip->save();
560
561 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
562 $this->ctrl->redirect($this, 'showClipboard');
563 }
564
568 protected function emptyClipboard()
569 {
570 include_once './Services/User/classes/class.ilUserClipboard.php';
571 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
572 $clip->clear();
573 $clip->save();
574
575 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
576 $this->ctrl->returnToParent($this);
577 }
578
582 protected function handleMultiCommand()
583 {
584 $class = $this->callback['class'];
585 $method = $this->callback['method'];
586
587 // Redirects if everything is ok
588 if (!$class->$method((array) $_POST['user'], $_POST['selectedCommand'])) {
589 $this->showSearchResults();
590 }
591 }
592
593 public function setCallback(&$class, $method, $a_add_options = array(), $default_option = '')
594 {
595 $this->callback = array('class' => $class,'method' => $method);
596 $this->add_options = $a_add_options ? $a_add_options : array();
597 $this->default_option = (string) $default_option;
598 }
599
600 public function setRoleCallback(&$class, $method, $a_add_options = array(), $default_option = '')
601 {
602 $this->role_callback = array('class' => $class,'method' => $method);
603 $this->add_options = $a_add_options ? $a_add_options : array();
604 $this->default_option = $default_option;
605 }
606
610 public function setPermissionQueryCallback($class, $method)
611 {
612 }
613
614 public function showSearch()
615 {
616 // only autocomplete input field, no search form if user privay should be respected
617 // see bug 25481
619 return;
620 }
621 $this->initFormSearch();
622 $this->tpl->setContent($this->form->getHTML());
623 }
624
628 public function showSearchSelected()
629 {
630 $selected = (int) $_REQUEST['selected_id'];
631
632 #include_once './Services/Object/classes/class.ilObjectFactory.php';
633 #$factory = new ilObjectFactory();
634 #$user = $factory->getInstanceByObjId($selected);
635
636 #$this->initFormSearch($user);
637 #$this->tpl->setContent($this->form->getHTML());
638
639 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
640 $this->addNewSearchButton();
641 $this->showSearchUserTable(array($selected), 'showSearchResults');
642 }
643
644 public function initFormSearch(ilObjUser $user = null)
645 {
646 global $DIC;
647
648 $ilCtrl = $DIC['ilCtrl'];
649
650 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
651
652 $this->form = new ilPropertyFormGUI();
653 $this->form->setFormAction($this->ctrl->getFormAction($this, 'showSearch'));
654 $this->form->setTitle($this->getTitle());
655 $this->form->addCommandButton('performSearch', $this->lng->txt('search'));
656 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
657
658
659 $kind = new ilRadioGroupInputGUI($this->lng->txt('search_type'), 'search_for');
660 $kind->setValue($this->search_type);
661 $this->form->addItem($kind);
662
663 // Users
664 $users = new ilRadioOption($this->lng->txt('search_for_users'), 'usr');
665
666 // UDF
667 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
669 switch ($info['type']) {
672
673 $sel = new ilSelectInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
674 $sel->setOptions($info['values']);
675 $users->addSubItem($sel);
676 break;
677
678 case FIELD_TYPE_MULTI:
680 case FIELD_TYPE_TEXT:
681
682 if (isset($info['autoComplete']) and $info['autoComplete']) {
683 $ilCtrl->setParameterByClass(get_class($this), 'autoCompleteField', $info['db']);
684 $ul = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
685 $ul->setDataSourceSubmitOnSelection(true);
686 $ul->setDataSourceSubmitUrl(
687 $this->ctrl->getLinkTarget(
688 $this,
689 'showSearchSelected',
690 '',
691 false,
692 false
693 )
694 );
695 $ul->setDataSource($ilCtrl->getLinkTarget(
696 $this,
697 "doUserAutoComplete",
698 "",
699 true
700 ));
701 $ul->setSize(30);
702 $ul->setMaxLength(120);
703
704 if ($user instanceof ilObjUser) {
705 switch ($info['db']) {
706 case 'firstname':
707 $ul->setValue($user->getFirstname());
708 break;
709 case 'lastname':
710 $ul->setValue($user->getLastname());
711 break;
712 case 'login':
713 $ul->setValue($user->getLogin());
714 break;
715 }
716 }
717
718
719
720 $users->addSubItem($ul);
721 } else {
722 $txt = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
723 $txt->setSize(30);
724 $txt->setMaxLength(120);
725 $users->addSubItem($txt);
726 }
727 break;
728 }
729 }
730 $kind->addOption($users);
731
732
733
734 // Role
735 $roles = new ilRadioOption($this->lng->txt('search_for_role_members'), 'role');
736 $role = new ilTextInputGUI($this->lng->txt('search_role_title'), 'rep_query[role][title]');
737 $role->setSize(30);
738 $role->setMaxLength(120);
739 $roles->addSubItem($role);
740 $kind->addOption($roles);
741
742 // Course
743 $groups = new ilRadioOption($this->lng->txt('search_for_crs_members'), 'crs');
744 $group = new ilTextInputGUI($this->lng->txt('search_crs_title'), 'rep_query[crs][title]');
745 $group->setSize(30);
746 $group->setMaxLength(120);
747 $groups->addSubItem($group);
748 $kind->addOption($groups);
749
750 // Group
751 $groups = new ilRadioOption($this->lng->txt('search_for_grp_members'), 'grp');
752 $group = new ilTextInputGUI($this->lng->txt('search_grp_title'), 'rep_query[grp][title]');
753 $group->setSize(30);
754 $group->setMaxLength(120);
755 $groups->addSubItem($group);
756 $kind->addOption($groups);
757
758 // Orgus
759 if (ilUserSearchOptions::_isEnabled("org_units")) {
760 $orgus = new ilRadioOption($this->lng->txt('search_for_orgu_members'), 'orgu');
761 $orgu = new ilRepositorySelector2InputGUI($this->lng->txt('select_orgu'), 'rep_query_orgu', true, get_class($this));
762 $orgu->getExplorerGUI()->setSelectableTypes(["orgu"]);
763 $orgu->getExplorerGUI()->setTypeWhiteList(["root", "orgu"]);
764 $orgu->getExplorerGUI()->setRootId(ilObjOrgUnit::getRootOrgRefId());
765 $orgu->getExplorerGUI()->setAjax(false);
766 $orgus->addSubItem($orgu);
767 $kind->addOption($orgus);
768 }
769 }
770
771
772 public function show()
773 {
774 $this->showSearchResults();
775 }
776
777 public function appendSearch()
778 {
779 $_SESSION['search_append'] = true;
780 $this->performSearch();
781 }
782
787 public function performSearch()
788 {
789 // only autocomplete input field, no search form if user privay should be respected
790 // see bug 25481
792 return "";
793 }
794 $found_query = false;
795 foreach ((array) $_POST['rep_query'][$_POST['search_for']] as $field => $value) {
796 if (trim(ilUtil::stripSlashes($value))) {
797 $found_query = true;
798 break;
799 }
800 }
801 if (array_key_exists('rep_query_orgu', $_POST) && count($_POST['rep_query_orgu']) > 0) {
802 $found_query = true;
803 }
804 if (!$found_query) {
805 ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
806 $this->start();
807 return false;
808 }
809
810 // unset search_append if called directly
811 if ($_POST['cmd']['performSearch']) {
812 unset($_SESSION['search_append']);
813 }
814
815 switch ($this->search_type) {
816 case 'usr':
817 $this->__performUserSearch();
818 break;
819
820 case 'grp':
821 $this->__performGroupSearch();
822 break;
823
824 case 'crs':
825 $this->__performCourseSearch();
826 break;
827
828 case 'role':
829 $this->__performRoleSearch();
830 break;
831 case 'orgu':
832 $_POST['obj'] = array_map(
833 function ($ref_id) {
834 return (int) ilObject::_lookupObjId($ref_id);
835 },
836 $_POST['rep_query_orgu']
837 );
838 return $this->listUsers();
839 default:
840 echo 'not defined';
841 }
842
843 $this->result_obj->setRequiredPermission('read');
844 $this->result_obj->addObserver($this, 'searchResultFilterListener');
845 $this->result_obj->filter(ROOT_FOLDER_ID, QP_COMBINATION_OR);
846
847 // User access filter
848 if ($this->search_type == 'usr') {
849 $callable_name = '';
850 if (is_callable($this->user_filter, true, $callable_name)) {
851 $result_ids = call_user_func_array($this->user_filter, [$this->result_obj->getResultIds()]);
852 } else {
853 $result_ids = $this->result_obj->getResultIds();
854 }
855
856 include_once './Services/User/classes/class.ilUserFilter.php';
857 $this->search_results = array_intersect(
858 $result_ids,
859 ilUserFilter::getInstance()->filter($result_ids)
860 );
861 } else {
862 $this->search_results = array();
863 foreach ((array) $this->result_obj->getResults() as $res) {
864 $this->search_results[] = $res['obj_id'];
865 }
866 }
867
868 if (!count($this->search_results)) {
869 ilUtil::sendFailure($this->lng->txt('search_no_match'));
870 $this->showSearch();
871 return true;
872 }
873 $this->__updateResults();
874 if ($this->result_obj->isLimitReached()) {
875 $message = sprintf($this->lng->txt('search_limit_reached'), $this->settings->getMaxHits());
877 return true;
878 }
879 // show results
880 $this->show();
881 return true;
882 }
883
884 public function __performUserSearch()
885 {
886 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
887 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
888
890 $name = $info['db'];
891 $query_string = $_SESSION['rep_query']['usr'][$name];
892
893 // continue if no query string is given
894 if (!$query_string) {
895 continue;
896 }
897
898 if (!is_object($query_parser = $this->__parseQueryString($query_string, true, ($info['type'] == FIELD_TYPE_SELECT)))) {
899 ilUtil::sendInfo($query_parser);
900 return false;
901 }
902 switch ($info['type']) {
904 // Do a phrase query for select fields
905 $query_parser = $this->__parseQueryString($query_string);
906
907 // no break
910 $udf_search->setFields(array($name));
911 $result_obj = $udf_search->performSearch();
912
913 // Store entries
914 $this->__storeEntries($result_obj);
915 break;
916
918
919 if ($info['db'] == 'org_units') {
921 $result_obj = $user_search->performSearch();
922 $this->__storeEntries($result_obj);
923 break;
924 }
925
926 // Do a phrase query for select fields
927 $query_parser = $this->__parseQueryString($query_string, true, true);
928
929 // no break
930 case FIELD_TYPE_TEXT:
931 $user_search = &ilObjectSearchFactory::_getUserSearchInstance($query_parser);
932 $user_search->setFields(array($name));
933 $result_obj = $user_search->performSearch();
934
935 // store entries
936 $this->__storeEntries($result_obj);
937 break;
938
939 case FIELD_TYPE_MULTI:
940 $multi_search = ilObjectSearchFactory::getUserMultiFieldSearchInstance($query_parser);
941 $multi_search->setFields(array($name));
942 $result_obj = $multi_search->performSearch();
943 $this->__storeEntries($result_obj);
944 break;
945
946 }
947 }
948 }
949
954 public function __performGroupSearch()
955 {
956 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
957
958 $query_string = $_SESSION['rep_query']['grp']['title'];
959 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
960 ilUtil::sendInfo($query_parser, true);
961 return false;
962 }
963
964 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
965 $object_search = new ilLikeObjectSearch($query_parser);
966 $object_search->setFilter(array('grp'));
967 $this->__storeEntries($object_search->performSearch());
968
969 return true;
970 }
971
976 protected function __performCourseSearch()
977 {
978 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
979
980 $query_string = $_SESSION['rep_query']['crs']['title'];
981 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
982 ilUtil::sendInfo($query_parser, true);
983 return false;
984 }
985
986 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
987 $object_search = new ilLikeObjectSearch($query_parser);
988 $object_search->setFilter(array('crs'));
989 $this->__storeEntries($object_search->performSearch());
990
991 return true;
992 }
993
998 public function __performRoleSearch()
999 {
1000 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
1001
1002 $query_string = $_SESSION['rep_query']['role']['title'];
1003 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
1004 ilUtil::sendInfo($query_parser, true);
1005 return false;
1006 }
1007
1008 // Perform like search
1009 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
1010 $object_search = new ilLikeObjectSearch($query_parser);
1011 $object_search->setFilter(array('role'));
1012 $this->__storeEntries($object_search->performSearch());
1013
1014 return true;
1015 }
1016
1022 public function &__parseQueryString($a_string, $a_combination_or = true, $a_ignore_length = false)
1023 {
1024 $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
1025 $query_parser->setCombination($a_combination_or ? QP_COMBINATION_OR : QP_COMBINATION_AND);
1026 $query_parser->setMinWordLength(1);
1027
1028 // #17502
1029 if (!(bool) $a_ignore_length) {
1030 $query_parser->setGlobalMinLength(3); // #14768
1031 }
1032
1033 $query_parser->parse();
1034
1035 if (!$query_parser->validate()) {
1036 return $query_parser->getMessage();
1037 }
1038 return $query_parser;
1039 }
1040
1041 // Private
1042 public function __loadQueries()
1043 {
1044 if (is_array($_POST['rep_query'])) {
1045 $_SESSION['rep_query'] = $_POST['rep_query'];
1046 }
1047 }
1048
1049
1050 public function __setSearchType()
1051 {
1052 // Update search type. Default to user search
1053 if ($_POST['search_for']) {
1054 #echo 1;
1055 $_SESSION['rep_search_type'] = $_POST['search_for'];
1056 }
1057 if (!$_POST['search_for'] and !$_SESSION['rep_search_type']) {
1058 #echo 2;
1059 $_SESSION['rep_search_type'] = 'usr';
1060 }
1061
1062 $this->search_type = $_SESSION['rep_search_type'];
1063 #echo $this->search_type;
1064
1065 return true;
1066 }
1067
1068
1069 public function __updateResults()
1070 {
1071 if (!$_SESSION['search_append']) {
1072 $_SESSION['rep_search'] = array();
1073 }
1074 foreach ($this->search_results as $result) {
1075 $_SESSION['rep_search'][$this->search_type][] = $result;
1076 }
1077 if (!$_SESSION['rep_search'][$this->search_type]) {
1078 $_SESSION['rep_search'][$this->search_type] = array();
1079 } else {
1080 // remove duplicate entries
1081 $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
1082 }
1083 return true;
1084 }
1085
1086 public function __appendToStoredResults($a_usr_ids)
1087 {
1088 if (!$_SESSION['search_append']) {
1089 return $_SESSION['rep_search']['usr'] = $a_usr_ids;
1090 }
1091 $_SESSION['rep_search']['usr'] = array();
1092 foreach ($a_usr_ids as $usr_id) {
1093 $_SESSION['rep_search']['usr'][] = $usr_id;
1094 }
1095 return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
1096 }
1097
1098 public function __storeEntries(&$new_res)
1099 {
1100 if ($this->stored == false) {
1101 $this->result_obj->mergeEntries($new_res);
1102 $this->stored = true;
1103 return true;
1104 } else {
1105 $this->result_obj->intersectEntries($new_res);
1106 return true;
1107 }
1108 }
1109
1114 protected function addNewSearchButton()
1115 {
1116 include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1117 $toolbar = new ilToolbarGUI();
1118 $toolbar->addButton(
1119 $this->lng->txt('search_new'),
1120 $this->ctrl->getLinkTarget($this, 'showSearch')
1121 );
1122 $this->tpl->setVariable('ACTION_BUTTONS', $toolbar->getHTML());
1123 }
1124
1125 public function showSearchResults()
1126 {
1127 $counter = 0;
1128 $f_result = array();
1129
1130 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1131 $this->addNewSearchButton();
1132
1133 switch ($this->search_type) {
1134 case "usr":
1135 $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'showSearchResults');
1136 break;
1137
1138 case 'grp':
1139 $this->showSearchGroupTable($_SESSION['rep_search']['grp']);
1140 break;
1141
1142 case 'crs':
1143 $this->showSearchCourseTable($_SESSION['rep_search']['crs']);
1144 break;
1145
1146 case 'role':
1147 $this->showSearchRoleTable($_SESSION['rep_search']['role']);
1148 break;
1149 }
1150 }
1151
1157 protected function showSearchUserTable($a_usr_ids, $a_parent_cmd)
1158 {
1159 $is_in_admin = ($_REQUEST['baseClass'] == 'ilAdministrationGUI');
1160 if ($is_in_admin) {
1161 // remember link target to admin search gui (this)
1162 $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this, 'show');
1163 }
1164
1165 include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
1166
1167 $table = new ilRepositoryUserResultTableGUI($this, $a_parent_cmd, $is_in_admin);
1168 if (count($this->add_options)) {
1169 $table->addMultiItemSelectionButton(
1170 'selectedCommand',
1171 $this->add_options,
1172 'handleMultiCommand',
1173 $this->lng->txt('execute'),
1174 $this->default_option
1175 );
1176 } else {
1177 $table->addMultiCommand('addUser', $this->lng->txt('btn_add'));
1178 }
1179 $table->setUserLimitations($this->getUserLimitations());
1180 $table->parseUserIds($a_usr_ids);
1181
1182 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1183 }
1184
1190 protected function showSearchRoleTable($a_obj_ids)
1191 {
1192 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1193
1194 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1195 $table->parseObjectIds($a_obj_ids);
1196
1197 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1198 }
1199
1205 protected function showSearchGroupTable($a_obj_ids)
1206 {
1207 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1208
1209 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1210 $table->parseObjectIds($a_obj_ids);
1211
1212 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1213 }
1214
1220 protected function showSearchCourseTable($a_obj_ids)
1221 {
1222 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1223
1224 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1225 $table->parseObjectIds($a_obj_ids);
1226
1227 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1228 }
1229
1234 protected function listUsers()
1235 {
1236 // get parameter is used e.g. in exercises to provide
1237 // "add members of course" link
1238 if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1239 $_POST['obj'][0] = $_GET["list_obj"];
1240 }
1241 if (!is_array($_POST['obj']) or !$_POST['obj']) {
1242 ilUtil::sendFailure($this->lng->txt('select_one'));
1243 $this->showSearchResults();
1244 return false;
1245 }
1246
1247 $_SESSION['rep_search']['objs'] = $_POST['obj'];
1248
1249 // Get all members
1250 $members = array();
1251 foreach ($_POST['obj'] as $obj_id) {
1252 $type = ilObject::_lookupType($obj_id);
1253 switch ($type) {
1254 case 'crs':
1255 case 'grp':
1256
1257 include_once './Services/Membership/classes/class.ilParticipants.php';
1259 $part = [];
1260 if (is_callable($this->user_filter)) {
1261 $part = call_user_func_array(
1262 $this->user_filter,
1263 [
1264 ilParticipants::getInstanceByObjId($obj_id)->getParticipants()
1265 ]
1266 );
1267 } else {
1268 $part = ilParticipants::getInstanceByObjId($obj_id)->getParticipants();
1269 }
1270
1271 $members = array_merge((array) $members, $part);
1272 }
1273 break;
1274
1275 case 'role':
1276 global $DIC;
1277
1278 $rbacreview = $DIC['rbacreview'];
1279
1280 $assigned = [];
1281 if (is_callable($this->user_filter)) {
1282 $assigned = call_user_func_array(
1283 $this->user_filter,
1284 [
1285 $rbacreview->assignedUsers($obj_id)
1286 ]
1287 );
1288 } else {
1289 $assigned = $rbacreview->assignedUsers($obj_id);
1290 }
1291
1292 $members = array_merge($members, ilUserFilter::getInstance()->filter($assigned));
1293 break;
1294 case 'orgu':
1295 if ($ref_ids = ilObject::_getAllReferences($obj_id)) {
1297 ->getUserIdsOfOrgUnit(array_shift($ref_ids));
1298 if (is_callable($this->user_filter)) {
1299 $assigned = call_user_func_array(
1300 $this->user_filter,
1301 [$assigned]
1302 );
1303 }
1304
1305 $members = array_merge(
1306 $members,
1307 $assigned
1308 );
1309 }
1310 break;
1311 }
1312 }
1313 $members = array_unique((array) $members);
1314 $this->__appendToStoredResults($members);
1315
1316 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1317
1318 $this->addNewSearchButton();
1319 $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'storedUserList');
1320 return true;
1321 }
1322
1327 protected function storedUserList()
1328 {
1329 $_POST['obj'] = $_SESSION['rep_search']['objs'];
1330 $this->listUsers();
1331 return true;
1332 }
1333
1342 public function searchResultFilterListener($a_ref_id, $a_data)
1343 {
1344 if ($a_data['type'] == 'usr') {
1345 if ($a_data['obj_id'] == ANONYMOUS_USER_ID) {
1346 return false;
1347 }
1348 }
1349 return true;
1350 }
1351
1357 public function allowObjectSelection($a_value = false)
1358 {
1359 $this->object_selection = (bool) $a_value;
1360 }
1361
1365 protected function selectObject()
1366 {
1367 // get parameter is used e.g. in exercises to provide
1368 // "add members of course" link
1369 if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1370 $_POST['obj'][0] = $_GET["list_obj"];
1371 }
1372 if (!is_array($_POST['obj']) or !$_POST['obj']) {
1373 ilUtil::sendFailure($this->lng->txt('select_one'));
1374 $this->showSearchResults();
1375 return false;
1376 }
1377
1378 $this->ctrl->setParameter($this->callback["class"], "obj", implode(";", $_POST["obj"]));
1379 $this->ctrl->redirect($this->callback["class"], $this->callback["method"]);
1380 }
1381
1387 public function setUserLimitations($a_limitations)
1388 {
1389 $this->user_limitations = (bool) $a_limitations;
1390 }
1391
1396 public function getUserLimitations()
1397 {
1399 }
1400}
$result
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const QP_COMBINATION_OR
const QP_COMBINATION_AND
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const FIELD_TYPE_TEXT
const FIELD_TYPE_MULTI
const FIELD_TYPE_SELECT
const FIELD_TYPE_UDF_SELECT
Class ilUserSearchOptions.
const FIELD_TYPE_UDF_TEXT
static encode($mixed, $suppress_native=false)
static getInstance()
Factory.
static getLogger($a_component_id)
Get component logger.
static getRootOrgRefId()
static _lookupId($a_user_str)
Lookup id by login.
static _getUserDefinedFieldSearchInstance($query_parser)
get reference of ilLikeUserDefinedFieldSearch
static getUserMultiFieldSearchInstance($query_parser)
static getUserOrgUnitAssignmentInstance($query_parser)
get orgunit search instance
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getDefaultMemberRole($a_ref_id)
static hasParticipantListAccess($a_obj_id, $a_usr_id=null)
Check if (current) user has access to the participant list.
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
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.
TableGUI class object (course,group and role) search results Used in member search.
selectObject()
Return selection of course/group/roles to calling script.
initFormSearch(ilObjUser $user=null)
setRoleCallback(&$class, $method, $a_add_options=array(), $default_option='')
emptyClipboard()
Remove from clipboard.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
removeFromClipboard()
Remove from clipboard.
showSearchRoleTable($a_obj_ids)
Show usr table.
setTitle($a_title)
Set form title.
enableSearchableCheck($a_status)
En/disable the validation of the searchable flag.
storedUserList()
Called from table sort.
setCallback(&$class, $method, $a_add_options=array(), $default_option='')
showSearchSelected()
submit from autocomplete
doUserAutoComplete()
Do auto completion.
getTitle()
Get search form title.
addFromClipboard()
add users from clipboard
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
showSearchUserTable($a_usr_ids, $a_parent_cmd)
Show usr table.
setPermissionQueryCallback($class, $method)
Set callback method for user permission access queries.
searchResultFilterListener($a_ref_id, $a_data)
Listener called from ilSearchResult Id is obj_id for role, usr Id is ref_id for crs grp.
addUserAccessFilterCallable(callable $user_filter)
Closure for filtering users e.g $rep_search_gui->addUserAccessFilterCallable(function($user_ids) use(...
listUsers()
List users of course/group/roles.
addNewSearchButton()
Add new search button.
getUserLimitations()
allow user limitations like inactive and access limitations
executeCommand()
Control @access public.
setString($a_str)
Set/get search string @access public.
addUserFromAutoComplete()
Add user from auto complete input.
handleMultiCommand()
Handle multi command.
allowObjectSelection($a_value=false)
Toggle object selection status.
& __parseQueryString($a_string, $a_combination_or=true, $a_ignore_length=false)
parse query string, using query parser instance
__construct()
Constructor @access public.
This class represents a selection list property in a property form.
static getInstance()
Factory.
This class represents a text property in a property form.
Auto completion class for user lists.
Show administrate clipboard content.
static getInstance($a_usr_id)
Get singelton instance.
static getInstance()
Singelton get instance.
static _getSearchableFieldsInfo($a_admin=false)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
const ANONYMOUS_USER_ID
Definition: constants.php:25
const ROOT_FOLDER_ID
Definition: constants.php:30
$txt
Definition: error.php:13
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
exit
Definition: login.php:29
if($format !==null) $name
Definition: metadata.php:230
$type
$lng
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
$message
Definition: xapiexit.php:14