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;
 
  241        $available_fields = array();
 
  243            include_once 
'Services/Search/classes/class.ilUserSearchOptions.php';
 
  245                $available_fields[] = $field;
 
  248        return $available_fields;
 
  257        $this->result_field = $a_field;
 
  265    public function getList($a_str)
 
  274            $result_json[
'items'] = [];
 
  275            $result_json[
'hasMoreResults'] = 
false;
 
  276            $this->logger->debug(
'Autocomplete search rejected: minimum characters count.');
 
  277            return json_encode($result_json);
 
  282        $where_part    = $this->getWherePart($parsed_query);
 
  284        $query         = implode(
" ", array(
 
  285            'SELECT ' . $select_part,
 
  286            'FROM ' . $this->getFromPart(),
 
  287            $where_part ? 
'WHERE ' . $where_part : 
'',
 
  288            $order_by_part ? 
'ORDER BY ' . $order_by_part : 
'' 
  291        $this->logger->debug(
'Query: ' . 
$query);
 
  297        include_once 
'Services/Search/classes/class.ilUserSearchOptions.php';
 
  302        $add_second_email = 
true;
 
  304            $add_second_email = 
false;
 
  307        include_once 
'./Services/Search/classes/class.ilSearchSettings.php';
 
  310        $more_results = 
false;
 
  312        while (($rec = 
$ilDB->fetchAssoc(
$res)) && $cnt < ($max + 1)) {
 
  314                $more_results = 
true;
 
  318            if (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || in_array($rec[
'profile_value'], [
'y',
'g'])) {
 
  319                $label = $rec[
'lastname'] . 
', ' . $rec[
'firstname'] . 
' [' . $rec[
'login'] . 
']';
 
  321                $label = 
'[' . $rec[
'login'] . 
']';
 
  324            if ($add_email && $rec[
'email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || 
'y' == $rec[
'email_value'])) {
 
  325                $label .= 
', ' . $rec[
'email'];
 
  328            if ($add_second_email && $rec[
'second_email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() || 
'y' == $rec[
'second_email_value'])) {
 
  329                $label .= 
', ' . $rec[
'second_email'];
 
  332            $result[$cnt][
'value'] = (string) $rec[$this->result_field];
 
  333            $result[$cnt][
'label'] = $label;
 
  334            $result[$cnt][
'id']    = $rec[
'usr_id'];
 
  338        include_once 
'Services/JSON/classes/class.ilJsonUtil.php';
 
  340        $result_json[
'items'] = 
$result;
 
  341        $result_json[
'hasMoreResults'] = $more_results;
 
  343        $this->logger->dump($result_json);
 
  362        if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
 
  363            $fields[] = 
'profpref.value profile_value';
 
  364            $fields[] = 
'pubemail.value email_value';
 
  365            $fields[] = 
'pubsecondemail.value second_email_value';
 
  368        return implode(
', ', $fields);
 
  374    protected function getFromPart()
 
  383        if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
 
  384            $joins[] = 
'LEFT JOIN usr_pref profpref 
  385                                ON profpref.usr_id = ud.usr_id 
  386                                AND profpref.keyword = ' . 
$ilDB->quote(
'public_profile', 
'text');
 
  388            $joins[] = 
'LEFT JOIN usr_pref pubemail 
  389                                ON pubemail.usr_id = ud.usr_id 
  390                                AND pubemail.keyword = ' . 
$ilDB->quote(
'public_email', 
'text');
 
  392            $joins[] = 
'LEFT JOIN usr_pref pubsecondemail 
  393                                ON pubsecondemail.usr_id = ud.usr_id 
  394                                AND pubsecondemail.keyword = ' . 
$ilDB->quote(
'public_second_email', 
'text');
 
  398            return 'usr_data ud ' . implode(
' ', $joins);
 
  400            return 'usr_data ud';
 
  408    protected function getWherePart(array $search_query)
 
  416        $outer_conditions = array();
 
  419        if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
 
  421            $this->
getUser()->isAnonymous()
 
  423            if (!
$ilSetting->get(
'enable_global_profiles', 0)) {
 
  428                $outer_conditions[] = 
'profpref.value = ' . 
$ilDB->quote(
'g', 
'text');
 
  432        $outer_conditions[] =  
'ud.usr_id != ' . 
$ilDB->quote(ANONYMOUS_USER_ID, 
'integer');
 
  434        $field_conditions = array();
 
  436            $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
 
  438            if (
'email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
 
  441                $email_query        = array();
 
  442                $email_query[]      = $field_condition;
 
  443                $email_query[]      = 
'pubemail.value = ' . 
$ilDB->quote(
'y', 
'text');
 
  444                $field_conditions[] = 
'(' . implode(
' AND ', $email_query) . 
')';
 
  445            } elseif (
'second_email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode()) {
 
  448                $email_query        = array();
 
  449                $email_query[]      = $field_condition;
 
  450                $email_query[]      = 
'pubsecondemail.value = ' . 
$ilDB->quote(
'y', 
'text');
 
  451                $field_conditions[] = 
'(' . implode(
' AND ', $email_query) . 
')';
 
  453                $field_conditions[] = $field_condition;
 
  461        if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
 
  465            $fields = 
'(' . implode(
' OR ', $field_conditions) . 
')';
 
  467            $field_conditions = [
 
  468                '(' . implode(
' AND ', array(
 
  470                $ilDB->in(
'profpref.value', array(
'y', 
'g'), 
false, 
'text')
 
  477        $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
 
  479        include_once 
'Services/User/classes/class.ilUserAccountSettings.php';
 
  481            include_once 
'./Services/User/classes/class.ilUserFilter.php';
 
  485        if ($field_conditions) {
 
  486            $outer_conditions[] = 
'(' . implode(
' OR ', $field_conditions) . 
')';
 
  489        include_once 
'./Services/Search/classes/class.ilSearchSettings.php';
 
  492        if (!$settings->isInactiveUserVisible() && $this->getUserLimitations()) {
 
  493            $outer_conditions[] = 
"ud.active = " . 
$ilDB->quote(1, 
'integer');
 
  496        if (!$settings->isLimitedUserVisible() && $this->getUserLimitations()) {
 
  497            $unlimited = 
"ud.time_limit_unlimited = " . 
$ilDB->quote(1, 
'integer');
 
  498            $from = 
"ud.time_limit_from < " . 
$ilDB->quote(time(), 
'integer');
 
  499            $until = 
"ud.time_limit_until > " . 
$ilDB->quote(time(), 
'integer');
 
  501            $outer_conditions[] = 
'(' . $unlimited . 
' OR (' . 
$from . 
' AND ' . $until . 
'))';
 
  504        return implode(
' AND ', $outer_conditions);
 
  520    protected function getQueryConditionByFieldAndValue($field, 
$query)
 
  527        $query_strings = array(
$query[
'query']);
 
  529        if (array_key_exists($field, 
$query)) {
 
  530            $query_strings = array(
$query[$field]);
 
  531        } elseif (array_key_exists(
'parts', 
$query)) {
 
  532            $query_strings = 
$query[
'parts'];
 
  535        $query_condition = 
'( ';
 
  537        foreach ($query_strings as $query_string) {
 
  539                $query_condition .= 
' OR ';
 
  542                $query_condition .= 
$ilDB->like($field, 
'text', $query_string . 
'%');
 
  544                $query_condition .= 
$ilDB->like($field, 
'text', $query_string);
 
  547        $query_condition .= 
')';
 
  548        return $query_condition;
 
  558        $this->user_limitations = (bool) $a_limitations;
 
  597        if (!stristr($a_query, 
'\\')) {
 
  598            $a_query = str_replace(
'%', 
'\%', $a_query);
 
  599            $a_query = str_replace(
'_', 
'\_', $a_query);
 
  602        $query[
'query'] = trim($a_query);
 
  605        if (strpos($a_query, 
',')) {
 
  606            $comma_separated = (array) explode(
',', $a_query);
 
  608            if (count($comma_separated) == 2) {
 
  609                if (trim($comma_separated[0])) {
 
  610                    $query[
'lastname'] = trim($comma_separated[0]);
 
  612                if (trim($comma_separated[1])) {
 
  613                    $query[
'firstname'] = trim($comma_separated[1]);
 
  617            $whitespace_separated = (array) explode(
' ', $a_query);
 
  618            foreach ($whitespace_separated as $part) {
 
  620                    $query[
'parts'][] = trim($part);
 
An exception for terminatinating execution or to throw for unit testing.
static encode($mixed, $suppress_native=false)
const MIN_WORD_LENGTH
Minimum of characters required for search.
static getInstance()
Singelton get instance.
Auto completion class for user lists.
getFields()
Get searchable fields.
setSearchType($search_type)
parseQueryString($a_query)
Parse query string.
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
setPrivacyMode($privacy_mode)
__construct()
Default constructor.
getUserLimitations()
allow user limitations like inactive and access limitations
isUserAccessCheckEnabled()
Check if user access check is enabled.
isFieldSearchableCheckEnabled()
Searchable check enabled.
const PRIVACY_MODE_RESPECT_USER_SETTING
setResultField($a_field)
Set result field.
getSearchFields()
get possible search fields
getRespectMinimumSearchCharacterCount()
$respect_min_search_character_count
enableFieldSearchableCheck($a_status)
Enable the check whether the field is searchable in Administration -> Settings -> Standard Fields.
setSearchFields($a_fields)
Set searchable fields.
enableUserAccessCheck($a_status)
Enable user access check.
respectMinimumSearchCharacterCount($a_status)
const PRIVACY_MODE_IGNORE_USER_SETTING
setMoreLinkAvailable($more_link_available)
IMPORTANT: remember to read request parameter 'fetchall' to use this function.
static getInstance()
Singelton get instance.
static _isEnabled($a_key)
foreach($_POST as $key=> $value) $res