99 $this->result_field =
'login';
104 $this->logger = $DIC->logger()->user();
112 $this->respect_min_search_character_count = $a_status;
140 $this->limit = $a_limit;
202 $this->searchable_check = $a_status;
221 $this->user_access_check = $a_status;
239 $this->possible_fields = $a_fields;
260 $available_fields = array();
262 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
264 $available_fields[] = $field;
267 return $available_fields;
276 $this->result_field = $a_field;
284 public function getList($a_str)
291 $ilDB = $DIC[
'ilDB'];
296 $result_json[
'items'] = [];
297 $result_json[
'hasMoreResults'] =
false;
298 $this->logger->debug(
'Autocomplete search rejected: minimum characters count.');
299 return json_encode($result_json);
304 $where_part = $this->getWherePart($parsed_query);
306 $query = implode(
" ", array(
307 'SELECT ' . $select_part,
308 'FROM ' . $this->getFromPart(),
309 $where_part ?
'WHERE ' . $where_part :
'',
310 $order_by_part ?
'ORDER BY ' . $order_by_part :
'' 313 $this->logger->debug(
'Query: ' .
$query);
319 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
324 $add_second_email =
true;
326 $add_second_email =
false;
329 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
332 $more_results =
false;
336 while (($rec =
$ilDB->fetchAssoc(
$res)) && $cnt < ($max + 1)) {
338 $more_results =
true;
341 $recs[$rec[
'usr_id']] = $rec;
342 $usrIds[] = $rec[
'usr_id'];
344 if (is_callable($this->user_filter,
true, $callable_name =
'')) {
345 $usrIds = call_user_func_array($this->user_filter, [$usrIds]);
347 foreach ($usrIds as $usr_id) {
348 $rec = $recs[$usr_id];
350 if (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || in_array($rec[
'profile_value'], [
'y',
'g'])) {
351 $label = $rec[
'lastname'] .
', ' . $rec[
'firstname'] .
' [' . $rec[
'login'] .
']';
353 $label =
'[' . $rec[
'login'] .
']';
356 if ($add_email && $rec[
'email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $rec[
'email_value'])) {
357 $label .=
', ' . $rec[
'email'];
360 if ($add_second_email && $rec[
'second_email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $rec[
'second_email_value'])) {
361 $label .=
', ' . $rec[
'second_email'];
364 $result[$cnt][
'value'] = (string) $rec[$this->result_field];
365 $result[$cnt][
'label'] = $label;
366 $result[$cnt][
'id'] = $rec[
'usr_id'];
370 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
372 $result_json[
'items'] =
$result;
373 $result_json[
'hasMoreResults'] = $more_results;
394 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
395 $fields[] =
'profpref.value profile_value';
396 $fields[] =
'pubemail.value email_value';
397 $fields[] =
'pubsecondemail.value second_email_value';
400 return implode(
', ', $fields);
406 protected function getFromPart()
413 $ilDB = $DIC[
'ilDB'];
417 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
418 $joins[] =
'LEFT JOIN usr_pref profpref 419 ON profpref.usr_id = ud.usr_id 420 AND profpref.keyword = ' .
$ilDB->quote(
'public_profile',
'text');
422 $joins[] =
'LEFT JOIN usr_pref pubemail 423 ON pubemail.usr_id = ud.usr_id 424 AND pubemail.keyword = ' .
$ilDB->quote(
'public_email',
'text');
426 $joins[] =
'LEFT JOIN usr_pref pubsecondemail 427 ON pubsecondemail.usr_id = ud.usr_id 428 AND pubsecondemail.keyword = ' .
$ilDB->quote(
'public_second_email',
'text');
432 return 'usr_data ud ' . implode(
' ', $joins);
434 return 'usr_data ud';
442 protected function getWherePart(array $search_query)
450 $ilDB = $DIC[
'ilDB'];
453 $outer_conditions = array();
456 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
458 $this->
getUser()->isAnonymous()
460 if (!
$ilSetting->get(
'enable_global_profiles', 0)) {
465 $outer_conditions[] =
'profpref.value = ' .
$ilDB->quote(
'g',
'text');
469 $outer_conditions[] =
'ud.usr_id != ' .
$ilDB->quote(ANONYMOUS_USER_ID,
'integer');
471 $field_conditions = array();
473 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
475 if (
'email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
478 $email_query = array();
479 $email_query[] = $field_condition;
480 $email_query[] =
'pubemail.value = ' .
$ilDB->quote(
'y',
'text');
481 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
482 } elseif (
'second_email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
485 $email_query = array();
486 $email_query[] = $field_condition;
487 $email_query[] =
'pubsecondemail.value = ' .
$ilDB->quote(
'y',
'text');
488 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
490 $field_conditions[] = $field_condition;
498 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
502 $fields =
'(' . implode(
' OR ', $field_conditions) .
')';
504 $field_conditions = [
505 '(' . implode(
' AND ', array(
507 $ilDB->in(
'profpref.value', array(
'y',
'g'),
false,
'text')
514 $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
516 include_once
'Services/User/classes/class.ilUserAccountSettings.php';
518 include_once
'./Services/User/classes/class.ilUserFilter.php';
522 if ($field_conditions) {
523 $outer_conditions[] =
'(' . implode(
' OR ', $field_conditions) .
')';
526 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
530 $outer_conditions[] =
"ud.active = " .
$ilDB->quote(1,
'integer');
534 $unlimited =
"ud.time_limit_unlimited = " .
$ilDB->quote(1,
'integer');
535 $from =
"ud.time_limit_from < " .
$ilDB->quote(time(),
'integer');
536 $until =
"ud.time_limit_until > " .
$ilDB->quote(time(),
'integer');
538 $outer_conditions[] =
'(' . $unlimited .
' OR (' .
$from .
' AND ' . $until .
'))';
541 return implode(
' AND ', $outer_conditions);
557 protected function getQueryConditionByFieldAndValue($field,
$query)
564 $ilDB = $DIC[
'ilDB'];
566 $query_strings = array(
$query[
'query']);
568 if (array_key_exists($field,
$query)) {
569 $query_strings = array(
$query[$field]);
570 } elseif (array_key_exists(
'parts',
$query)) {
571 $query_strings =
$query[
'parts'];
574 $query_condition =
'( ';
576 foreach ($query_strings as $query_string) {
578 $query_condition .=
' OR ';
581 $query_condition .=
$ilDB->like($field,
'text', $query_string .
'%');
583 $query_condition .=
$ilDB->like($field,
'text', $query_string);
586 $query_condition .=
')';
587 return $query_condition;
597 $this->user_limitations = (bool) $a_limitations;
636 if (!stristr($a_query,
'\\')) {
637 $a_query = str_replace(
'%',
'\%', $a_query);
638 $a_query = str_replace(
'_',
'\_', $a_query);
641 $query[
'query'] = trim($a_query);
644 if (strpos($a_query,
',')) {
645 $comma_separated = (array) explode(
',', $a_query);
647 if (count($comma_separated) == 2) {
648 if (trim($comma_separated[0])) {
649 $query[
'lastname'] = trim($comma_separated[0]);
651 if (trim($comma_separated[1])) {
652 $query[
'firstname'] = trim($comma_separated[1]);
656 $whitespace_separated = (array) explode(
' ', $a_query);
657 foreach ($whitespace_separated as $part) {
659 $query[
'parts'][] = trim($part);
respectMinimumSearchCharacterCount($a_status)
isFieldSearchableCheckEnabled()
Searchable check enabled.
addUserAccessFilterCallable(callable $user_filter)
Closure for filtering users e.g $rep_search_gui->addUserAccessFilterCallable(function($user_ids) use(...
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
const PRIVACY_MODE_RESPECT_USER_SETTING
setMoreLinkAvailable($more_link_available)
IMPORTANT: remember to read request parameter 'fetchall' to use this function.
$respect_min_search_character_count
static getInstance()
Singelton get instance.
Auto completion class for user lists.
getRespectMinimumSearchCharacterCount()
const MIN_WORD_LENGTH
Minimum of characters required for search.
getFields()
Get searchable fields.
static encode($mixed, $suppress_native=false)
enableUserAccessCheck($a_status)
Enable user access check.
foreach($_POST as $key=> $value) $res
setPrivacyMode($privacy_mode)
getSearchFields()
get possible search fields
getUserLimitations()
allow user limitations like inactive and access limitations
setSearchType($search_type)
parseQueryString($a_query)
Parse query string.
setResultField($a_field)
Set result field.
isUserAccessCheckEnabled()
Check if user access check is enabled.
enableFieldSearchableCheck($a_status)
Enable the check whether the field is searchable in Administration -> Settings -> Standard Fields...
__construct()
Default constructor.
static getInstance()
Singelton get instance.
setSearchFields($a_fields)
Set searchable fields.
const PRIVACY_MODE_IGNORE_USER_SETTING
static _isEnabled($a_key)