ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
35include_once 'Services/Search/classes/class.ilSearchResult.php';
36include_once 'Services/Search/classes/class.ilSearchSettings.php';
37include_once './Services/User/classes/class.ilUserAccountSettings.php';
38include_once 'Services/Search/classes/class.ilQueryParser.php';
39include_once("./Services/User/classes/class.ilUserAutoComplete.php");
40
41
43{
44 private $search_results = array();
45
46 protected $add_options = array();
47 protected $object_selection = false;
48
49 protected $searchable_check = true;
50 protected $search_title = '';
51
52 var $search_type = 'usr';
53 protected $user_limitations = true;
54
59
60
65 function __construct()
66 {
67 global $ilCtrl,$tpl,$lng;
68
69 $this->ctrl = $ilCtrl;
70 $this->tpl = $tpl;
71 $this->lng = $lng;
72 $this->lng->loadLanguageModule('search');
73 $this->lng->loadLanguageModule('crs');
74
75 $this->setTitle($this->lng->txt('add_members_header'));
76
77 $this->__setSearchType();
78 $this->__loadQueries();
79
80 $this->result_obj = new ilSearchResult();
81 $this->result_obj->setMaxHits(1000000);
82 $this->settings = new ilSearchSettings();
83
84 }
85
90 public function setTitle($a_title)
91 {
92 $this->search_title = $a_title;
93 }
94
99 public function getTitle()
100 {
101 return $this->search_title;
102 }
103
108 public function enableSearchableCheck($a_status)
109 {
110 $this->searchable_check = $a_status;
111 }
112
117 public function isSearchableCheckEnabled()
118 {
120 }
121
126 {
127 $this->privacy_mode = $privacy_mode;
128 }
129
133 public function getPrivacyMode()
134 {
135 return $this->privacy_mode;
136 }
137
138
152 public static function fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar = null, $a_options = array(), $a_sticky = false)
153 {
154 global $ilToolbar, $lng, $ilCtrl, $tree;
155
156 if(!$toolbar instanceof ilToolbarGUI)
157 {
158 $toolbar = $ilToolbar;
159 }
160
161 // Fill default options
162 if(!isset($a_options['auto_complete_name']))
163 {
164 $a_options['auto_complete_name'] = $lng->txt('obj_user');
165 }
166 if(!isset($a_options['auto_complete_size']))
167 {
168 $a_options['auto_complete_size'] = 15;
169 }
170 if(!isset($a_options['submit_name']))
171 {
172 $a_options['submit_name'] = $lng->txt('btn_add');
173 }
174 if(!isset($a_options['user_type_default']))
175 {
176 $a_options['user_type_default'] = null;
177 }
178
179 $ajax_url = $ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'),
180 'doUserAutoComplete', '', true,false);
181
182 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
183 $ul = new ilTextInputGUI($a_options['auto_complete_name'], 'user_login');
184 $ul->setDataSource($ajax_url);
185 $ul->setSize($a_options['auto_complete_size']);
186 if(!$a_sticky)
187 {
188 $toolbar->addInputItem($ul, true);
189 }
190 else
191 {
192 $toolbar->addStickyItem($ul, true);
193 }
194
195 if(count((array) $a_options['user_type']))
196 {
197 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
198 $si = new ilSelectInputGUI("", "user_type");
199 $si->setOptions($a_options['user_type']);
200 $si->setValue($a_options['user_type_default']);
201 if(!$a_sticky)
202 {
203 $toolbar->addInputItem($si);
204 }
205 else
206 {
207 $toolbar->addStickyItem($si);
208 }
209 }
210
211 include_once './Services/User/classes/class.ilUserClipboard.php';
212 $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
213 if($clip->hasContent())
214 {
215 include_once './Services/UIComponent/SplitButton/classes/class.ilSplitButtonGUI.php';
216 $action_button = ilSplitButtonGUI::getInstance();
217
218 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
219 $add_button = ilSubmitButton::getInstance();
220 $add_button->setCaption($a_options['submit_name'], false);
221 $add_button->setCommand('addUserFromAutoComplete');
222
223 $action_button->setDefaultButton($add_button);
224
225 include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
226 $clip_button = ilSubmitButton::getInstance();
227 $clip_button->addCSSClass('btn btndefault');
228 $GLOBALS['DIC']->language()->loadLanguageModule('user');
229 $clip_button->setCaption($GLOBALS['DIC']->language()->txt('clipboard_add_from_btn'), false);
230 $clip_button->setCommand('showClipboard');
231
232 $action_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($clip_button));
233
234 $toolbar->addButtonInstance($action_button);
235 }
236 else
237 {
238 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
239 $button = ilSubmitButton::getInstance();
240 $button->setCaption($a_options['submit_name'], false);
241 $button->setCommand('addUserFromAutoComplete');
242 if(!$a_sticky)
243 {
244 $toolbar->addButtonInstance($button);
245 }
246 else
247 {
248 $toolbar->addStickyItem($button);
249 }
250 }
251
252 if((bool)$a_options['add_search'] ||
253 is_numeric($a_options['add_from_container']))
254 {
255 $lng->loadLanguageModule("search");
256
257 $toolbar->addSeparator();
258
259 if((bool)$a_options['add_search'])
260 {
261 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
262 $button = ilLinkButton::getInstance();
263 $button->setCaption("search_users");
264 $button->setUrl($ilCtrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
265 $toolbar->addButtonInstance($button);
266 }
267
268 if(is_numeric($a_options['add_from_container']))
269 {
270 $parent_ref_id = (int)$a_options['add_from_container'];
271 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "grp");
272 $parent_container_type = "grp";
273 if(!$parent_container_ref_id)
274 {
275 $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "crs");
276 $parent_container_type = "crs";
277 }
278 if($parent_container_ref_id)
279 {
280 if((bool)$a_options['add_search'])
281 {
282 $toolbar->addSpacer();
283 }
284
285 $ilCtrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", ilObject::_lookupObjId($parent_container_ref_id));
286
287 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
288 $button = ilLinkButton::getInstance();
289 $button->setCaption("search_add_members_from_container_".$parent_container_type);
290 $button->setUrl($ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'), 'listUsers'));
291 $toolbar->addButtonInstance($button);
292 }
293 }
294 }
295
296 $toolbar->setFormAction(
297 $ilCtrl->getFormActionByClass(
298 array(
299 get_class($parent_object),
300 'ilRepositorySearchGUI')
301 )
302 );
303 return $toolbar;
304 }
305
310 protected function doUserAutoComplete()
311 {
312 // hide anonymout request
313 if($GLOBALS['ilUser']->getId() == ANONYMOUS_USER_ID)
314 {
315 include_once './Services/JSON/classes/class.ilJsonUtil.php';
316 return ilJsonUtil::encode(new stdClass());
317 exit;
318 }
319
320
321 if(!isset($_GET['autoCompleteField']))
322 {
323 $a_fields = array('login','firstname','lastname','email');
324 $result_field = 'login';
325 }
326 else
327 {
328 $a_fields = array((string) $_GET['autoCompleteField']);
329 $result_field = (string) $_GET['autoCompleteField'];
330 }
331
332 include_once './Services/User/classes/class.ilUserAutoComplete.php';
333 $auto = new ilUserAutoComplete();
334 $auto->setPrivacyMode($this->getPrivacyMode());
335
336 if(($_REQUEST['fetchall']))
337 {
338 $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
339 }
340
341 $auto->setMoreLinkAvailable(true);
342 $auto->setSearchFields($a_fields);
343 $auto->setResultField($result_field);
344 $auto->enableFieldSearchableCheck(true);
345 $auto->setUserLimitations($this->getUserLimitations());
346
347 echo $auto->getList($_REQUEST['term']);
348 exit();
349 }
350
351
356 function setString($a_str)
357 {
358 $_SESSION['search']['string'] = $this->string = $a_str;
359 }
360 function getString()
361 {
362 return $this->string;
363 }
364
369 function executeCommand()
370 {
371 global $rbacsystem;
372
373 $next_class = $this->ctrl->getNextClass($this);
374 $cmd = $this->ctrl->getCmd();
375
376 $this->ctrl->setReturn($this,'');
377
378 switch($next_class)
379 {
380 default:
381 if(!$cmd)
382 {
383 $cmd = "showSearch";
384 }
385 $this->$cmd();
386 break;
387 }
388 return true;
389 }
390
391 function __clearSession()
392 {
393
394 unset($_SESSION['rep_search']);
395 unset($_SESSION['append_results']);
396 unset($_SESSION['rep_query']);
397 unset($_SESSION['rep_search_type']);
398 }
399
400 function cancel()
401 {
402 $this->ctrl->returnToParent($this);
403 }
404
405 function start()
406 {
407 // delete all session info
408 $this->__clearSession();
409 $this->showSearch();
410
411 return true;
412 }
413
414
415 public function addUser()
416 {
417 $class = $this->callback['class'];
418 $method = $this->callback['method'];
419
420 // call callback if that function does give a return value => show error message
421 // listener redirects if everything is ok.
422 $class->$method($_POST['user']);
423
424 $this->showSearchResults();
425 }
426
430 protected function addUserFromAutoComplete()
431 {
432 $class = $this->callback['class'];
433 $method = $this->callback['method'];
434
435 $users = explode(',', $_POST['user_login']);
436 $user_ids = array();
437 foreach($users as $user)
438 {
439 $user_id = ilObjUser::_lookupId($user);
440 if($user_id)
441 {
442 $user_ids[] = $user_id;
443 }
444 }
445
446 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
447
448 if(!$class->$method($user_ids,$user_type))
449 {
450 $GLOBALS['ilCtrl']->returnToParent($this);
451 }
452 }
453
454 protected function showClipboard()
455 {
456 $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
457
458 ilLoggerFactory::getLogger('crs')->dump($_REQUEST);
459
460 $GLOBALS['ilTabs']->clearTargets();
461 $GLOBALS['ilTabs']->setBackTarget(
462 $GLOBALS['lng']->txt('back'),
463 $GLOBALS['ilCtrl']->getParentReturn($this)
464 );
465
466 include_once './Services/User/classes/class.ilUserClipboardTableGUI.php';
467 $clip = new ilUserClipboardTableGUI($this, 'showClipboard', $GLOBALS['ilUser']->getId());
468 $clip->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
469 $clip->init();
470 $clip->parse();
471
472 $GLOBALS['tpl']->setContent($clip->getHTML());
473 }
474
478 protected function addFromClipboard()
479 {
480 $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
481 $users = (array) $_POST['uids'];
482 if(!count($users))
483 {
484 ilUtil::sendFailure($this->lng->txt('select_one'), true);
485 $GLOBALS['ilCtrl']->redirect($this, 'showClipboard');
486 }
487 $class = $this->callback['class'];
488 $method = $this->callback['method'];
489 $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
490
491 if(!$class->$method($users,$user_type))
492 {
493 $GLOBALS['ilCtrl']->returnToParent($this);
494 }
495 }
496
500 protected function removeFromClipboard()
501 {
502 $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
503 $users = (array) $_POST['uids'];
504 if(!count($users))
505 {
506 ilUtil::sendFailure($this->lng->txt('select_one'), true);
507 $GLOBALS['ilCtrl']->redirect($this, 'showClipboard');
508 }
509
510 include_once './Services/User/classes/class.ilUserClipboard.php';
511 $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
512 $clip->delete($users);
513 $clip->save();
514
515 ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
516 $this->ctrl->redirect($this, 'showClipboard');
517 }
518
522 protected function emptyClipboard()
523 {
524 include_once './Services/User/classes/class.ilUserClipboard.php';
525 $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
526 $clip->clear();
527 $clip->save();
528
529 ilUtil::sendSuccess($this->lng->txt('settings_saved'),true);
530 $this->ctrl->returnToParent($this);
531 }
532
536 protected function handleMultiCommand()
537 {
538 $class = $this->callback['class'];
539 $method = $this->callback['method'];
540
541 // Redirects if everything is ok
542 if(!$class->$method((array) $_POST['user'],$_POST['selectedCommand']))
543 {
544 $this->showSearchResults();
545 }
546 }
547
548 public function setCallback(&$class,$method,$a_add_options = array())
549 {
550 $this->callback = array('class' => $class,'method' => $method);
551 $this->add_options = $a_add_options ? $a_add_options : array();
552 }
553
554 public function showSearch()
555 {
556 $this->initFormSearch();
557 $this->tpl->setContent($this->form->getHTML());
558 }
559
563 public function showSearchSelected()
564 {
565 $selected = (int) $_REQUEST['selected_id'];
566
567 #include_once './Services/Object/classes/class.ilObjectFactory.php';
568 #$factory = new ilObjectFactory();
569 #$user = $factory->getInstanceByObjId($selected);
570
571 #$this->initFormSearch($user);
572 #$this->tpl->setContent($this->form->getHTML());
573
574 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.rep_search_result.html','Services/Search');
575 $this->addNewSearchButton();
576 $this->showSearchUserTable(array($selected),'showSearchResults');
577 }
578
579 public function initFormSearch(ilObjUser $user = NULL)
580 {
581 global $ilCtrl;
582
583 include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
584
585 $this->form = new ilPropertyFormGUI();
586 $this->form->setFormAction($this->ctrl->getFormAction($this,'search'));
587 $this->form->setTitle($this->getTitle());
588 $this->form->addCommandButton('performSearch', $this->lng->txt('search'));
589 $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
590
591
592 $kind = new ilRadioGroupInputGUI($this->lng->txt('search_type'),'search_for');
593 $kind->setValue($this->search_type);
594 $this->form->addItem($kind);
595
596 // Users
597 $users = new ilRadioOption($this->lng->txt('search_for_users'),'usr');
598
599 // UDF
600 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
602 {
603 switch($info['type'])
604 {
607
608 $sel = new ilSelectInputGUI($info['lang'],"rep_query[usr][".$info['db']."]");
609 $sel->setOptions($info['values']);
610 $users->addSubItem($sel);
611 break;
612
613 case FIELD_TYPE_MULTI:
615 case FIELD_TYPE_TEXT:
616
617 if(isset($info['autoComplete']) and $info['autoComplete'])
618 {
619 $ilCtrl->setParameterByClass(get_class($this),'autoCompleteField',$info['db']);
620 $ul = new ilTextInputGUI($info['lang'], "rep_query[usr][".$info['db']."]");
621 $ul->setDataSourceSubmitOnSelection(TRUE);
622 $ul->setDataSourceSubmitUrl(
623 $this->ctrl->getLinkTarget(
624 $this,
625 'showSearchSelected',
626 '',
627 FALSE,
628 FALSE
629 )
630 );
631 $ul->setDataSource($ilCtrl->getLinkTarget($this,
632 "doUserAutoComplete", "", true));
633 $ul->setSize(30);
634 $ul->setMaxLength(120);
635
636 if($user instanceof ilObjUser)
637 {
638 switch($info['db'])
639 {
640 case 'firstname':
641 $ul->setValue($user->getFirstname());
642 break;
643 case 'lastname':
644 $ul->setValue($user->getLastname());
645 break;
646 case 'login':
647 $ul->setValue($user->getLogin());
648 break;
649 }
650 }
651
652
653
654 $users->addSubItem($ul);
655 }
656 else
657 {
658 $txt = new ilTextInputGUI($info['lang'],"rep_query[usr][".$info['db']."]");
659 $txt->setSize(30);
660 $txt->setMaxLength(120);
661 $users->addSubItem($txt);
662 }
663 break;
664 }
665 }
666 $kind->addOption($users);
667
668
669
670 // Role
671 $roles = new ilRadioOption($this->lng->txt('search_for_role_members'),'role');
672 $role = new ilTextInputGUI($this->lng->txt('search_role_title'),'rep_query[role][title]');
673 $role->setSize(30);
674 $role->setMaxLength(120);
675 $roles->addSubItem($role);
676 $kind->addOption($roles);
677
678 // Course
679 $groups = new ilRadioOption($this->lng->txt('search_for_crs_members'),'crs');
680 $group = new ilTextInputGUI($this->lng->txt('search_crs_title'),'rep_query[crs][title]');
681 $group->setSize(30);
682 $group->setMaxLength(120);
683 $groups->addSubItem($group);
684 $kind->addOption($groups);
685
686 // Group
687 $groups = new ilRadioOption($this->lng->txt('search_for_grp_members'),'grp');
688 $group = new ilTextInputGUI($this->lng->txt('search_grp_title'),'rep_query[grp][title]');
689 $group->setSize(30);
690 $group->setMaxLength(120);
691 $groups->addSubItem($group);
692 $kind->addOption($groups);
693 }
694
695
696 function show()
697 {
698 $this->showSearchResults();
699 }
700
701 function appendSearch()
702 {
703 $_SESSION['search_append'] = true;
704 $this->performSearch();
705 }
706
711 function performSearch()
712 {
713 $found_query = false;
714 foreach((array) $_POST['rep_query'][$_POST['search_for']] as $field => $value)
715 {
716 if(trim(ilUtil::stripSlashes($value)))
717 {
718 $found_query = true;
719 break;
720 }
721 }
722 if(!$found_query)
723 {
724 ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
725 $this->start();
726 return false;
727 }
728
729 // unset search_append if called directly
730 if($_POST['cmd']['performSearch'])
731 {
732 unset($_SESSION['search_append']);
733 }
734
735 switch($this->search_type)
736 {
737 case 'usr':
738 $this->__performUserSearch();
739 break;
740
741 case 'grp':
742 $this->__performGroupSearch();
743 break;
744
745 case 'crs':
746 $this->__performCourseSearch();
747 break;
748
749 case 'role':
750 $this->__performRoleSearch();
751 break;
752
753 default:
754 echo 'not defined';
755 }
756
757 $GLOBALS['DIC']->logger()->src()->dump($this->result_obj->getEntries());
758
759 $this->result_obj->setRequiredPermission('read');
760 $this->result_obj->addObserver($this, 'searchResultFilterListener');
761 $this->result_obj->filter(ROOT_FOLDER_ID,QP_COMBINATION_OR);
762
763 // User access filter
764 if($this->search_type == 'usr')
765 {
766 include_once './Services/User/classes/class.ilUserFilter.php';
767 $this->search_results = array_intersect(
768 $this->result_obj->getResultIds(),
769 ilUserFilter::getInstance()->filter($this->result_obj->getResultIds())
770 );
771 }
772 else
773 {
774 $this->search_results = array();
775 foreach((array) $this->result_obj->getResults() as $res)
776 {
777 $this->search_results[] = $res['obj_id'];
778 }
779 }
780
781 if(!count($this->search_results))
782 {
783 ilUtil::sendFailure($this->lng->txt('search_no_match'));
784 $this->showSearch();
785 return true;
786 }
787 $this->__updateResults();
788 if($this->result_obj->isLimitReached())
789 {
790 $message = sprintf($this->lng->txt('search_limit_reached'),$this->settings->getMaxHits());
791 ilUtil::sendInfo($message);
792 return true;
793 }
794 // show results
795 $this->show();
796 return true;
797 }
798
800 {
801 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
802 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
803
805 {
806 $name = $info['db'];
807 $query_string = $_SESSION['rep_query']['usr'][$name];
808
809 // continue if no query string is given
810 if(!$query_string)
811 {
812 continue;
813 }
814
815 if(!is_object($query_parser = $this->__parseQueryString($query_string, true, ($info['type'] == FIELD_TYPE_SELECT))))
816 {
817 ilUtil::sendInfo($query_parser);
818 return false;
819 }
820 switch($info['type'])
821 {
823 // Do a phrase query for select fields
824 $query_parser = $this->__parseQueryString('"'.$query_string.'"');
825
828 $udf_search->setFields(array($name));
829 $result_obj = $udf_search->performSearch();
830
831 // Store entries
832 $this->__storeEntries($result_obj);
833 break;
834
836
837 if($info['db'] == 'org_units')
838 {
840 $result_obj = $user_search->performSearch();
841 $this->__storeEntries($result_obj);
842 break;
843 }
844
845 // Do a phrase query for select fields
846 $query_parser = $this->__parseQueryString('"'.$query_string.'"', true, true);
847
848 case FIELD_TYPE_TEXT:
849 $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser);
850 $user_search->setFields(array($name));
851 $result_obj = $user_search->performSearch();
852
853 // store entries
854 $this->__storeEntries($result_obj);
855 break;
856
857 case FIELD_TYPE_MULTI:
858 $multi_search = ilObjectSearchFactory::getUserMultiFieldSearchInstance($query_parser);
859 $multi_search->setFields(array($name));
860 $result_obj = $multi_search->performSearch();
861 $this->__storeEntries($result_obj);
862 break;
863
864 }
865 }
866 }
867
873 {
874 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
875
876 $query_string = $_SESSION['rep_query']['grp']['title'];
877 if(!is_object($query_parser = $this->__parseQueryString($query_string)))
878 {
879 ilUtil::sendInfo($query_parser,true);
880 return false;
881 }
882
883 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
884 $object_search = new ilLikeObjectSearch($query_parser);
885 $object_search->setFilter(array('grp'));
886 $this->__storeEntries($object_search->performSearch());
887
888 return true;
889 }
890
895 protected function __performCourseSearch()
896 {
897 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
898
899 $query_string = $_SESSION['rep_query']['crs']['title'];
900 if(!is_object($query_parser = $this->__parseQueryString($query_string)))
901 {
902 ilUtil::sendInfo($query_parser,true);
903 return false;
904 }
905
906 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
907 $object_search = new ilLikeObjectSearch($query_parser);
908 $object_search->setFilter(array('crs'));
909 $this->__storeEntries($object_search->performSearch());
910
911 return true;
912 }
913
919 {
920 include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
921
922 $query_string = $_SESSION['rep_query']['role']['title'];
923 if(!is_object($query_parser = $this->__parseQueryString($query_string)))
924 {
925 ilUtil::sendInfo($query_parser,true);
926 return false;
927 }
928
929 // Perform like search
930 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
931 $object_search = new ilLikeObjectSearch($query_parser);
932 $object_search->setFilter(array('role'));
933 $this->__storeEntries($object_search->performSearch());
934
935 return true;
936 }
937
943 function &__parseQueryString($a_string,$a_combination_or = true,$a_ignore_length = false)
944 {
945 $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
946 $query_parser->setCombination($a_combination_or ? QP_COMBINATION_OR : QP_COMBINATION_AND);
947 $query_parser->setMinWordLength(1);
948
949 // #17502
950 if(!(bool)$a_ignore_length)
951 {
952 $query_parser->setGlobalMinLength(3); // #14768
953 }
954
955 $query_parser->parse();
956
957 if(!$query_parser->validate())
958 {
959 return $query_parser->getMessage();
960 }
961 return $query_parser;
962 }
963
964 // Private
965 function __loadQueries()
966 {
967 if(is_array($_POST['rep_query']))
968 {
969 $_SESSION['rep_query'] = $_POST['rep_query'];
970 }
971 }
972
973
975 {
976 // Update search type. Default to user search
977 if($_POST['search_for'])
978 {
979 #echo 1;
980 $_SESSION['rep_search_type'] = $_POST['search_for'];
981 }
982 if(!$_POST['search_for'] and !$_SESSION['rep_search_type'])
983 {
984 #echo 2;
985 $_SESSION['rep_search_type'] = 'usr';
986 }
987
988 $this->search_type = $_SESSION['rep_search_type'];
989 #echo $this->search_type;
990
991 return true;
992 }
993
994
996 {
997 if(!$_SESSION['search_append'])
998 {
999 $_SESSION['rep_search'] = array();
1000 }
1001 foreach($this->search_results as $result)
1002 {
1003 $_SESSION['rep_search'][$this->search_type][] = $result;
1004 }
1005 if(!$_SESSION['rep_search'][$this->search_type])
1006 {
1007 $_SESSION['rep_search'][$this->search_type] = array();
1008 }
1009 else
1010 {
1011 // remove duplicate entries
1012 $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
1013 }
1014 return true;
1015 }
1016
1017 function __appendToStoredResults($a_usr_ids)
1018 {
1019 if(!$_SESSION['search_append'])
1020 {
1021 return $_SESSION['rep_search']['usr'] = $a_usr_ids;
1022 }
1023 $_SESSION['rep_search']['usr'] = array();
1024 foreach($a_usr_ids as $usr_id)
1025 {
1026 $_SESSION['rep_search']['usr'][] = $usr_id;
1027 }
1028 return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
1029 }
1030
1031 function __storeEntries(&$new_res)
1032 {
1033 if($this->stored == false)
1034 {
1035 $this->result_obj->mergeEntries($new_res);
1036 $this->stored = true;
1037 return true;
1038 }
1039 else
1040 {
1041 $this->result_obj->intersectEntries($new_res);
1042 return true;
1043 }
1044 }
1045
1050 protected function addNewSearchButton()
1051 {
1052 include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1053 $toolbar = new ilToolbarGUI();
1054 $toolbar->addButton(
1055 $this->lng->txt('search_new'),
1056 $this->ctrl->getLinkTarget($this,'showSearch')
1057 );
1058 $this->tpl->setVariable('ACTION_BUTTONS',$toolbar->getHTML());
1059 }
1060
1061 public function showSearchResults()
1062 {
1063 $counter = 0;
1064 $f_result = array();
1065
1066 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.rep_search_result.html','Services/Search');
1067 $this->addNewSearchButton();
1068
1069 switch($this->search_type)
1070 {
1071 case "usr":
1072 $this->showSearchUserTable($_SESSION['rep_search']['usr'],'showSearchResults');
1073 break;
1074
1075 case 'grp':
1076 $this->showSearchGroupTable($_SESSION['rep_search']['grp']);
1077 break;
1078
1079 case 'crs':
1080 $this->showSearchCourseTable($_SESSION['rep_search']['crs']);
1081 break;
1082
1083 case 'role':
1084 $this->showSearchRoleTable($_SESSION['rep_search']['role']);
1085 break;
1086 }
1087 }
1088
1094 protected function showSearchUserTable($a_usr_ids,$a_parent_cmd)
1095 {
1096 $is_in_admin = ($_REQUEST['baseClass'] == 'ilAdministrationGUI');
1097 if($is_in_admin)
1098 {
1099 // remember link target to admin search gui (this)
1100 $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this,'show');
1101 }
1102
1103 include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
1104
1105 $table = new ilRepositoryUserResultTableGUI($this,$a_parent_cmd,$is_in_admin);
1106 if(count($this->add_options))
1107 {
1108 $table->addMultiItemSelectionButton(
1109 'selectedCommand',
1110 $this->add_options,
1111 'handleMultiCommand',
1112 $this->lng->txt('execute')
1113 );
1114 }
1115 else
1116 {
1117 $table->addMultiCommand('addUser', $this->lng->txt('btn_add'));
1118 }
1119 $table->setUserLimitations($this->getUserLimitations());
1120 $table->parseUserIds($a_usr_ids);
1121
1122 $this->tpl->setVariable('RES_TABLE',$table->getHTML());
1123 }
1124
1130 protected function showSearchRoleTable($a_obj_ids)
1131 {
1132 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1133
1134 $table = new ilRepositoryObjectResultTableGUI($this,'showSearchResults',$this->object_selection);
1135 $table->parseObjectIds($a_obj_ids);
1136
1137 $this->tpl->setVariable('RES_TABLE',$table->getHTML());
1138 }
1139
1145 protected function showSearchGroupTable($a_obj_ids)
1146 {
1147 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1148
1149 $table = new ilRepositoryObjectResultTableGUI($this,'showSearchResults',$this->object_selection);
1150 $table->parseObjectIds($a_obj_ids);
1151
1152 $this->tpl->setVariable('RES_TABLE',$table->getHTML());
1153 }
1154
1160 protected function showSearchCourseTable($a_obj_ids)
1161 {
1162 include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1163
1164 $table = new ilRepositoryObjectResultTableGUI($this,'showSearchResults',$this->object_selection);
1165 $table->parseObjectIds($a_obj_ids);
1166
1167 $this->tpl->setVariable('RES_TABLE',$table->getHTML());
1168 }
1169
1174 protected function listUsers()
1175 {
1176 // get parameter is used e.g. in exercises to provide
1177 // "add members of course" link
1178 if ($_GET["list_obj"] != "" && !is_array($_POST['obj']))
1179 {
1180 $_POST['obj'][0] = $_GET["list_obj"];
1181 }
1182 if(!is_array($_POST['obj']) or !$_POST['obj'])
1183 {
1184 ilUtil::sendFailure($this->lng->txt('select_one'));
1185 $this->showSearchResults();
1186 return false;
1187 }
1188
1189 $_SESSION['rep_search']['objs'] = $_POST['obj'];
1190
1191 // Get all members
1192 $members = array();
1193 foreach($_POST['obj'] as $obj_id)
1194 {
1195 $type = ilObject::_lookupType($obj_id);
1196 switch($type)
1197 {
1198 case 'crs':
1199 case 'grp':
1200
1201 include_once './Services/Membership/classes/class.ilParticipants.php';
1203 {
1204 $members = array_merge((array) $members, ilParticipants::getInstanceByObjId($obj_id)->getParticipants());
1205 }
1206 break;
1207
1208 case 'role':
1209 global $rbacreview;
1210
1211 include_once './Services/User/classes/class.ilUserFilter.php';
1212 $members = array_merge($members, ilUserFilter::getInstance()->filter($rbacreview->assignedUsers($obj_id)));
1213 break;
1214 }
1215 }
1216 $members = array_unique((array) $members);
1217 $this->__appendToStoredResults($members);
1218
1219 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.rep_search_result.html','Services/Search');
1220
1221 $this->addNewSearchButton();
1222 $this->showSearchUserTable($_SESSION['rep_search']['usr'],'storedUserList');
1223 return true;
1224 }
1225
1230 protected function storedUserList()
1231 {
1232 $_POST['obj'] = $_SESSION['rep_search']['objs'];
1233 $this->listUsers();
1234 return true;
1235 }
1236
1245 public function searchResultFilterListener($a_ref_id,$a_data)
1246 {
1247 if($a_data['type'] == 'usr')
1248 {
1249 if($a_data['obj_id'] == ANONYMOUS_USER_ID)
1250 {
1251 return false;
1252 }
1253 }
1254 return true;
1255 }
1256
1262 public function allowObjectSelection($a_value = false)
1263 {
1264 $this->object_selection = (bool)$a_value;
1265 }
1266
1270 protected function selectObject()
1271 {
1272 // get parameter is used e.g. in exercises to provide
1273 // "add members of course" link
1274 if ($_GET["list_obj"] != "" && !is_array($_POST['obj']))
1275 {
1276 $_POST['obj'][0] = $_GET["list_obj"];
1277 }
1278 if(!is_array($_POST['obj']) or !$_POST['obj'])
1279 {
1280 ilUtil::sendFailure($this->lng->txt('select_one'));
1281 $this->showSearchResults();
1282 return false;
1283 }
1284
1285 $this->ctrl->setParameter($this->callback["class"], "obj", implode(";", $_POST["obj"]));
1286 $this->ctrl->redirect($this->callback["class"], $this->callback["method"]);
1287 }
1288
1294 public function setUserLimitations($a_limitations)
1295 {
1296 $this->user_limitations = (bool) $a_limitations;
1297 }
1298
1303 public function getUserLimitations()
1304 {
1306 }
1307}
1308?>
sprintf('%.4f', $callTime)
$result
global $tpl
Definition: ilias.php:8
$_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 _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 _lookupType($a_id, $a_reference=false)
lookup object type
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.
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
initFormSearch(ilObjUser $user=NULL)
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.
searchResultFilterListener($a_ref_id, $a_data)
Listener called from ilSearchResult Id is obj_id for role, usr Id is ref_id for crs grp.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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.
$counter
$txt
Definition: error.php:12
$info
Definition: example_052.php:80
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
settings()
Definition: settings.php:2