ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
35 include_once 'Services/Search/classes/class.ilSearchResult.php';
36 include_once 'Services/Search/classes/class.ilSearchSettings.php';
37 include_once './Services/User/classes/class.ilUserAccountSettings.php';
38 include_once 'Services/Search/classes/class.ilQueryParser.php';
39 include_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  public $search_type = 'usr';
53  protected $user_limitations = true;
54 
58  protected $user_filter = null;
59 
64 
65 
70  public function __construct()
71  {
72  global $ilCtrl,$tpl,$lng;
73 
74  $this->ctrl = $ilCtrl;
75  $this->tpl = $tpl;
76  $this->lng = $lng;
77  $this->lng->loadLanguageModule('search');
78  $this->lng->loadLanguageModule('crs');
79 
80  $this->setTitle($this->lng->txt('add_members_header'));
81 
82  $this->__setSearchType();
83  $this->__loadQueries();
84 
85  $this->result_obj = new ilSearchResult();
86  $this->result_obj->setMaxHits(1000000);
87  $this->settings = new ilSearchSettings();
88  }
89 
99  public function addUserAccessFilterCallable(callable $user_filter)
100  {
101  $this->user_filter = $user_filter;
102  }
103 
108  public function setTitle($a_title)
109  {
110  $this->search_title = $a_title;
111  }
112 
117  public function getTitle()
118  {
119  return $this->search_title;
120  }
121 
126  public function enableSearchableCheck($a_status)
127  {
128  $this->searchable_check = $a_status;
129  }
130 
135  public function isSearchableCheckEnabled()
136  {
138  }
139 
143  public function setPrivacyMode($privacy_mode)
144  {
145  $this->privacy_mode = $privacy_mode;
146  }
147 
151  public function getPrivacyMode()
152  {
153  return $this->privacy_mode;
154  }
155 
156 
170  public static function fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar = null, $a_options = array(), $a_sticky = false)
171  {
172  global $ilToolbar, $lng, $ilCtrl, $tree;
173 
174  if (!$toolbar instanceof ilToolbarGUI) {
175  $toolbar = $ilToolbar;
176  }
177 
178  // Fill default options
179  if (!isset($a_options['auto_complete_name'])) {
180  $a_options['auto_complete_name'] = $lng->txt('obj_user');
181  }
182  if (!isset($a_options['auto_complete_size'])) {
183  $a_options['auto_complete_size'] = 15;
184  }
185  if (!isset($a_options['submit_name'])) {
186  $a_options['submit_name'] = $lng->txt('btn_add');
187  }
188  if (!isset($a_options['user_type_default'])) {
189  $a_options['user_type_default'] = null;
190  }
191 
192  $ajax_url = $ilCtrl->getLinkTargetByClass(
193  array(get_class($parent_object),'ilRepositorySearchGUI'),
194  'doUserAutoComplete',
195  '',
196  true,
197  false
198  );
199 
200  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
201  $ul = new ilTextInputGUI($a_options['auto_complete_name'], 'user_login');
202  $ul->setDataSource($ajax_url);
203  $ul->setSize($a_options['auto_complete_size']);
204  if (!$a_sticky) {
205  $toolbar->addInputItem($ul, true);
206  } else {
207  $toolbar->addStickyItem($ul, true);
208  }
209 
210  if (count((array) $a_options['user_type'])) {
211  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
212  $si = new ilSelectInputGUI("", "user_type");
213  $si->setOptions($a_options['user_type']);
214  $si->setValue($a_options['user_type_default']);
215  if (!$a_sticky) {
216  $toolbar->addInputItem($si);
217  } else {
218  $toolbar->addStickyItem($si);
219  }
220  }
221 
222  include_once './Services/User/classes/class.ilUserClipboard.php';
223  $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
224  if ($clip->hasContent()) {
225  include_once './Services/UIComponent/SplitButton/classes/class.ilSplitButtonGUI.php';
226  $action_button = ilSplitButtonGUI::getInstance();
227 
228  include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
229  $add_button = ilSubmitButton::getInstance();
230  $add_button->setCaption($a_options['submit_name'], false);
231  $add_button->setCommand('addUserFromAutoComplete');
232 
233  $action_button->setDefaultButton($add_button);
234 
235  include_once './Services/UIComponent/Button/classes/class.ilLinkButton.php';
236  $clip_button = ilSubmitButton::getInstance();
237  $clip_button->addCSSClass('btn btndefault');
238  $GLOBALS['DIC']->language()->loadLanguageModule('user');
239  $clip_button->setCaption($GLOBALS['DIC']->language()->txt('clipboard_add_from_btn'), false);
240  $clip_button->setCommand('showClipboard');
241 
242  $action_button->addMenuItem(new ilButtonToSplitButtonMenuItemAdapter($clip_button));
243 
244  $toolbar->addButtonInstance($action_button);
245  } else {
246  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
247  $button = ilSubmitButton::getInstance();
248  $button->setCaption($a_options['submit_name'], false);
249  $button->setCommand('addUserFromAutoComplete');
250  if (!$a_sticky) {
251  $toolbar->addButtonInstance($button);
252  } else {
253  $toolbar->addStickyItem($button);
254  }
255  }
256 
257  if ((bool) $a_options['add_search'] ||
258  is_numeric($a_options['add_from_container'])) {
259  $lng->loadLanguageModule("search");
260 
261  $toolbar->addSeparator();
262 
263  if ((bool) $a_options['add_search']) {
264  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
265  $button = ilLinkButton::getInstance();
266  $button->setCaption("search_users");
267  $button->setUrl($ilCtrl->getLinkTargetByClass('ilRepositorySearchGUI', ''));
268  $toolbar->addButtonInstance($button);
269  }
270 
271  if (is_numeric($a_options['add_from_container'])) {
272  $parent_ref_id = (int) $a_options['add_from_container'];
273  $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "grp");
274  $parent_container_type = "grp";
275  if (!$parent_container_ref_id) {
276  $parent_container_ref_id = $tree->checkForParentType($parent_ref_id, "crs");
277  $parent_container_type = "crs";
278  }
279  if ($parent_container_ref_id) {
280  if ((bool) $a_options['add_search']) {
281  $toolbar->addSpacer();
282  }
283 
284  $ilCtrl->setParameterByClass('ilRepositorySearchGUI', "list_obj", ilObject::_lookupObjId($parent_container_ref_id));
285 
286  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
287  $button = ilLinkButton::getInstance();
288  $button->setCaption("search_add_members_from_container_" . $parent_container_type);
289  $button->setUrl($ilCtrl->getLinkTargetByClass(array(get_class($parent_object),'ilRepositorySearchGUI'), 'listUsers'));
290  $toolbar->addButtonInstance($button);
291  }
292  }
293  }
294 
295  $toolbar->setFormAction(
296  $ilCtrl->getFormActionByClass(
297  array(
298  get_class($parent_object),
299  'ilRepositorySearchGUI')
300  )
301  );
302  return $toolbar;
303  }
304 
309  protected function doUserAutoComplete()
310  {
311  // hide anonymout request
312  if ($GLOBALS['ilUser']->getId() == ANONYMOUS_USER_ID) {
313  include_once './Services/JSON/classes/class.ilJsonUtil.php';
314  return ilJsonUtil::encode(new stdClass());
315  exit;
316  }
317 
318 
319  if (!isset($_GET['autoCompleteField'])) {
320  $a_fields = array('login','firstname','lastname','email');
321  $result_field = 'login';
322  } else {
323  $a_fields = array((string) $_GET['autoCompleteField']);
324  $result_field = (string) $_GET['autoCompleteField'];
325  }
326 
327  include_once './Services/User/classes/class.ilUserAutoComplete.php';
328  $auto = new ilUserAutoComplete();
329  $auto->setPrivacyMode($this->getPrivacyMode());
330 
331  if (($_REQUEST['fetchall'])) {
332  $auto->setLimit(ilUserAutoComplete::MAX_ENTRIES);
333  }
334 
335  $auto->setMoreLinkAvailable(true);
336  $auto->setSearchFields($a_fields);
337  $auto->setResultField($result_field);
338  $auto->enableFieldSearchableCheck(true);
339  $auto->setUserLimitations($this->getUserLimitations());
340 
341  echo $auto->getList($_REQUEST['term']);
342  exit();
343  }
344 
345 
350  public function setString($a_str)
351  {
352  $_SESSION['search']['string'] = $this->string = $a_str;
353  }
354  public function getString()
355  {
356  return $this->string;
357  }
358 
363  public function executeCommand()
364  {
365  global $rbacsystem;
366 
367  $next_class = $this->ctrl->getNextClass($this);
368  $cmd = $this->ctrl->getCmd();
369 
370  $this->ctrl->setReturn($this, '');
371 
372  switch ($next_class) {
373  default:
374  if (!$cmd) {
375  $cmd = "showSearch";
376  }
377  $this->$cmd();
378  break;
379  }
380  return true;
381  }
382 
383  public function __clearSession()
384  {
385  unset($_SESSION['rep_search']);
386  unset($_SESSION['append_results']);
387  unset($_SESSION['rep_query']);
388  unset($_SESSION['rep_search_type']);
389  }
390 
391  public function cancel()
392  {
393  $this->ctrl->returnToParent($this);
394  }
395 
396  public function start()
397  {
398  // delete all session info
399  $this->__clearSession();
400  $this->showSearch();
401 
402  return true;
403  }
404 
405 
406  public function addUser()
407  {
408  $class = $this->callback['class'];
409  $method = $this->callback['method'];
410 
411  // call callback if that function does give a return value => show error message
412  // listener redirects if everything is ok.
413  $class->$method((array) $_POST['user']);
414 
415  $this->showSearchResults();
416  }
417 
421  protected function addUserFromAutoComplete()
422  {
423  $class = $this->callback['class'];
424  $method = $this->callback['method'];
425 
426  $users = explode(',', $_POST['user_login']);
427  $user_ids = array();
428  foreach ($users as $user) {
429  $user_id = ilObjUser::_lookupId($user);
430  if ($user_id) {
431  $user_ids[] = $user_id;
432  }
433  }
434 
435  $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
436 
437  if (!$class->$method($user_ids, $user_type)) {
438  $GLOBALS['ilCtrl']->returnToParent($this);
439  }
440  }
441 
442  protected function showClipboard()
443  {
444  $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
445 
446  ilLoggerFactory::getLogger('crs')->dump($_REQUEST);
447 
448  $GLOBALS['ilTabs']->clearTargets();
449  $GLOBALS['ilTabs']->setBackTarget(
450  $GLOBALS['lng']->txt('back'),
451  $GLOBALS['ilCtrl']->getParentReturn($this)
452  );
453 
454  include_once './Services/User/classes/class.ilUserClipboardTableGUI.php';
455  $clip = new ilUserClipboardTableGUI($this, 'showClipboard', $GLOBALS['ilUser']->getId());
456  $clip->setFormAction($GLOBALS['ilCtrl']->getFormAction($this));
457  $clip->init();
458  $clip->parse();
459 
460  $GLOBALS['tpl']->setContent($clip->getHTML());
461  }
462 
466  protected function addFromClipboard()
467  {
468  $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
469  $users = (array) $_POST['uids'];
470  if (!count($users)) {
471  ilUtil::sendFailure($this->lng->txt('select_one'), true);
472  $GLOBALS['ilCtrl']->redirect($this, 'showClipboard');
473  }
474  $class = $this->callback['class'];
475  $method = $this->callback['method'];
476  $user_type = isset($_REQUEST['user_type']) ? $_REQUEST['user_type'] : 0;
477 
478  if (!$class->$method($users, $user_type)) {
479  $GLOBALS['ilCtrl']->returnToParent($this);
480  }
481  }
482 
486  protected function removeFromClipboard()
487  {
488  $GLOBALS['ilCtrl']->setParameter($this, 'user_type', (int) $_REQUEST['user_type']);
489  $users = (array) $_POST['uids'];
490  if (!count($users)) {
491  ilUtil::sendFailure($this->lng->txt('select_one'), true);
492  $GLOBALS['ilCtrl']->redirect($this, 'showClipboard');
493  }
494 
495  include_once './Services/User/classes/class.ilUserClipboard.php';
496  $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
497  $clip->delete($users);
498  $clip->save();
499 
500  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
501  $this->ctrl->redirect($this, 'showClipboard');
502  }
503 
507  protected function emptyClipboard()
508  {
509  include_once './Services/User/classes/class.ilUserClipboard.php';
510  $clip = ilUserClipboard::getInstance($GLOBALS['ilUser']->getId());
511  $clip->clear();
512  $clip->save();
513 
514  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
515  $this->ctrl->returnToParent($this);
516  }
517 
521  protected function handleMultiCommand()
522  {
523  $class = $this->callback['class'];
524  $method = $this->callback['method'];
525 
526  // Redirects if everything is ok
527  if (!$class->$method((array) $_POST['user'], $_POST['selectedCommand'])) {
528  $this->showSearchResults();
529  }
530  }
531 
532  public function setCallback(&$class, $method, $a_add_options = array())
533  {
534  $this->callback = array('class' => $class,'method' => $method);
535  $this->add_options = $a_add_options ? $a_add_options : array();
536  }
537 
541  public function setPermissionQueryCallback($class, $method)
542  {
543  }
544 
545  public function showSearch()
546  {
547  // only autocomplete input field, no search form if user privay should be respected
548  // see bug 25481
550  return;
551  }
552  $this->initFormSearch();
553  $this->tpl->setContent($this->form->getHTML());
554  }
555 
559  public function showSearchSelected()
560  {
561  $selected = (int) $_REQUEST['selected_id'];
562 
563  #include_once './Services/Object/classes/class.ilObjectFactory.php';
564  #$factory = new ilObjectFactory();
565  #$user = $factory->getInstanceByObjId($selected);
566 
567  #$this->initFormSearch($user);
568  #$this->tpl->setContent($this->form->getHTML());
569 
570  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
571  $this->addNewSearchButton();
572  $this->showSearchUserTable(array($selected), 'showSearchResults');
573  }
574 
575  public function initFormSearch(ilObjUser $user = null)
576  {
577  global $ilCtrl;
578 
579  include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
580 
581  $this->form = new ilPropertyFormGUI();
582  $this->form->setFormAction($this->ctrl->getFormAction($this, 'search'));
583  $this->form->setTitle($this->getTitle());
584  $this->form->addCommandButton('performSearch', $this->lng->txt('search'));
585  $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
586 
587 
588  $kind = new ilRadioGroupInputGUI($this->lng->txt('search_type'), 'search_for');
589  $kind->setValue($this->search_type);
590  $this->form->addItem($kind);
591 
592  // Users
593  $users = new ilRadioOption($this->lng->txt('search_for_users'), 'usr');
594 
595  // UDF
596  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
598  switch ($info['type']) {
600  case FIELD_TYPE_SELECT:
601 
602  $sel = new ilSelectInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
603  $sel->setOptions($info['values']);
604  $users->addSubItem($sel);
605  break;
606 
607  case FIELD_TYPE_MULTI:
608  case FIELD_TYPE_UDF_TEXT:
609  case FIELD_TYPE_TEXT:
610 
611  if (isset($info['autoComplete']) and $info['autoComplete']) {
612  $ilCtrl->setParameterByClass(get_class($this), 'autoCompleteField', $info['db']);
613  $ul = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
614  $ul->setDataSourceSubmitOnSelection(true);
615  $ul->setDataSourceSubmitUrl(
616  $this->ctrl->getLinkTarget(
617  $this,
618  'showSearchSelected',
619  '',
620  false,
621  false
622  )
623  );
624  $ul->setDataSource($ilCtrl->getLinkTarget(
625  $this,
626  "doUserAutoComplete",
627  "",
628  true
629  ));
630  $ul->setSize(30);
631  $ul->setMaxLength(120);
632 
633  if ($user instanceof ilObjUser) {
634  switch ($info['db']) {
635  case 'firstname':
636  $ul->setValue($user->getFirstname());
637  break;
638  case 'lastname':
639  $ul->setValue($user->getLastname());
640  break;
641  case 'login':
642  $ul->setValue($user->getLogin());
643  break;
644  }
645  }
646 
647 
648 
649  $users->addSubItem($ul);
650  } else {
651  $txt = new ilTextInputGUI($info['lang'], "rep_query[usr][" . $info['db'] . "]");
652  $txt->setSize(30);
653  $txt->setMaxLength(120);
654  $users->addSubItem($txt);
655  }
656  break;
657  }
658  }
659  $kind->addOption($users);
660 
661 
662 
663  // Role
664  $roles = new ilRadioOption($this->lng->txt('search_for_role_members'), 'role');
665  $role = new ilTextInputGUI($this->lng->txt('search_role_title'), 'rep_query[role][title]');
666  $role->setSize(30);
667  $role->setMaxLength(120);
668  $roles->addSubItem($role);
669  $kind->addOption($roles);
670 
671  // Course
672  $groups = new ilRadioOption($this->lng->txt('search_for_crs_members'), 'crs');
673  $group = new ilTextInputGUI($this->lng->txt('search_crs_title'), 'rep_query[crs][title]');
674  $group->setSize(30);
675  $group->setMaxLength(120);
676  $groups->addSubItem($group);
677  $kind->addOption($groups);
678 
679  // Group
680  $groups = new ilRadioOption($this->lng->txt('search_for_grp_members'), 'grp');
681  $group = new ilTextInputGUI($this->lng->txt('search_grp_title'), 'rep_query[grp][title]');
682  $group->setSize(30);
683  $group->setMaxLength(120);
684  $groups->addSubItem($group);
685  $kind->addOption($groups);
686  }
687 
688 
689  public function show()
690  {
691  $this->showSearchResults();
692  }
693 
694  public function appendSearch()
695  {
696  $_SESSION['search_append'] = true;
697  $this->performSearch();
698  }
699 
704  public function performSearch()
705  {
706  // only autocomplete input field, no search form if user privay should be respected
707  // see bug 25481
709  return "";
710  }
711  $found_query = false;
712  foreach ((array) $_POST['rep_query'][$_POST['search_for']] as $field => $value) {
713  if (trim(ilUtil::stripSlashes($value))) {
714  $found_query = true;
715  break;
716  }
717  }
718  if (!$found_query) {
719  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
720  $this->start();
721  return false;
722  }
723 
724  // unset search_append if called directly
725  if ($_POST['cmd']['performSearch']) {
726  unset($_SESSION['search_append']);
727  }
728 
729  switch ($this->search_type) {
730  case 'usr':
731  $this->__performUserSearch();
732  break;
733 
734  case 'grp':
735  $this->__performGroupSearch();
736  break;
737 
738  case 'crs':
739  $this->__performCourseSearch();
740  break;
741 
742  case 'role':
743  $this->__performRoleSearch();
744  break;
745 
746  default:
747  echo 'not defined';
748  }
749 
750  $this->result_obj->setRequiredPermission('read');
751  $this->result_obj->addObserver($this, 'searchResultFilterListener');
752  $this->result_obj->filter(ROOT_FOLDER_ID, QP_COMBINATION_OR);
753 
754  // User access filter
755  if ($this->search_type == 'usr') {
756  $callable_name = '';
757  if (is_callable($this->user_filter, true, $callable_name)) {
758  $result_ids = call_user_func_array($this->user_filter, [$this->result_obj->getResultIds()]);
759  } else {
760  $result_ids = $this->result_obj->getResultIds();
761  }
762 
763  include_once './Services/User/classes/class.ilUserFilter.php';
764  $this->search_results = array_intersect(
765  $result_ids,
766  ilUserFilter::getInstance()->filter($result_ids)
767  );
768  } else {
769  $this->search_results = array();
770  foreach ((array) $this->result_obj->getResults() as $res) {
771  $this->search_results[] = $res['obj_id'];
772  }
773  }
774 
775  if (!count($this->search_results)) {
776  ilUtil::sendFailure($this->lng->txt('search_no_match'));
777  $this->showSearch();
778  return true;
779  }
780  $this->__updateResults();
781  if ($this->result_obj->isLimitReached()) {
782  $message = sprintf($this->lng->txt('search_limit_reached'), $this->settings->getMaxHits());
784  return true;
785  }
786  // show results
787  $this->show();
788  return true;
789  }
790 
791  public function __performUserSearch()
792  {
793  include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
794  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
795 
797  $name = $info['db'];
798  $query_string = $_SESSION['rep_query']['usr'][$name];
799 
800  // continue if no query string is given
801  if (!$query_string) {
802  continue;
803  }
804 
805  if (!is_object($query_parser = $this->__parseQueryString($query_string, true, ($info['type'] == FIELD_TYPE_SELECT)))) {
806  ilUtil::sendInfo($query_parser);
807  return false;
808  }
809  switch ($info['type']) {
811  // Do a phrase query for select fields
812  $query_parser = $this->__parseQueryString('"' . $query_string . '"');
813 
814  // no break
815  case FIELD_TYPE_UDF_TEXT:
817  $udf_search->setFields(array($name));
818  $result_obj = $udf_search->performSearch();
819 
820  // Store entries
821  $this->__storeEntries($result_obj);
822  break;
823 
824  case FIELD_TYPE_SELECT:
825 
826  if ($info['db'] == 'org_units') {
827  $user_search = ilObjectSearchFactory::getUserOrgUnitAssignmentInstance($query_parser);
828  $result_obj = $user_search->performSearch();
829  $this->__storeEntries($result_obj);
830  break;
831  }
832 
833  // Do a phrase query for select fields
834  $query_parser = $this->__parseQueryString('"' . $query_string . '"', true, true);
835 
836  // no break
837  case FIELD_TYPE_TEXT:
838  $user_search =&ilObjectSearchFactory::_getUserSearchInstance($query_parser);
839  $user_search->setFields(array($name));
840  $result_obj = $user_search->performSearch();
841 
842  // store entries
843  $this->__storeEntries($result_obj);
844  break;
845 
846  case FIELD_TYPE_MULTI:
847  $multi_search = ilObjectSearchFactory::getUserMultiFieldSearchInstance($query_parser);
848  $multi_search->setFields(array($name));
849  $result_obj = $multi_search->performSearch();
850  $this->__storeEntries($result_obj);
851  break;
852 
853  }
854  }
855  }
856 
861  public function __performGroupSearch()
862  {
863  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
864 
865  $query_string = $_SESSION['rep_query']['grp']['title'];
866  if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
867  ilUtil::sendInfo($query_parser, true);
868  return false;
869  }
870 
871  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
872  $object_search = new ilLikeObjectSearch($query_parser);
873  $object_search->setFilter(array('grp'));
874  $this->__storeEntries($object_search->performSearch());
875 
876  return true;
877  }
878 
883  protected function __performCourseSearch()
884  {
885  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
886 
887  $query_string = $_SESSION['rep_query']['crs']['title'];
888  if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
889  ilUtil::sendInfo($query_parser, true);
890  return false;
891  }
892 
893  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
894  $object_search = new ilLikeObjectSearch($query_parser);
895  $object_search->setFilter(array('crs'));
896  $this->__storeEntries($object_search->performSearch());
897 
898  return true;
899  }
900 
905  public function __performRoleSearch()
906  {
907  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
908 
909  $query_string = $_SESSION['rep_query']['role']['title'];
910  if (!is_object($query_parser = $this->__parseQueryString($query_string))) {
911  ilUtil::sendInfo($query_parser, true);
912  return false;
913  }
914 
915  // Perform like search
916  include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
917  $object_search = new ilLikeObjectSearch($query_parser);
918  $object_search->setFilter(array('role'));
919  $this->__storeEntries($object_search->performSearch());
920 
921  return true;
922  }
923 
929  public function &__parseQueryString($a_string, $a_combination_or = true, $a_ignore_length = false)
930  {
931  $query_parser = new ilQueryParser(ilUtil::stripSlashes($a_string));
932  $query_parser->setCombination($a_combination_or ? QP_COMBINATION_OR : QP_COMBINATION_AND);
933  $query_parser->setMinWordLength(1);
934 
935  // #17502
936  if (!(bool) $a_ignore_length) {
937  $query_parser->setGlobalMinLength(3); // #14768
938  }
939 
940  $query_parser->parse();
941 
942  if (!$query_parser->validate()) {
943  return $query_parser->getMessage();
944  }
945  return $query_parser;
946  }
947 
948  // Private
949  public function __loadQueries()
950  {
951  if (is_array($_POST['rep_query'])) {
952  $_SESSION['rep_query'] = $_POST['rep_query'];
953  }
954  }
955 
956 
957  public function __setSearchType()
958  {
959  // Update search type. Default to user search
960  if ($_POST['search_for']) {
961  #echo 1;
962  $_SESSION['rep_search_type'] = $_POST['search_for'];
963  }
964  if (!$_POST['search_for'] and !$_SESSION['rep_search_type']) {
965  #echo 2;
966  $_SESSION['rep_search_type'] = 'usr';
967  }
968 
969  $this->search_type = $_SESSION['rep_search_type'];
970  #echo $this->search_type;
971 
972  return true;
973  }
974 
975 
976  public function __updateResults()
977  {
978  if (!$_SESSION['search_append']) {
979  $_SESSION['rep_search'] = array();
980  }
981  foreach ($this->search_results as $result) {
982  $_SESSION['rep_search'][$this->search_type][] = $result;
983  }
984  if (!$_SESSION['rep_search'][$this->search_type]) {
985  $_SESSION['rep_search'][$this->search_type] = array();
986  } else {
987  // remove duplicate entries
988  $_SESSION['rep_search'][$this->search_type] = array_unique($_SESSION['rep_search'][$this->search_type]);
989  }
990  return true;
991  }
992 
993  public function __appendToStoredResults($a_usr_ids)
994  {
995  if (!$_SESSION['search_append']) {
996  return $_SESSION['rep_search']['usr'] = $a_usr_ids;
997  }
998  $_SESSION['rep_search']['usr'] = array();
999  foreach ($a_usr_ids as $usr_id) {
1000  $_SESSION['rep_search']['usr'][] = $usr_id;
1001  }
1002  return $_SESSION['rep_search']['usr'] ? array_unique($_SESSION['rep_search']['usr']) : array();
1003  }
1004 
1005  public function __storeEntries(&$new_res)
1006  {
1007  if ($this->stored == false) {
1008  $this->result_obj->mergeEntries($new_res);
1009  $this->stored = true;
1010  return true;
1011  } else {
1012  $this->result_obj->intersectEntries($new_res);
1013  return true;
1014  }
1015  }
1016 
1021  protected function addNewSearchButton()
1022  {
1023  include_once './Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
1024  $toolbar = new ilToolbarGUI();
1025  $toolbar->addButton(
1026  $this->lng->txt('search_new'),
1027  $this->ctrl->getLinkTarget($this, 'showSearch')
1028  );
1029  $this->tpl->setVariable('ACTION_BUTTONS', $toolbar->getHTML());
1030  }
1031 
1032  public function showSearchResults()
1033  {
1034  $counter = 0;
1035  $f_result = array();
1036 
1037  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1038  $this->addNewSearchButton();
1039 
1040  switch ($this->search_type) {
1041  case "usr":
1042  $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'showSearchResults');
1043  break;
1044 
1045  case 'grp':
1046  $this->showSearchGroupTable($_SESSION['rep_search']['grp']);
1047  break;
1048 
1049  case 'crs':
1050  $this->showSearchCourseTable($_SESSION['rep_search']['crs']);
1051  break;
1052 
1053  case 'role':
1054  $this->showSearchRoleTable($_SESSION['rep_search']['role']);
1055  break;
1056  }
1057  }
1058 
1064  protected function showSearchUserTable($a_usr_ids, $a_parent_cmd)
1065  {
1066  $is_in_admin = ($_REQUEST['baseClass'] == 'ilAdministrationGUI');
1067  if ($is_in_admin) {
1068  // remember link target to admin search gui (this)
1069  $_SESSION["usr_search_link"] = $this->ctrl->getLinkTarget($this, 'show');
1070  }
1071 
1072  include_once './Services/Search/classes/class.ilRepositoryUserResultTableGUI.php';
1073 
1074  $table = new ilRepositoryUserResultTableGUI($this, $a_parent_cmd, $is_in_admin);
1075  if (count($this->add_options)) {
1076  $table->addMultiItemSelectionButton(
1077  'selectedCommand',
1078  $this->add_options,
1079  'handleMultiCommand',
1080  $this->lng->txt('execute')
1081  );
1082  } else {
1083  $table->addMultiCommand('addUser', $this->lng->txt('btn_add'));
1084  }
1085  $table->setUserLimitations($this->getUserLimitations());
1086  $table->parseUserIds($a_usr_ids);
1087 
1088  $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1089  }
1090 
1096  protected function showSearchRoleTable($a_obj_ids)
1097  {
1098  include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1099 
1100  $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1101  $table->parseObjectIds($a_obj_ids);
1102 
1103  $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1104  }
1105 
1111  protected function showSearchGroupTable($a_obj_ids)
1112  {
1113  include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1114 
1115  $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1116  $table->parseObjectIds($a_obj_ids);
1117 
1118  $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1119  }
1120 
1126  protected function showSearchCourseTable($a_obj_ids)
1127  {
1128  include_once './Services/Search/classes/class.ilRepositoryObjectResultTableGUI.php';
1129 
1130  $table = new ilRepositoryObjectResultTableGUI($this, 'showSearchResults', $this->object_selection);
1131  $table->parseObjectIds($a_obj_ids);
1132 
1133  $this->tpl->setVariable('RES_TABLE', $table->getHTML());
1134  }
1135 
1140  protected function listUsers()
1141  {
1142  // get parameter is used e.g. in exercises to provide
1143  // "add members of course" link
1144  if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1145  $_POST['obj'][0] = $_GET["list_obj"];
1146  }
1147  if (!is_array($_POST['obj']) or !$_POST['obj']) {
1148  ilUtil::sendFailure($this->lng->txt('select_one'));
1149  $this->showSearchResults();
1150  return false;
1151  }
1152 
1153  $_SESSION['rep_search']['objs'] = $_POST['obj'];
1154 
1155  // Get all members
1156  $members = array();
1157  foreach ($_POST['obj'] as $obj_id) {
1158  $type = ilObject::_lookupType($obj_id);
1159  switch ($type) {
1160  case 'crs':
1161  case 'grp':
1162 
1163  include_once './Services/Membership/classes/class.ilParticipants.php';
1165  $part = [];
1166  if (is_callable($this->user_filter)) {
1167  $part = call_user_func_array(
1168  $this->user_filter,
1169  [
1170  ilParticipants::getInstanceByObjId($obj_id)->getParticipants()
1171  ]
1172  );
1173  } else {
1174  $part = ilParticipants::getInstanceByObjId($obj_id)->getParticipants();
1175  }
1176 
1177  $members = array_merge((array) $members, $part);
1178  }
1179  break;
1180 
1181  case 'role':
1182  global $rbacreview;
1183 
1184  $assigned = [];
1185  if (is_callable($this->user_filter)) {
1186  $assigned = call_user_func_array(
1187  $this->user_filter,
1188  [
1189  $rbacreview->assignedUsers($obj_id)
1190  ]
1191  );
1192  } else {
1193  $assigned = $rbacreview->assignedUsers($obj_id);
1194  }
1195 
1196  $members = array_merge($members, ilUserFilter::getInstance()->filter($assigned));
1197  break;
1198  }
1199  }
1200  $members = array_unique((array) $members);
1201  $this->__appendToStoredResults($members);
1202 
1203  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search');
1204 
1205  $this->addNewSearchButton();
1206  $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'storedUserList');
1207  return true;
1208  }
1209 
1214  protected function storedUserList()
1215  {
1216  $_POST['obj'] = $_SESSION['rep_search']['objs'];
1217  $this->listUsers();
1218  return true;
1219  }
1220 
1229  public function searchResultFilterListener($a_ref_id, $a_data)
1230  {
1231  if ($a_data['type'] == 'usr') {
1232  if ($a_data['obj_id'] == ANONYMOUS_USER_ID) {
1233  return false;
1234  }
1235  }
1236  return true;
1237  }
1238 
1244  public function allowObjectSelection($a_value = false)
1245  {
1246  $this->object_selection = (bool) $a_value;
1247  }
1248 
1252  protected function selectObject()
1253  {
1254  // get parameter is used e.g. in exercises to provide
1255  // "add members of course" link
1256  if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) {
1257  $_POST['obj'][0] = $_GET["list_obj"];
1258  }
1259  if (!is_array($_POST['obj']) or !$_POST['obj']) {
1260  ilUtil::sendFailure($this->lng->txt('select_one'));
1261  $this->showSearchResults();
1262  return false;
1263  }
1264 
1265  $this->ctrl->setParameter($this->callback["class"], "obj", implode(";", $_POST["obj"]));
1266  $this->ctrl->redirect($this->callback["class"], $this->callback["method"]);
1267  }
1268 
1274  public function setUserLimitations($a_limitations)
1275  {
1276  $this->user_limitations = (bool) $a_limitations;
1277  }
1278 
1283  public function getUserLimitations()
1284  {
1285  return $this->user_limitations;
1286  }
1287 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
setCallback(&$class, $method, $a_add_options=array())
setTitle($a_title)
Set form title.
selectObject()
Return selection of course/group/roles to calling script.
This class represents an option in a radio group.
Add rich text string
enableSearchableCheck($a_status)
En/disable the validation of the searchable flag.
addUserFromAutoComplete()
Add user from auto complete input.
static getInstance($a_usr_id)
Get singelton instance.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
$result
This class represents a property form user interface.
$type
showSearchSelected()
submit from autocomplete
$_GET["client_id"]
$tpl
Definition: ilias.php:10
addNewSearchButton()
Add new search button.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
showSearchRoleTable($a_obj_ids)
Show usr table.
const FIELD_TYPE_MULTI
static _lookupId($a_user_str)
Lookup id by login.
const FIELD_TYPE_UDF_TEXT
__construct()
Constructor public.
const FIELD_TYPE_SELECT
static getInstance()
Singelton get instance.
static getUserMultiFieldSearchInstance($query_parser)
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
static hasParticipantListAccess($a_obj_id, $a_usr_id=null)
Check if (current) user has access to the participant list.
searchResultFilterListener($a_ref_id, $a_data)
Listener called from ilSearchResult Id is obj_id for role, usr Id is ref_id for crs grp...
const QP_COMBINATION_OR
Auto completion class for user lists.
global $ilCtrl
Definition: ilias.php:18
addFromClipboard()
add users from clipboard
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$counter
Show administrate clipboard content.
if($format !==null) $name
Definition: metadata.php:146
initFormSearch(ilObjUser $user=null)
catch(Exception $e) $message
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch
setPermissionQueryCallback($class, $method)
Set callback method for user permission access queries.
This class represents a property in a property form.
static encode($mixed, $suppress_native=false)
foreach($_POST as $key=> $value) $res
doUserAutoComplete()
Do auto completion.
addSubItem($a_item)
Add Subitem.
getUserLimitations()
allow user limitations like inactive and access limitations
static _lookupObjId($a_id)
This class represents a text property in a property form.
getTitle()
Get search form title.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
const FIELD_TYPE_UDF_SELECT
Class ilUserSearchOptions.
listUsers()
List users of course/group/roles.
$txt
Definition: error.php:11
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
allowObjectSelection($a_value=false)
Toggle object selection status.
$users
Definition: authpage.php:44
removeFromClipboard()
Remove from clipboard.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
storedUserList()
Called from table sort.
TableGUI class object (course,group and role) search results Used in member search.
settings()
Definition: settings.php:2
addUserAccessFilterCallable(callable $user_filter)
Closure for filtering users e.g $rep_search_gui->addUserAccessFilterCallable(function($user_ids) use(...
setString($a_str)
Set/get search string public.
handleMultiCommand()
Handle multi command.
global $lng
Definition: privfeed.php:17
& __parseQueryString($a_string, $a_combination_or=true, $a_ignore_length=false)
parse query string, using query parser instance
static getLogger($a_component_id)
Get component logger.
const QP_COMBINATION_AND
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
if(empty($password)) $table
Definition: pwgen.php:24
const FIELD_TYPE_TEXT
showSearchUserTable($a_usr_ids, $a_parent_cmd)
Show usr table.
$info
Definition: index.php:5
emptyClipboard()
Remove from clipboard.
$_POST["username"]
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
static getUserOrgUnitAssignmentInstance($query_parser)
get orgunit search instance
static _getUserDefinedFieldSearchInstance($query_parser)
get reference of ilLikeUserDefinedFieldSearch
static _getSearchableFieldsInfo($a_admin=false)