80 $this->result_field =
'login';
88 $this->limit = $a_limit;
150 $this->searchable_check = $a_status;
169 $this->user_access_check = $a_status;
187 $this->possible_fields = $a_fields;
209 $available_fields = array();
212 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
215 $available_fields[] = $field;
218 return $available_fields;
227 $this->result_field = $a_field;
235 public function getList($a_str)
244 $where_part = $this->getWherePart($a_str);
246 $query = implode(
" ", array(
247 'SELECT ' . $select_part,
248 'FROM ' . $this->getFromPart(),
249 $where_part ?
'WHERE ' . $where_part :
'',
250 $order_by_part ?
'ORDER BY ' . $order_by_part :
''
253 $ilLog->write(__METHOD__ .
': Query: ' .
$query);
255 $res = $ilDB->query($query);
259 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
265 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
268 $more_results = FALSE;
270 while(($rec = $ilDB->fetchAssoc(
$res)) && $cnt < ($max + 1))
274 $more_results = TRUE;
279 $label = $rec[
'lastname'] .
', ' . $rec[
'firstname'] .
' [' . $rec[
'login'] .
']';
281 if($add_email && $rec[
'email'] && (self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $rec[
'email_value']))
283 $label .=
', ' . $rec[
'email'];
286 $result[$cnt][
'value'] = (string)$rec[$this->result_field];
287 $result[$cnt][
'label'] = $label;
288 $result[$cnt][
'id'] = $rec[
'usr_id'];
292 include_once
'Services/JSON/classes/class.ilJsonUtil.php';
294 $result_json[
'items'] =
$result;
295 $result_json[
'hasMoreResults'] = $more_results;
297 $GLOBALS[
'ilLog']->write(__METHOD__.
': '.print_r($result_json,TRUE));
315 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
317 $fields[] =
'profpref.value profile_value';
318 $fields[] =
'pubemail.value email_value';
321 return implode(
', ', $fields);
327 protected function getFromPart()
336 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
338 $joins[] =
'LEFT JOIN usr_pref profpref
339 ON profpref.usr_id = ud.usr_id
340 AND profpref.keyword = ' . $ilDB->quote(
'public_profile',
'text');
342 $joins[] =
'LEFT JOIN usr_pref pubemail
343 ON pubemail.usr_id = ud.usr_id
344 AND pubemail.keyword = ' . $ilDB->quote(
'public_email',
'text');
349 return 'usr_data ud ' . implode(
' ', $joins);
353 return 'usr_data ud';
361 protected function getWherePart($search_query)
369 $outer_conditions = array();
372 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
374 $this->
getUser()->isAnonymous()
377 if(!$ilSetting->get(
'enable_global_profiles', 0))
385 $outer_conditions[] =
'profpref.value = ' . $ilDB->quote(
'g',
'text');
389 $outer_conditions[] =
'ud.usr_id != ' . $ilDB->quote(ANONYMOUS_USER_ID,
'integer');
391 $field_conditions = array();
394 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
396 if(
'email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
400 $email_query = array();
401 $email_query[] = $field_condition;
402 $email_query[] =
'pubemail.value = ' . $ilDB->quote(
'y',
'text');
403 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
407 $field_conditions[] = $field_condition;
415 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
420 $fields = implode(
' OR ', $field_conditions);
422 $field_conditions[] =
'(' . implode(
' AND ', array(
424 $ilDB->in(
'profpref.value', array(
'y',
'g'),
false,
'text')
430 $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
432 include_once
'Services/User/classes/class.ilUserAccountSettings.php';
435 include_once
'./Services/User/classes/class.ilUserFilter.php';
439 if($field_conditions)
441 $outer_conditions[] =
'(' . implode(
' OR ', $field_conditions) .
')';
444 return implode(
' AND ', $outer_conditions);
460 protected function getQueryConditionByFieldAndValue($field, $a_str)
468 if(!stristr($a_str,
'\\'))
470 $a_str = str_replace(
'%',
'\%', $a_str);
471 $a_str = str_replace(
'_',
'\_', $a_str);
476 return $ilDB->like($field,
'text', $a_str .
'%');
480 return $ilDB->like($field,
'text', $a_str);