94 $this->result_field =
'login';
99 $this->logger = $DIC->logger()->user();
107 $this->respect_min_search_character_count = $a_status;
121 $this->limit = $a_limit;
183 $this->searchable_check = $a_status;
202 $this->user_access_check = $a_status;
220 $this->possible_fields = $a_fields;
242 $available_fields =
array();
245 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
248 $available_fields[] = $field;
251 return $available_fields;
260 $this->result_field = $a_field;
268 public function getList($a_str)
277 include_once
'./Services/Search/classes/class.ilQueryParser.php';
280 $result_json[
'items'] = [];
281 $result_json[
'hasMoreResults'] =
false;
282 $this->logger->debug(
'Autocomplete search rejected: minimum characters count.');
283 return json_encode($result_json);
288 $where_part = $this->getWherePart($parsed_query);
291 'SELECT ' . $select_part,
292 'FROM ' . $this->getFromPart(),
293 $where_part ?
'WHERE ' . $where_part :
'',
294 $order_by_part ?
'ORDER BY ' . $order_by_part :
'' 297 $this->logger->debug(
'Query: ' .
$query);
303 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
309 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
312 $more_results = FALSE;
314 while(($rec = $ilDB->fetchAssoc(
$res)) && $cnt < ($max + 1))
318 $more_results = TRUE;
322 if (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || in_array($rec[
'profile_value'], [
'y',
'g']))
324 $label = $rec[
'lastname'] .
', ' . $rec[
'firstname'] .
' [' . $rec[
'login'] .
']';
328 $label =
'[' . $rec[
'login'] .
']';
331 if($add_email && $rec[
'email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $rec[
'email_value']))
333 $label .=
', ' . $rec[
'email'];
337 $result[$cnt][
'label'] = $label;
338 $result[$cnt][
'id'] = $rec[
'usr_id'];
342 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
344 $result_json[
'items'] =
$result;
345 $result_json[
'hasMoreResults'] = $more_results;
347 $this->logger->dump($result_json);
365 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
367 $fields[] =
'profpref.value profile_value';
368 $fields[] =
'pubemail.value email_value';
371 return implode(
', ', $fields);
377 protected function getFromPart()
386 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
388 $joins[] =
'LEFT JOIN usr_pref profpref 389 ON profpref.usr_id = ud.usr_id 390 AND profpref.keyword = ' . $ilDB->quote(
'public_profile',
'text');
392 $joins[] =
'LEFT JOIN usr_pref pubemail 393 ON pubemail.usr_id = ud.usr_id 394 AND pubemail.keyword = ' . $ilDB->quote(
'public_email',
'text');
399 return 'usr_data ud ' . implode(
' ', $joins);
403 return 'usr_data ud';
411 protected function getWherePart(
array $search_query)
419 $outer_conditions =
array();
422 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
424 $this->
getUser()->isAnonymous()
427 if(!$ilSetting->get(
'enable_global_profiles', 0))
435 $outer_conditions[] =
'profpref.value = ' . $ilDB->quote(
'g',
'text');
439 $outer_conditions[] =
'ud.usr_id != ' . $ilDB->quote(ANONYMOUS_USER_ID,
'integer');
441 $field_conditions =
array();
444 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
446 if(
'email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
450 $email_query =
array();
451 $email_query[] = $field_condition;
452 $email_query[] =
'pubemail.value = ' . $ilDB->quote(
'y',
'text');
453 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
457 $field_conditions[] = $field_condition;
465 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
470 $fields =
'(' . implode(
' OR ', $field_conditions) .
')';
472 $field_conditions = [
473 '(' . implode(
' AND ',
array(
475 $ilDB->in(
'profpref.value',
array(
'y',
'g'),
false,
'text')
482 $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
484 include_once
'Services/User/classes/class.ilUserAccountSettings.php';
487 include_once
'./Services/User/classes/class.ilUserFilter.php';
491 if($field_conditions)
493 $outer_conditions[] =
'(' . implode(
' OR ', $field_conditions) .
')';
496 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
501 $outer_conditions[] =
"ud.active = ". $ilDB->quote(1,
'integer');
506 $unlimited =
"ud.time_limit_unlimited = ". $ilDB->quote(1,
'integer');
507 $from =
"ud.time_limit_from < ". $ilDB->quote(
time(),
'integer');
508 $until =
"ud.time_limit_until > ". $ilDB->quote(
time(),
'integer');
510 $outer_conditions[] =
'(' .$unlimited.
' OR ('.$from.
' AND ' .$until.
'))';
513 return implode(
' AND ', $outer_conditions);
529 protected function getQueryConditionByFieldAndValue($field,
$query)
538 if(array_key_exists($field,
$query))
542 elseif(array_key_exists(
'parts',
$query))
544 $query_strings =
$query[
'parts'];
547 $query_condition =
'( ';
549 foreach($query_strings as $query_string)
553 $query_condition .=
' OR ';
557 $query_condition .= $ilDB->like($field,
'text', $query_string .
'%');
561 $query_condition .= $ilDB->like($field,
'text', $query_string);
564 $query_condition .=
')';
565 return $query_condition;
575 $this->user_limitations = (bool) $a_limitations;
614 if(!stristr($a_query,
'\\'))
616 $a_query = str_replace(
'%',
'\%', $a_query);
617 $a_query = str_replace(
'_',
'\_', $a_query);
620 $query[
'query'] = trim($a_query);
623 if(strpos($a_query,
','))
625 $comma_separated = (
array) explode(
',', $a_query);
627 if(count($comma_separated) == 2)
629 if(trim($comma_separated[0]))
631 $query[
'lastname'] = trim($comma_separated[0]);
633 if(trim($comma_separated[1]))
635 $query[
'firstname'] = trim($comma_separated[1]);
641 $whitespace_separated = (
array) explode(
' ', $a_query);
642 foreach($whitespace_separated as $part)
646 $query[
'parts'][] = trim($part);
respectMinimumSearchCharacterCount($a_status)
isFieldSearchableCheckEnabled()
Searchable check enabled.
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
Add rich text string
The name of the decorator.
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.
setPrivacyMode($privacy_mode)
getSearchFields()
get possible search fields
getUserLimitations()
allow user limitations like inactive and access limitations
setSearchType($search_type)
Create styles array
The data for the language used.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
const PRIVACY_MODE_IGNORE_USER_SETTING
static _isEnabled($a_key)