52 $this->result_field =
'login';
57 $this->
logger = $DIC->logger()->user();
58 $this->db =
$DIC[
'ilDB'];
64 $this->respect_min_search_character_count = $a_status;
87 $this->limit = $a_limit;
130 $this->searchable_check = $a_status;
144 $this->user_access_check = $a_status;
160 $this->possible_fields = $a_fields;
179 $available_fields = [];
181 if (ilUserSearchOptions::_isEnabled($field)) {
182 $available_fields[] = $field;
185 return $available_fields;
193 $this->result_field = $a_field;
199 public function getList(
string $a_str): string
204 $result_json[
'items'] = [];
205 $result_json[
'hasMoreResults'] =
false;
206 $this->
logger->debug(
'Autocomplete search rejected: minimum characters count.');
207 return json_encode($result_json);
214 $query = implode(
" ", [
215 'SELECT ' . $select_part,
217 $where_part ?
'WHERE ' . $where_part :
'',
218 $order_by_part ?
'ORDER BY ' . $order_by_part :
''
221 $this->
logger->debug(
'Query: ' . $query);
223 $res = $this->db->query($query);
231 $add_second_email =
true;
233 $add_second_email =
false;
237 $more_results =
false;
242 while (count($usr_ids) <= $max) {
244 $records = array_replace($records, $next_records);
245 $usr_ids = array_keys($records);
247 $callable_name =
null;
248 if (is_callable($this->user_filter,
true, $callable_name)) {
249 $usr_ids = call_user_func($this->user_filter, $usr_ids);
252 if (count($next_records) <= $max) {
258 $more_results =
true;
261 foreach (array_slice($usr_ids, 0, $max) as $usr_id) {
262 $record = $records[$usr_id];
264 if (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || in_array($record[
'profile_value'], [
'y',
'g'])) {
265 $label = $record[
'lastname'] .
', ' . $record[
'firstname'] .
' [' . $record[
'login'] .
']';
267 $label =
'[' . $record[
'login'] .
']';
270 if ($add_email && $record[
'email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $record[
'email_value'])) {
271 $label .=
', ' . $record[
'email'];
274 if ($add_second_email && $record[
'second_email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $record[
'second_email_value'])) {
275 $label .=
', ' . $record[
'second_email'];
279 'value' => (string) $record[$this->result_field],
281 'id' => $record[
'usr_id']
285 $result_json[
'items'] = $result;
286 $result_json[
'hasMoreResults'] = $more_results;
290 return json_encode($result_json, JSON_THROW_ON_ERROR);
299 while (($rec = $this->db->fetchAssoc(
$res)) && $cnt <= $max) {
300 $recs[$rec[
'usr_id']] = $rec;
317 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode()) {
318 $fields[] =
'profpref.value profile_value';
319 $fields[] =
'pubemail.value email_value';
320 $fields[] =
'pubsecondemail.value second_email_value';
323 return implode(
', ', $fields);
330 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode()) {
331 $joins[] =
'LEFT JOIN usr_pref profpref
332 ON profpref.usr_id = ud.usr_id
333 AND profpref.keyword = ' . $this->db->quote(
'public_profile',
'text');
335 $joins[] =
'LEFT JOIN usr_pref pubemail
336 ON pubemail.usr_id = ud.usr_id
337 AND pubemail.keyword = ' . $this->db->quote(
'public_email',
'text');
339 $joins[] =
'LEFT JOIN usr_pref pubsecondemail
340 ON pubsecondemail.usr_id = ud.usr_id
341 AND pubsecondemail.keyword = ' . $this->db->quote(
'public_second_email',
'text');
345 return 'usr_data ud ' . implode(
' ', $joins);
347 return 'usr_data ud';
353 $outer_conditions = [];
356 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode() &&
358 $this->
getUser()->isAnonymous()
360 if (!$this->
settings->get(
'enable_global_profiles',
'0')) {
365 $outer_conditions[] =
'profpref.value = ' . $this->db->quote(
'g',
'text');
369 $outer_conditions[] =
'ud.usr_id != ' . $this->db->quote(
ANONYMOUS_USER_ID,
'integer');
371 $field_conditions = [];
372 foreach ($this->getFields() as $field) {
373 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
375 if ($field ===
'email' && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode()) {
379 $email_query[] = $field_condition;
380 $email_query[] =
'pubemail.value = ' . $this->db->quote(
'y',
'text');
381 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
382 } elseif ($field ===
'second_email' && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode()) {
386 $email_query[] = $field_condition;
387 $email_query[] =
'pubsecondemail.value = ' . $this->db->quote(
'y',
'text');
388 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
390 $field_conditions[] = $field_condition;
398 if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode() &&
402 $fields =
'(' . implode(
' OR ', $field_conditions) .
')';
404 $field_conditions = [
405 '(' . implode(
' AND ', [
407 $this->db->in(
'profpref.value', [
'y',
'g'],
false,
'text')
414 $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
420 if ($field_conditions) {
421 $outer_conditions[] =
'(' . implode(
' OR ', $field_conditions) .
')';
426 if (!$search_settings->isInactiveUserVisible() && $this->getUserLimitations()) {
427 $outer_conditions[] =
"ud.active = " . $this->db->quote(1,
'integer');
430 if (!$search_settings->isLimitedUserVisible() && $this->getUserLimitations()) {
431 $unlimited =
"ud.time_limit_unlimited = " . $this->db->quote(1,
'integer');
432 $from =
"ud.time_limit_from < " . $this->db->quote(time(),
'integer');
433 $until =
"ud.time_limit_until > " . $this->db->quote(time(),
'integer');
435 $outer_conditions[] =
'(' . $unlimited .
' OR (' . $from .
' AND ' . $until .
'))';
438 return implode(
' AND ', $outer_conditions);
448 $query_strings = [$query[
'query']];
450 if (array_key_exists($field, $query)) {
451 $query_strings = [$query[$field]];
452 } elseif (array_key_exists(
'parts', $query)) {
453 $query_strings = $query[
'parts'];
456 $query_condition =
'( ';
458 foreach ($query_strings as $query_string) {
460 $query_condition .=
' OR ';
462 if (self::SEARCH_TYPE_LIKE == $this->getSearchType()) {
463 $query_condition .= $this->db->like($field,
'text', $query_string .
'%');
465 $query_condition .= $this->db->like($field,
'text', $query_string);
468 $query_condition .=
')';
469 return $query_condition;
477 $this->user_limitations = $a_limitations;
485 return $this->user_limitations;
490 return $this->more_link_available;
498 $this->more_link_available = $more_link_available;
508 if (strpos($a_query,
'\\') ===
false) {
509 $a_query = str_replace([
'%',
'_'], [
'\%',
'\_'], $a_query);
512 $query[
'query'] = trim($a_query);
515 if (strpos($a_query,
',')) {
516 $comma_separated = explode(
',', $a_query);
518 if (count($comma_separated) == 2) {
519 if (trim($comma_separated[0])) {
520 $query[
'lastname'] = trim($comma_separated[0]);
522 if (trim($comma_separated[1])) {
523 $query[
'firstname'] = trim($comma_separated[1]);
527 $whitespace_separated = explode(
' ', $a_query);
528 foreach ($whitespace_separated as $part) {
530 $query[
'parts'][] = trim($part);
Component logger with individual log levels by component id.
const MIN_WORD_LENGTH
Minimum of characters required for search.
static strLen(string $a_string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
bool $respect_min_search_character_count
getFields()
Get searchable fields.
setSearchFields(array $a_fields)
Set searchable fields.
setResultField(string $a_field)
Set result field.
setUserLimitations(bool $a_limitations)
allow user limitations like inactive and access limitations
setPrivacyMode(int $privacy_mode)
respectMinimumSearchCharacterCount(bool $a_status)
getQueryConditionByFieldAndValue(string $field, array $query)
getUserLimitations()
allow user limitations like inactive and access limitations
getList(string $a_str)
Get completion list.
isUserAccessCheckEnabled()
Check if user access check is enabled.
setSearchType(int $search_type)
isFieldSearchableCheckEnabled()
const PRIVACY_MODE_RESPECT_USER_SETTING
getSearchFields()
get possible search fields
getRespectMinimumSearchCharacterCount()
enableUserAccessCheck(bool $a_status)
Enable user access check.
addUserAccessFilterCallable(Closure $user_filter)
Closure for filtering users e.g $rep_search_gui->addUserAccessFilterCallable(function($user_ids) use(...
setMoreLinkAvailable(bool $more_link_available)
IMPORTANT: remember to read request parameter 'fetchall' to use this function.
enableFieldSearchableCheck(bool $a_status)
Enable the check whether the field is searchable in Administration -> Settings -> Standard Fields.
fetchNextRecords(ilDBStatement $res, int $max)
bool $more_link_available
parseQueryString(string $a_query)
Parse query string.
getWherePart(array $search_query)
const PRIVACY_MODE_IGNORE_USER_SETTING
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc