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