124 $this->searchable_check = $a_status;
143 $this->user_access_check = $a_status;
161 $this->possible_fields = $a_fields;
183 $available_fields = array();
186 include_once
'Services/Search/classes/class.ilUserSearchOptions.php';
189 $available_fields[] = $field;
192 return $available_fields;
200 public function getList($a_str)
208 include_once
'./Services/JSON/classes/class.ilJsonUtil.php';
210 $result->response =
new stdClass();
211 $result->response->results = array();
212 if (strlen($a_str) < 3)
218 $where_part = $this->getWherePart($a_str);
220 $query = implode(
" ", array(
221 'SELECT ' . $select_part,
222 'FROM ' . $this->getFromPart(),
223 $where_part ?
'WHERE ' . $where_part :
'',
224 $order_by_part ?
'ORDER BY ' . $order_by_part :
''
227 $ilLog->write(__METHOD__ .
': Query: ' .
$query);
229 $res = $ilDB->query($query);
231 include_once
'./Services/Search/classes/class.ilSearchSettings.php';
234 while(($rec = $ilDB->fetchAssoc(
$res)) && $cnt < $max)
236 $result->response->results[$cnt] =
new stdClass();
237 $result->response->results[$cnt]->login = (string) $rec[
"login"];
238 $result->response->results[$cnt]->firstname = (string) $rec[
"firstname"];
239 $result->response->results[$cnt]->lastname = (string) $rec[
"lastname"];
241 if(self::PRIVACY_MODE_RESPECT_USER_SETTING != $this->
getPrivacyMode() ||
'y' == $rec[
'email_value'])
243 $result->response->results[$cnt]->email = (string) $rec[
"email"];
264 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
266 $fields[] =
'profpref.value profile_value';
267 $fields[] =
'pubemail.value email_value';
270 return implode(
', ', $fields);
276 protected function getFromPart()
285 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
287 $joins[] =
'LEFT JOIN usr_pref profpref
288 ON profpref.usr_id = usr_data.usr_id
289 AND profpref.keyword = ' . $ilDB->quote(
'public_profile',
'text');
291 $joins[] =
'LEFT JOIN usr_pref pubemail
292 ON pubemail.usr_id = usr_data.usr_id
293 AND pubemail.keyword = ' . $ilDB->quote(
'public_email',
'text');
298 return 'usr_data ' . implode(
' ', $joins);
310 protected function getWherePart($search_query)
318 $outer_conditions = array();
321 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
323 $this->
getUser()->isAnonymous()
326 if(!$ilSetting->get(
'enable_global_profiles', 0))
334 $outer_conditions[] =
'profpref.value = ' . $ilDB->quote(
'g',
'text');
338 $outer_conditions[] =
'usr_data.usr_id != ' . $ilDB->quote(ANONYMOUS_USER_ID,
'integer');
340 $field_conditions = array();
343 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
345 if(
'email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode())
349 $email_query = array();
350 $email_query[] = $field_condition;
351 $email_query[] =
'pubemail.value = ' . $ilDB->quote(
'y',
'text');
352 $field_conditions[] =
'(' . implode(
' AND ', $email_query) .
')';
356 $field_conditions[] = $field_condition;
364 if(self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->
getPrivacyMode() &&
368 $fields = implode(
' OR ', $field_conditions);
370 $field_conditions[] =
'(' . implode(
' AND ', array(
372 $ilDB->in(
'profpref.value', array(
'y',
'g'),
false,
'text')
378 $field_conditions[] = $this->getQueryConditionByFieldAndValue(
'login', $search_query);
380 include_once
'Services/User/classes/class.ilUserAccountSettings.php';
383 include_once
'./Services/User/classes/class.ilUserFilter.php';
387 if($field_conditions)
389 $outer_conditions[] =
'(' . implode(
' OR ', $field_conditions) .
')';
392 return implode(
' AND ', $outer_conditions);
408 protected function getQueryConditionByFieldAndValue($field, $a_str)
417 return $ilDB->like($field,
'text', $a_str .
'%');
421 return $ilDB->like($field,
'text', $a_str);