ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $object_selection = false;
49
50 protected $searchable_check = true;
51 protected $search_title = '';
52
53 public $search_type = 'usr';
54 protected $user_limitations = true;
55
59 protected $user_filter = null;
60
65
66
70 protected $tree;
74 protected $ui_renderer;
78 protected $ui_factory;
79
84 public function __construct()
85 {
86 global $DIC;
87
88 $ilCtrl = $DIC['ilCtrl'];
89 $tpl = $DIC['tpl'];
90 $lng = $DIC['lng'];
91 $tree = $DIC['tree'];
92 $ui_renderer = $DIC["ui.renderer"];
93 $ui_factory = $DIC["ui.factory"];
94
95 $this->ctrl = $ilCtrl;
96 $this->tpl = $tpl;
97 $this->tree = $tree;
98 $this->ui_renderer = $ui_renderer;
99 $this->ui_factory = $ui_factory;
100
101 $this->lng = $lng;
102 $this->lng->loadLanguageModule('search');
103 $this->lng->loadLanguageModule('crs');
104
105 $this->setTitle($this->lng->txt('add_members_header'));
106
107 $this->__setSearchType();
108 $this->__loadQueries();
109
110 $this->result_obj = new ilSearchResult();
111 $this->result_obj->setMaxHits(1000000);
112 $this->settings = new ilSearchSettings();
113 }
114
125 {
126 $this->user_filter = $user_filter;
127 }
128
133 public function setTitle($a_title)
134 {
135 $this->search_title = $a_title;
136 }
137
142 public function getTitle()
143 {
144 return $this->search_title;
145 }
146
151 public function enableSearchableCheck($a_status)
152 {
153 $this->searchable_check = $a_status;
154 }
155
160 public function isSearchableCheckEnabled()
161 {
163 }
164
169 {
170 $this->privacy_mode = $privacy_mode;
171 }
172
176 public function getPrivacyMode()
177 {
178 return $this->privacy_mode;
179 }
180
181
195 public static function fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar = null, $a_options = array(), $a_sticky = false)
196 {
197 global $DIC;
198
199 $ilToolbar = $DIC['ilToolbar'];
200 $lng = $DIC['lng'];
201 $ilCtrl = $DIC['ilCtrl'];
202 $tree = $DIC['tree'];
203
204 if (!$toolbar instanceof ilToolbarGUI) {
205 $toolbar = $ilToolbar;
206 }
207
208 // Fill default options
209 if (!isset($a_options['auto_complete_name'])) {
210 $a_options['auto_complete_name'] = $lng->txt('obj_user');
211 }
212 if (!isset($a_options['auto_complete_size'])) {
213 $a_options['auto_complete_size'] = 15;
214 }
215 if (!isset($a_options['submit_name'])) {
216 $a_options['submit_name'] = $lng->txt('btn_add');
217 }
218 if (!isset($a_options['user_type_default'])) {
219 $a_options['user_type_default'] = null;
220 }
221
222 $ajax_url = $ilCtrl->getLinkTargetByClass(
223 array(get_class($parent_object),'ilRepositorySearchGUI'),
224 'doUserAutoComplete',
225 '',
226 true,
227 false
228 );
229
230 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
231 $ul = new ilTextInputGUI($a_options['auto_complete_name'], 'user_login');
232 $ul->setDataSource($ajax_url);
233 $ul->setSize($a_options['auto_complete_size']);
234 if (!$a_sticky) {
235 $toolbar->addInputItem($ul, true);
236 } else {
237 $toolbar->addStickyItem($ul, true);
238 }
239
240 if (count((array) $a_options['user_type'])) {
241 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
242 $si = new ilSelectInputGUI("", "user_type");
243 $si->setOptions($a_options['user_type']);
244 $si->setValue($a_options['user_type_default']);
245 if (!$a_sticky) {
246 $toolbar->addInputItem($si);
247 } else {
248 $toolbar->addStickyItem($si);
249 }
250 }
251
252 include_once './Services/User/classes/class.ilUserClipboard.php';
253 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
254 if ($clip->hasContent()) {
255 include_once './Services/UIComponent/SplitButton/classes/class.ilSplitButtonGUI.php';
256 $action_button = ilSplitButtonGUI::getInstance();
257
258 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
259 $add_button = ilSubmitButton::getInstance();
260 $add_button->setCaption($a_options['submit_name'], false);
261 $add_button->setCommand('addUserFromAutoComplete');
262
263 $action_button->setDefaultButton($add_button);
264
265 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
266 $clip_button = ilSubmitButton::getInstance();
267 $clip_button->addCSSClass('btn btndefault');
268 $GLOBALS['DIC']->language()->loadLanguageModule('user');
269 $clip_button->setCaption($GLOBALS['DIC']->language()->txt('clipboard_add_from_btn'), false);
270 $clip_button->setCommand('showClipboard');
271
272 $action_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($clip_button));
273
274 $toolbar->addButtonInstance($action_button);
275 } else {
276 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
277 $button = ilSubmitButton::getInstance();
278 $button->setCaption($a_options['submit_name'], false);
279 $button->setCommand('addUserFromAutoComplete');
280 if (!$a_sticky) {
281 $toolbar->addButtonInstance($button);
282 } else {
283 $toolbar->addStickyItem($button);
284 }
285 }
286
287 if ((bool) $a_options['add_search'] ||
288 is_numeric($a_options['add_from_container'])) {
289 $lng->loadLanguageModule("search");
290
291 $toolbar->addSeparator();
292
293 if ((bool) $a_options['add_search']) {
294 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
295 $button = ilLinkButton::getInstance();
296 $button->setCaption("search_users");
297 $button->setUrl($ilCtrl->getLinkTargetByClass('ilRepositorySearchGUI', ''));
298 $toolbar->addButtonInstance($button);
299 }
300
301 if (is_numeric($a_options['add_from_container'])) {
302 $parent_ref_id = (int) $a_options['add_from_container'];
303 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "grp");
304 $parent_container_type = "grp";
305 if (!$parent_container_ref_id) {
306 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "crs");
307 $parent_container_type = "crs";
308 }
309 if ($parent_container_ref_id) {
310 if ((bool) $a_options['add_search']) {
311 $toolbar->addSpacer();
312 }
313
314 $ilCtrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", ilObject::_lookupObjId($parent_container_ref_id));
315
316 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
317 $button = ilLinkButton::getInstance();
318 $button->setCaption("search_add_members_from_container_" . $parent_container_type);
319 $button->setUrl($ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'), 'listUsers'));
320 $toolbar->addButtonInstance($button);
321 }
322 }
323 }
324
325 $toolbar->setFormAction(
326 $ilCtrl->getFormActionByClass(
327 array(
328 get_class($parent_object),
329 'ilRepositorySearchGUI')
330 )
331 );
332 return $toolbar;
333 }
334
339 protected function doUserAutoComplete()
340 {
341 // hide anonymout request
342 if ($GLOBALS['DIC']['ilUser']->getId() == ANONYMOUS_USER_ID) {
343 include_once './Services/JSON/classes/class.ilJsonUtil.php';
344 return ilJsonUtil::encode(new stdClass());
345 exit;
346 }
347
348
349 if (!isset($_GET['autoCompleteField'])) {
350 $a_fields = array('login','firstname','lastname','email');
351 $result_field = 'login';
352 } else {
353 $a_fields = array((string) $_GET['autoCompleteField']);
354 $result_field = (string) $_GET['autoCompleteField'];
355 }
356
357 include_once './Services/User/classes/class.ilUserAutoComplete.php';
358 $auto = new ilUserAutoComplete();
359 $auto->setPrivacyMode($this->getPrivacyMode());
360
361 if (($_REQUEST['fetchall'])) {
362 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
363 }
364
365 $auto->setMoreLinkAvailable(true);
366 $auto->setSearchFields($a_fields);
367 $auto->setResultField($result_field);
368 $auto->enableFieldSearchableCheck(true);
369 $auto->setUserLimitations($this->getUserLimitations());
370 if (is_callable($this->user_filter)) { // #0024249
371 $auto->addUserAccessFilterCallable($this->user_filter);
372 }
373
374 echo $auto->getList($_REQUEST['term']);
375 exit();
376 }
377
378
383 public function setString($a_str)
384 {
385 $_SESSION['search']['string'] = $this->string = $a_str;
386 }
387 public function getString()
388 {
389 return $this->string;
390 }
391
396 public function executeCommand()
397 {
398 global $DIC;
399
400 $rbacsystem = $DIC['rbacsystem'];
401
402 $next_class = $this->ctrl->getNextClass($this);
403 $cmd = $this->ctrl->getCmd();
404
405 $this->ctrl->setReturn($this, '');
406
407 switch ($next_class) {
408 default:
409 if (!$cmd) {
410 $cmd = "showSearch";
411 }
412 $this->$cmd();
413 break;
414 }
415 return true;
416 }
417
418 public function __clearSession()
419 {
420 unset($_SESSION['rep_search']);
421 unset($_SESSION['append_results']);
422 unset($_SESSION['rep_query']);
423 unset($_SESSION['rep_search_type']);
424 }
425
426 public function cancel()
427 {
428 $this->ctrl->returnToParent($this);
429 }
430
431 public function start()
432 {
433 // delete all session info
434 $this->__clearSession();
435 $this->showSearch();
436
437 return true;
438 }
439
440
441 public function addRole()
442 {
443 $class = $this->role_callback['class'];
444 $method = $this->role_callback['method'];
445
446 // call callback if that function does give a return value => show error message
447 // listener redirects if everything is ok.
448 $obj_ids = (array) $_POST['obj'];
449 $role_ids = array();
450 foreach ($obj_ids as $id) {
451 $obj_type = ilObject::_lookupType($id);
452 if ($obj_type == "crs" || $obj_type == "grp") {
453 $refs = ilObject::_getAllReferences($id);
454 $ref_id = end($refs);
455 $mem_role = ilParticipants::getDefaultMemberRole($ref_id);
456 $role_ids[] = $mem_role;
457 } else {
458 $role_ids[] = $id;
459 }
460 }
461 $class->$method((array) $role_ids);
462
463 $this->showSearchResults();
464 }
465
466 public function addUser()
467 {
468 $class = $this->callback['class'];
469 $method = $this->callback['method'];
470
471 // call callback if that function does give a return value => show error message
472 // listener redirects if everything is ok.
473 $class->$method((array) $_POST['user']);
474
475 $this->showSearchResults();
476 }
477
481 protected function addUserFromAutoComplete()
482 {
483 $class = $this->callback['class'];
484 $method = $this->callback['method'];
485
486 $users = explode(',', $_POST['user_login']);
487 $user_ids = array();
488 foreach ($users as $user) {
489 $user_id = ilObjUser::_lookupId($user);
490 if ($user_id) {
491 $user_ids[] = $user_id;
492 }
493 }
494
495 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
496
497 if (!$class->$method($user_ids, $user_type)) {
498 $GLOBALS['DIC']['ilCtrl']->returnToParent($this);
499 }
500 }
501
502 protected function showClipboard()
503 {
504 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
505
506 ilLoggerFactory::getLogger('crs')->dump($_REQUEST);
507
508 $GLOBALS['DIC']['ilTabs']->clearTargets();
509 $GLOBALS['DIC']['ilTabs']->setBackTarget(
510 $GLOBALS['DIC']['lng']->txt('back'),
511 $GLOBALS['DIC']['ilCtrl']->getParentReturn($this)
512 );
513
514 include_once './Services/User/classes/class.ilUserClipboardTableGUI.php';
515 $clip = new ilUserClipboardTableGUI($this, 'showClipboard', $GLOBALS['DIC']['ilUser']->getId());
516 $clip->setFormAction($GLOBALS['DIC']['ilCtrl']->getFormAction($this));
517 $clip->init();
518 $clip->parse();
519
520 $GLOBALS['DIC']['tpl']->setContent($clip->getHTML());
521 }
522
526 protected function addFromClipboard()
527 {
528 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
529 $users = (array) $_POST['uids'];
530 if (!count($users)) {
531 ilUtil::sendFailure($this->lng->txt('select_one'), true);
532 $GLOBALS['DIC']['ilCtrl']->redirect($this, 'showClipboard');
533 }
534 $class = $this->callback['class'];
535 $method = $this->callback['method'];
536 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
537
538 if (!$class->$method($users, $user_type)) {
539 $GLOBALS['DIC']['ilCtrl']->returnToParent($this);
540 }
541 }
542
546 protected function removeFromClipboard()
547 {
548 $GLOBALS['DIC']['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
549 $users = (array) $_POST['uids'];
550 if (!count($users)) {
551 ilUtil::sendFailure($this->lng->txt('select_one'), true);
552 $GLOBALS['DIC']['ilCtrl']->redirect($this, 'showClipboard');
553 }
554
555 include_once './Services/User/classes/class.ilUserClipboard.php';
556 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
557 $clip->delete($users);
558 $clip->save();
559
560 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
561 $this->ctrl->redirect($this, 'showClipboard');
562 }
563
567 protected function emptyClipboard()
568 {
569 include_once './Services/User/classes/class.ilUserClipboard.php';
570 $clip = ilUserClipboard::getInstance($GLOBALS['DIC']['ilUser']->getId());
571 $clip->clear();
572 $clip->save();
573
574 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
575 $this->ctrl->returnToParent($this);
576 }
577
581 protected function handleMultiCommand()
582 {
583 $class = $this->callback['class'];
584 $method = $this->callback['method'];
585
586 // Redirects if everything is ok
587 if (!$class->$method((array) $_POST['user'], $_POST['selectedCommand'])) {
588 $this->showSearchResults();
589 }
590 }
591
592 public function setCallback(&$class, $method, $a_add_options = array())
593 {
594 $this->callback = array('class' => $class,'method' => $method);
595 $this->add_options = $a_add_options ? $a_add_options : array();
596 }
597
598 public function setRoleCallback(&$class, $method, $a_add_options = array())
599 {
600 $this->role_callback = array('class' => $class,'method' => $method);
601 $this->add_options = $a_add_options ? $a_add_options : array();
602 }
603
607 public function setPermissionQueryCallback($class, $method)
608 {
609 }
610
611 public function showSearch()
612 {
613 // only autocomplete input field, no search form if user privay should be respected
614 // see bug 25481
616 return;
617 }
618 $this->initFormSearch();
619 $this->tpl->setContent($this->form->getHTML());
620 }
621
625 public function showSearchSelected()
626 {
627 $selected = (int) $_REQUEST['selected_id'];
628
629 #include_once './Services/Object/classes/class.ilObjectFactory.php';
630 #$factory = new ilObjectFactory();
631 #$user = $factory->getInstanceByObjId($selected);
632
633 #$this->initFormSearch($user);
634 #$this->tpl->setContent($this->form->getHTML());
635
636 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
637 $this->addNewSearchButton();
638 $this->showSearchUserTable(array($selected), 'showSearchResults');
639 }
640
641 public function initFormSearch(ilObjUser $user = null)
642 {
643 global $DIC;
644
645 $ilCtrl = $DIC['ilCtrl'];
646
647 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
648
649 $this->form = new ilPropertyFormGUI();
650 $this->form->setFormAction($this->ctrl->getFormAction($this, 'showSearch'));
651 $this->form->setTitle($this->getTitle());
652 $this->form->addCommandButton('performSearch', $this->lng->txt('search'));
653 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
654
655
656 $kind = new ilRadioGroupInputGUI($this->lng->txt('search_type'), 'search_for');
657 $kind->setValue($this->search_type);
658 $this->form->addItem($kind);
659
660 // Users
661 $users = new ilRadioOption($this->lng->txt('search_for_users'), 'usr');
662
663 // UDF
664 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
666 switch ($info['type']) {
669
670 $sel = new ilSelectInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
671 $sel->setOptions($info['values']);
672 $users->addSubItem($sel);
673 break;
674
675 case FIELD_TYPE_MULTI:
677 case FIELD_TYPE_TEXT:
678
679 if (isset($info['autoComplete']) and $info['autoComplete']) {
680 $ilCtrl->setParameterByClass(get_class($this), 'autoCompleteField', $info['db']);
681 $ul = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
682 $ul->setDataSourceSubmitOnSelection(true);
683 $ul->setDataSourceSubmitUrl(
684 $this->ctrl->getLinkTarget(
685 $this,
686 'showSearchSelected',
687 '',
688 false,
689 false
690 )
691 );
692 $ul->setDataSource($ilCtrl->getLinkTarget(
693 $this,
694 "doUserAutoComplete",
695 "",
696 true
697 ));
698 $ul->setSize(30);
699 $ul->setMaxLength(120);
700
701 if ($user instanceof ilObjUser) {
702 switch ($info['db']) {
703 case 'firstname':
704 $ul->setValue($user->getFirstname());
705 break;
706 case 'lastname':
707 $ul->setValue($user->getLastname());
708 break;
709 case 'login':
710 $ul->setValue($user->getLogin());
711 break;
712 }
713 }
714
715
716
717 $users->addSubItem($ul);
718 } else {
719 $txt = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
720 $txt->setSize(30);
721 $txt->setMaxLength(120);
722 $users->addSubItem($txt);
723 }
724 break;
725 }
726 }
727 $kind->addOption($users);
728
729
730
731 // Role
732 $roles = new ilRadioOption($this->lng->txt('search_for_role_members'), 'role');
733 $role = new ilTextInputGUI($this->lng->txt('search_role_title'), 'rep_query[role][title]');
734 $role->setSize(30);
735 $role->setMaxLength(120);
736 $roles->addSubItem($role);
737 $kind->addOption($roles);
738
739 // Course
740 $groups = new ilRadioOption($this->lng->txt('search_for_crs_members'), 'crs');
741 $group = new ilTextInputGUI($this->lng->txt('search_crs_title'), 'rep_query[crs][title]');
742 $group->setSize(30);
743 $group->setMaxLength(120);
744 $groups->addSubItem($group);
745 $kind->addOption($groups);
746
747 // Group
748 $groups = new ilRadioOption($this->lng->txt('search_for_grp_members'), 'grp');
749 $group = new ilTextInputGUI($this->lng->txt('search_grp_title'), 'rep_query[grp][title]');
750 $group->setSize(30);
751 $group->setMaxLength(120);
752 $groups->addSubItem($group);
753 $kind->addOption($groups);
754
755 // Orgus
756 if (ilUserSearchOptions::_isEnabled("org_units")) {
757 $orgus = new ilRadioOption($this->lng->txt('search_for_orgu_members'), 'orgu');
758 $orgu = new ilRepositorySelector2InputGUI($this->lng->txt('select_orgu'), 'rep_query_orgu', true, get_class($this));
759 $orgu->getExplorerGUI()->setSelectableTypes(["orgu"]);
760 $orgu->getExplorerGUI()->setTypeWhiteList(["root", "orgu"]);
761 $orgu->getExplorerGUI()->setRootId(ilObjOrgUnit::getRootOrgRefId());
762 $orgu->getExplorerGUI()->setAjax(false);
763 $orgus->addSubItem($orgu);
764 $kind->addOption($orgus);
765 }
766 }
767
768
769 public function show()
770 {
771 $this->showSearchResults();
772 }
773
774 public function appendSearch()
775 {
776 $_SESSION['search_append'] = true;
777 $this->performSearch();
778 }
779
784 public function performSearch()
785 {
786 // only autocomplete input field, no search form if user privay should be respected
787 // see bug 25481
789 return "";
790 }
791 $found_query = false;
792 foreach ((array) $_POST['rep_query'][$_POST['search_for']] as $field => $value) {
793 if (trim(ilUtil::stripSlashes($value))) {
794 $found_query = true;
795 break;
796 }
797 }
798 if (array_key_exists('rep_query_orgu', $_POST) && count($_POST['rep_query_orgu']) > 0) {
799 $found_query = true;
800 }
801 if (!$found_query) {
802 ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
803 $this->start();
804 return false;
805 }
806
807 // unset search_append if called directly
808 if ($_POST['cmd']['performSearch']) {
809 unset($_SESSION['search_append']);
810 }
811
812 switch ($this->search_type) {
813 case 'usr':
814 $this->__performUserSearch();
815 break;
816
817 case 'grp':
818 $this->__performGroupSearch();
819 break;
820
821 case 'crs':
822 $this->__performCourseSearch();
823 break;
824
825 case 'role':
826 $this->__performRoleSearch();
827 break;
828 case 'orgu':
829 $_POST['obj'] = array_map(
830 function ($ref_id) {
831 return (int) ilObject::_lookupObjId($ref_id);
832 },
833 $_POST['rep_query_orgu']
834 );
835 return $this->listUsers();
836 default:
837 echo 'not defined';
838 }
839
840 $this->result_obj->setRequiredPermission('read');
841 $this->result_obj->addObserver($this, 'searchResultFilterListener');
842 $this->result_obj->filter(ROOT_FOLDER_ID, QP_COMBINATION_OR);
843
844 // User access filter
845 if ($this->search_type == 'usr') {
846 $callable_name = '';
847 if (is_callable($this->user_filter, true, $callable_name)) {
848 $result_ids = call_user_func_array($this->user_filter, [$this->result_obj->getResultIds()]);
849 } else {
850 $result_ids = $this->result_obj->getResultIds();
851 }
852
853 include_once './Services/User/classes/class.ilUserFilter.php';
854 $this->search_results = array_intersect(
855 $result_ids,
856 ilUserFilter::getInstance()->filter($result_ids)
857 );
858 } else {
859 $this->search_results = array();
860 foreach ((array) $this->result_obj->getResults() as $res) {
861 $this->search_results[] = $res['obj_id'];
862 }
863 }
864
865 if (!count($this->search_results)) {
866 ilUtil::sendFailure($this->lng->txt('search_no_match'));
867 $this->showSearch();
868 return true;
869 }
870 $this->__updateResults();
871 if ($this->result_obj->isLimitReached()) {
872 $message = sprintf($this->lng->txt('search_limit_reached'), $this->settings->getMaxHits());
874 return true;
875 }
876 // show results
877 $this->show();
878 return true;
879 }
880
881 public function __performUserSearch()
882 {
883 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
884 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
885
887 $name = $info['db'];
888 $query_string = $_SESSION['rep_query']['usr'][$name];
889
890 // continue if no query string is given
891 if (!$query_string) {
892 continue;
893 }
894
895 if (!is_object($query_parser = $this->__parseQueryString($query_string, true, ($info['type'] == FIELD_TYPE_SELECT)))) {
896 ilUtil::sendInfo($query_parser);
897 return false;
898 }
899 switch ($info['type']) {
901 // Do a phrase query for select fields
902 $query_parser = $this->__parseQueryString('"' . $query_string . '"');
903
904 // no break
907 $udf_search->setFields(array($name));
908 $result_obj = $udf_search->performSearch();
909
910 // Store entries
911 $this->__storeEntries($result_obj);
912 break;
913
915
916 if ($info['db'] == 'org_units') {
918 $result_obj = $user_search->performSearch();
919 $this->__storeEntries($result_obj);
920 break;
921 }
922
923 // Do a phrase query for select fields
924 $query_parser = $this->__parseQueryString('"' . $query_string . '"', true, true);
925
926 // no break
927 case FIELD_TYPE_TEXT:
928 $user_search = &ilObjectSearchFactory::_getUserSearchInstance($query_parser);
929 $user_search->setFields(array($name));
930 $result_obj = $user_search->performSearch();
931
932 // store entries
933 $this->__storeEntries($result_obj);
934 break;
935
936 case FIELD_TYPE_MULTI:
937 $multi_search = ilObjectSearchFactory::getUserMultiFieldSearchInstance($query_parser);
938 $multi_search->setFields(array($name));
939 $result_obj = $multi_search->performSearch();
940 $this->__storeEntries($result_obj);
941 break;
942
943 }
944 }
945 }
946
951 public function __performGroupSearch()
952 {
953 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
954
955 $query_string = $_SESSION['rep_query']['grp']['title'];
956 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
957 ilUtil::sendInfo($query_parser, true);
958 return false;
959 }
960
961 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
962 $object_search = new ilLikeObjectSearch($query_parser);
963 $object_search->setFilter(array('grp'));
964 $this->__storeEntries($object_search->performSearch());
965
966 return true;
967 }
968
973 protected function __performCourseSearch()
974 {
975 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
976
977 $query_string = $_SESSION['rep_query']['crs']['title'];
978 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
979 ilUtil::sendInfo($query_parser, true);
980 return false;
981 }
982
983 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
984 $object_search = new ilLikeObjectSearch($query_parser);
985 $object_search->setFilter(array('crs'));
986 $this->__storeEntries($object_search->performSearch());
987
988 return true;
989 }
990
995 public function __performRoleSearch()
996 {
997 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
998
999 $query_string = $_SESSION['rep_query']['role']['title'];
1000 if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
1001 ilUtil::sendInfo($query_parser, true);
1002 return false;
1003 }
1004
1005 // Perform like search
1006 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
1007 $object_search = new ilLikeObjectSearch($query_parser);
1008 $object_search->setFilter(array('role'));
1009 $this->__storeEntries($object_search->performSearch());
1010
1011 return true;
1012 }
1013
1019 public function &__parseQueryString($a_string, $a_combination_or = true, $a_ignore_length = false)
1020 {
1021 $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
1022 $query_parser->setCombination($a_combination_or ? QP_COMBINATION_OR : QP_COMBINATION_AND);
1023 $query_parser->setMinWordLength(1);
1024
1025 // #17502
1026 if (!(bool) $a_ignore_length) {
1027 $query_parser->setGlobalMinLength(3); // #14768
1028 }
1029
1030 $query_parser->parse();
1031
1032 if (!$query_parser->validate()) {
1033 return $query_parser->getMessage();
1034 }
1035 return $query_parser;
1036 }
1037
1038 // Private
1039 public function __loadQueries()
1040 {
1041 if (is_array($_POST['rep_query'])) {
1042 $_SESSION['rep_query'] = $_POST['rep_query'];
1043 }
1044 }
1045
1046
1047 public function __setSearchType()
1048 {
1049 // Update search type. Default to user search
1050 if ($_POST['search_for']) {
1051 #echo 1;
1052 $_SESSION['rep_search_type'] = $_POST['search_for'];
1053 }
1054 if (!$_POST['search_for'] and !$_SESSION['rep_search_type']) {
1055 #echo 2;
1056 $_SESSION['rep_search_type'] = 'usr';
1057 }
1058
1059 $this->search_type = $_SESSION['rep_search_type'];
1060 #echo $this->search_type;
1061
1062 return true;
1063 }
1064
1065
1066 public function __updateResults()
1067 {
1068 if (!$_SESSION['search_append']) {
1069 $_SESSION['rep_search'] = array();
1070 }
1071 foreach ($this->search_results as $result) {
1072 $_SESSION['rep_search'][$this->search_type][] = $result;
1073 }
1074 if (!$_SESSION['rep_search'][$this->search_type]) {
1075 $_SESSION['rep_search'][$this->search_type] = array();
1076 } else {
1077 // remove duplicate entries
1078 $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
1079 }
1080 return true;
1081 }
1082
1083 public function __appendToStoredResults($a_usr_ids)
1084 {
1085 if (!$_SESSION['search_append']) {
1086 return $_SESSION['rep_search']['usr'] = $a_usr_ids;
1087 }
1088 $_SESSION['rep_search']['usr'] = array();
1089 foreach ($a_usr_ids as $usr_id) {
1090 $_SESSION['rep_search']['usr'][] = $usr_id;
1091 }
1092 return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
1093 }
1094
1095 public function __storeEntries(&$new_res)
1096 {
1097 if ($this->stored == false) {
1098 $this->result_obj->mergeEntries($new_res);
1099 $this->stored = true;
1100 return true;
1101 } else {
1102 $this->result_obj->intersectEntries($new_res);
1103 return true;
1104 }
1105 }
1106
1111 protected function addNewSearchButton()
1112 {
1113 include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1114 $toolbar = new ilToolbarGUI();
1115 $toolbar->addButton(
1116 $this->lng->txt('search_new'),
1117 $this->ctrl->getLinkTarget($this, 'showSearch')
1118 );
1119 $this->tpl->setVariable('ACTION_BUTTONS', $toolbar->getHTML());
1120 }
1121
1122 public function showSearchResults()
1123 {
1124 $counter = 0;
1125 $f_result = array();
1126
1127 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1128 $this->addNewSearchButton();
1129
1130 switch ($this->search_type) {
1131 case "usr":
1132 $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'showSearchResults');
1133 break;
1134
1135 case 'grp':
1136 $this->showSearchGroupTable($_SESSION['rep_search']['grp']);
1137 break;
1138
1139 case 'crs':
1140 $this->showSearchCourseTable($_SESSION['rep_search']['crs']);
1141 break;
1142
1143 case 'role':
1144 $this->showSearchRoleTable($_SESSION['rep_search']['role']);
1145 break;
1146 }
1147 }
1148
1154 protected function showSearchUserTable($a_usr_ids, $a_parent_cmd)
1155 {
1156 $is_in_admin = ($_REQUEST['baseClass'] == 'ilAdministrationGUI');
1157 if ($is_in_admin) {
1158 // remember link target to admin search gui (this)
1159 $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this, 'show');
1160 }
1161
1162 include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
1163
1164 $table = new ilRepositoryUserResultTableGUI($this, $a_parent_cmd, $is_in_admin);
1165 if (count($this->add_options)) {
1166 $table->addMultiItemSelectionButton(
1167 'selectedCommand',
1168 $this->add_options,
1169 'handleMultiCommand',
1170 $this->lng->txt('execute')
1171 );
1172 } else {
1173 $table->addMultiCommand('addUser', $this->lng->txt('btn_add'));
1174 }
1175 $table->setUserLimitations($this->getUserLimitations());
1176 $table->parseUserIds($a_usr_ids);
1177
1178 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1179 }
1180
1186 protected function showSearchRoleTable($a_obj_ids)
1187 {
1188 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1189
1190 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1191 $table->parseObjectIds($a_obj_ids);
1192
1193 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1194 }
1195
1201 protected function showSearchGroupTable($a_obj_ids)
1202 {
1203 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1204
1205 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1206 $table->parseObjectIds($a_obj_ids);
1207
1208 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1209 }
1210
1216 protected function showSearchCourseTable($a_obj_ids)
1217 {
1218 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1219
1220 $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1221 $table->parseObjectIds($a_obj_ids);
1222
1223 $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1224 }
1225
1230 protected function listUsers()
1231 {
1232 // get parameter is used e.g. in exercises to provide
1233 // "add members of course" link
1234 if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1235 $_POST['obj'][0] = $_GET["list_obj"];
1236 }
1237 if (!is_array($_POST['obj']) or !$_POST['obj']) {
1238 ilUtil::sendFailure($this->lng->txt('select_one'));
1239 $this->showSearchResults();
1240 return false;
1241 }
1242
1243 $_SESSION['rep_search']['objs'] = $_POST['obj'];
1244
1245 // Get all members
1246 $members = array();
1247 foreach ($_POST['obj'] as $obj_id) {
1248 $type = ilObject::_lookupType($obj_id);
1249 switch ($type) {
1250 case 'crs':
1251 case 'grp':
1252
1253 include_once './Services/Membership/classes/class.ilParticipants.php';
1255 $part = [];
1256 if (is_callable($this->user_filter)) {
1257 $part = call_user_func_array(
1258 $this->user_filter,
1259 [
1260 ilParticipants::getInstanceByObjId($obj_id)->getParticipants()
1261 ]
1262 );
1263 } else {
1264 $part = ilParticipants::getInstanceByObjId($obj_id)->getParticipants();
1265 }
1266
1267 $members = array_merge((array) $members, $part);
1268 }
1269 break;
1270
1271 case 'role':
1272 global $DIC;
1273
1274 $rbacreview = $DIC['rbacreview'];
1275
1276 $assigned = [];
1277 if (is_callable($this->user_filter)) {
1278 $assigned = call_user_func_array(
1279 $this->user_filter,
1280 [
1281 $rbacreview->assignedUsers($obj_id)
1282 ]
1283 );
1284 } else {
1285 $assigned = $rbacreview->assignedUsers($obj_id);
1286 }
1287
1288 $members = array_merge($members, ilUserFilter::getInstance()->filter($assigned));
1289 break;
1290 case 'orgu':
1291 if ($ref_ids = ilObject::_getAllReferences($obj_id)) {
1293 ->getUserIdsOfOrgUnit(array_shift($ref_ids));
1294 if (is_callable($this->user_filter)) {
1295 $assigned = call_user_func_array(
1296 $this->user_filter,
1297 [$assigned]
1298 );
1299 }
1300
1301 $members = array_merge(
1302 $members,
1303 $assigned
1304 );
1305 }
1306 break;
1307 }
1308 }
1309 $members = array_unique((array) $members);
1310 $this->__appendToStoredResults($members);
1311
1312 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1313
1314 $this->addNewSearchButton();
1315 $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'storedUserList');
1316 return true;
1317 }
1318
1323 protected function storedUserList()
1324 {
1325 $_POST['obj'] = $_SESSION['rep_search']['objs'];
1326 $this->listUsers();
1327 return true;
1328 }
1329
1338 public function searchResultFilterListener($a_ref_id, $a_data)
1339 {
1340 if ($a_data['type'] == 'usr') {
1341 if ($a_data['obj_id'] == ANONYMOUS_USER_ID) {
1342 return false;
1343 }
1344 }
1345 return true;
1346 }
1347
1353 public function allowObjectSelection($a_value = false)
1354 {
1355 $this->object_selection = (bool) $a_value;
1356 }
1357
1361 protected function selectObject()
1362 {
1363 // get parameter is used e.g. in exercises to provide
1364 // "add members of course" link
1365 if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1366 $_POST['obj'][0] = $_GET["list_obj"];
1367 }
1368 if (!is_array($_POST['obj']) or !$_POST['obj']) {
1369 ilUtil::sendFailure($this->lng->txt('select_one'));
1370 $this->showSearchResults();
1371 return false;
1372 }
1373
1374 $this->ctrl->setParameter($this->callback["class"], "obj", implode(";", $_POST["obj"]));
1375 $this->ctrl->redirect($this->callback["class"], $this->callback["method"]);
1376 }
1377
1383 public function setUserLimitations($a_limitations)
1384 {
1385 $this->user_limitations = (bool) $a_limitations;
1386 }
1387
1392 public function getUserLimitations()
1393 {
1395 }
1396}
$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
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)
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.
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
setRoleCallback(&$class, $method, $a_add_options=array())
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.
setCallback(&$class, $method, $a_add_options=array())
& __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.
$txt
Definition: error.php:13
global $ilCtrl
Definition: ilias.php:18
language()
Definition: language.php:2
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
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46