53 "time_limit_unlimited",
66 $this->logger = $DIC->logger()->usr();
79 foreach ((array) $a_val as $udf_name => $udf_value) {
80 list($udf_string, $udf_id) = explode(
'_', $udf_name);
81 if (array_key_exists((
int) $udf_id, $definitions)) {
82 $valid_udfs[$udf_name] = $udf_value;
85 $this->udf_filter = $valid_udfs;
105 $this->order_field = $a_order;
116 $this->order_dir = $a_dir;
125 $this->offset = $a_offset;
135 $this->limit = $a_limit;
144 $this->text_filter = $a_filter;
154 $this->activation = $a_activation;
163 $this->last_login = $dt;
172 $this->limited_access = $a_status;
181 $this->no_courses = $a_no_course;
190 $this->no_groups = $a_no_group;
200 $this->crs_grp = $a_cg_id;
210 $this->role = $a_role_id;
220 $this->user_folder = $a_fold_id;
229 $this->additional_fields = (array) $a_add;
238 $this->users = $a_filter;
247 $this->first_letter = $a_fll;
257 $this->has_access = (bool) $a_access;
267 $this->authentication_method = $a_authentication;
278 $ilDB = $DIC[
'ilDB'];
281 $udf_fields = array();
285 if (is_array($this->additional_fields)) {
286 foreach ($this->additional_fields as
$f) {
287 if (!in_array($f, $this->default_fields)) {
288 if ($f ==
"online_time") {
289 $this->default_fields[] =
"ut_online.online_time";
290 $join =
" LEFT JOIN ut_online ON (usr_data.usr_id = ut_online.usr_id) ";
291 } elseif (substr($f, 0, 4) ==
"udf_") {
292 $udf_fields[] = (int) substr($f, 4);
294 $this->default_fields[] =
$f;
302 if (count($udf_fields) > 0) {
303 include_once
'./Services/User/classes/class.ilUserDefinedFields.php';
308 foreach ($udf_fields as
$id) {
312 $join .=
" LEFT JOIN " . $udf_table .
" ud_" . $id .
" ON (ud_" . $id .
".field_id=" .
$ilDB->quote($id) .
" AND ud_" . $id .
".usr_id = usr_data.usr_id) ";
316 $count_query =
"SELECT count(usr_data.usr_id) cnt" .
319 $all_multi_fields = array(
"interests_general",
"interests_help_offered",
"interests_help_looking");
320 $multi_fields = array();
322 $sql_fields = array();
323 foreach ($this->default_fields as $idx => $field) {
328 if (in_array($field, $all_multi_fields)) {
329 $multi_fields[] = $field;
330 } elseif (!stristr($field,
".")) {
331 $sql_fields[] =
"usr_data." . $field;
333 $sql_fields[] = $field;
338 foreach ($udf_fields as $id) {
339 $sql_fields[] =
"ud_" . $id .
".value udf_" .
$id;
343 $query =
"SELECT " . implode($sql_fields,
",") .
347 $count_query = $count_query .
" " .
351 $query .=
" WHERE usr_data.usr_id <> " .
$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
354 $count_query .=
" WHERE 1 = 1 ";
355 $count_user_filter =
"usr_data.usr_id != " .
$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
356 if ($this->users
and is_array(($this->users))) {
357 $query .=
' AND ' .
$ilDB->in(
'usr_data.usr_id', $this->users,
false,
'integer');
358 $count_user_filter =
$ilDB->in(
'usr_data.usr_id', $this->users,
false,
'integer');
361 $count_query .=
" AND " . $count_user_filter .
" ";
364 if ($this->first_letter !=
"") {
365 $add = $where .
" (" .
$ilDB->upper(
$ilDB->substr(
"usr_data.lastname", 1, 1)) .
" = " .
$ilDB->upper(
$ilDB->quote($this->first_letter,
"text")) .
") ";
367 $count_query .= $add;
371 if ($this->text_filter !=
"") {
372 $add = $where .
" (" .
$ilDB->like(
"usr_data.login",
"text",
"%" . $this->text_filter .
"%") .
" " .
373 "OR " .
$ilDB->like(
"usr_data.firstname",
"text",
"%" . $this->text_filter .
"%") .
" " .
374 "OR " .
$ilDB->like(
"usr_data.lastname",
"text",
"%" . $this->text_filter .
"%") .
" " .
375 "OR " .
$ilDB->like(
"usr_data.second_email",
"text",
"%" . $this->text_filter .
"%") .
" " .
376 "OR " .
$ilDB->like(
"usr_data.email",
"text",
"%" . $this->text_filter .
"%") .
") ";
378 $count_query .= $add;
382 if ($this->activation !=
"") {
383 if ($this->activation ==
"inactive") {
384 $add = $where .
" usr_data.active = " .
$ilDB->quote(0,
"integer") .
" ";
386 $add = $where .
" usr_data.active = " .
$ilDB->quote(1,
"integer") .
" ";
389 $count_query .= $add;
393 if ($this->last_login instanceof
ilDateTime) {
395 $add = $where .
" usr_data.last_login < " .
398 $count_query .= $add;
402 if ($this->limited_access) {
403 $add = $where .
" usr_data.time_limit_unlimited= " .
$ilDB->quote(0,
"integer");
405 $count_query .= $add;
412 $udf_id = explode(
"_", $k)[1];
414 $add = $where .
" " .
$ilDB->like(
"ud_" . $udf_id .
".value",
"text",
"%" .
$f .
"%");
416 $add = $where .
" ud_" . $udf_id .
".value = " .
$ilDB->quote(
$f,
"text");
419 $count_query .= $add;
424 if ($this->has_access) {
425 $unlimited =
"time_limit_unlimited = " .
$ilDB->quote(1,
'integer');
426 $from =
"time_limit_from < " .
$ilDB->quote(time(),
'integer');
427 $until =
"time_limit_until > " .
$ilDB->quote(time(),
'integer');
429 $add = $where .
' (' . $unlimited .
' OR (' .
$from .
' AND ' . $until .
'))';
431 $count_query .= $add;
434 if ($this->no_courses) {
435 $add = $where .
" usr_data.usr_id NOT IN (" .
436 "SELECT DISTINCT ud.usr_id " .
437 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " .
438 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " .
439 "WHERE od.title LIKE 'il_crs_%')";
441 $count_query .= $add;
444 if ($this->no_groups) {
445 $add = $where .
" usr_data.usr_id NOT IN (" .
446 "SELECT DISTINCT ud.usr_id " .
447 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " .
448 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " .
449 "WHERE od.title LIKE 'il_grp_%')";
451 $count_query .= $add;
454 if ($this->crs_grp > 0) {
456 $add = $where .
" usr_data.usr_id IN (" .
457 "SELECT DISTINCT ud.usr_id " .
458 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " .
459 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) " .
460 "WHERE od.title = " .
$ilDB->quote(
"il_" . $cgtype .
"_member_" . $this->crs_grp,
"text") .
")";
462 $count_query .= $add;
465 if ($this->role > 0) {
466 $add = $where .
" usr_data.usr_id IN (" .
467 "SELECT DISTINCT ud.usr_id " .
468 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) " .
469 "WHERE rbac_ua.rol_id = " .
$ilDB->quote($this->role,
"integer") .
")";
471 $count_query .= $add;
475 if ($this->user_folder) {
476 $add = $where .
" " .
$ilDB->in(
'usr_data.time_limit_owner', $this->user_folder,
false,
'integer');
478 $count_query .= $add;
482 if ($this->authentication_method !=
"") {
483 $add = $where .
" usr_data.auth_mode = " .
$ilDB->quote($this->authentication_method,
"text") .
" ";
485 $count_query .= $add;
490 switch ($this->order_field) {
492 if ($this->order_dir ==
"desc") {
493 $query .=
" ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
495 $query .=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
500 if ($this->order_dir ==
"desc") {
501 $query .=
" ORDER BY ut_online.online_time DESC";
503 $query .=
" ORDER BY ut_online.online_time ASC";
508 if ($this->order_dir !=
"asc" && $this->order_dir !=
"desc") {
509 $this->order_dir =
"asc";
511 if (substr($this->order_field, 0, 4) ==
"udf_") {
514 $query .=
" ORDER BY ud_" . ((int) substr($this->order_field, 4)) .
".value " . strtoupper($this->order_dir);
516 $query .=
' ORDER BY ' . self::DEFAULT_ORDER_FIELD .
' ' . strtoupper($this->order_dir);
519 if (!in_array($this->order_field, $this->default_fields)) {
520 $this->order_field =
"login";
522 $query .=
" ORDER BY usr_data." . $this->order_field .
" " . strtoupper($this->order_dir);
528 $set =
$ilDB->query($count_query);
530 if ($rec =
$ilDB->fetchAssoc($set)) {
535 $limit = (int) $this->limit;
544 if (
sizeof($multi_fields)) {
552 while ($rec =
$ilDB->fetchAssoc($set)) {
554 if (
sizeof($multi_fields)) {
555 $usr_ids[] = $rec[
"usr_id"];
560 if (
sizeof($multi_fields) &&
sizeof($usr_ids)) {
561 $usr_multi = array();
562 $set =
$ilDB->query(
"SELECT * FROM usr_data_multi" .
563 " WHERE " .
$ilDB->in(
"usr_id", $usr_ids,
"",
"integer"));
565 $usr_multi[
$row[
"usr_id"]][
$row[
"field_id"]][] = $row[
"value"];
567 foreach (
$result as $idx => $item) {
568 if (isset($usr_multi[$item[
"usr_id"]])) {
569 $result[$idx] = array_merge($item, $usr_multi[$item[
"usr_id"]]);
573 return array(
"cnt" => $cnt,
"set" =>
$result);
586 $a_string_filter =
"",
587 $a_activation_filter =
"",
588 $a_last_login_filter = null,
589 $a_limited_access_filter =
false,
590 $a_no_courses_filter =
false,
591 $a_course_group_filter = 0,
593 $a_user_folder_filter = null,
594 $a_additional_fields =
'',
595 $a_user_filter = null,
596 $a_first_letter =
"",
597 $a_authentication_filter = null
600 $query->setOrderField($a_order_field);
601 $query->setOrderDirection($a_order_dir);
602 $query->setOffset($a_offset);
603 $query->setLimit($a_limit);
604 $query->setTextFilter($a_string_filter);
605 $query->setActionFilter($a_activation_filter);
606 $query->setLastLogin($a_last_login_filter);
607 $query->setLimitedAccessFilter($a_limited_access_filter);
608 $query->setNoCourseFilter($a_no_courses_filter);
609 $query->setCourseGroupFilter($a_course_group_filter);
610 $query->setRoleFilter($a_role_filter);
611 $query->setUserFolder($a_user_folder_filter);
612 $query->setAdditionalFields($a_additional_fields);
613 $query->setUserFilter($a_user_filter);
614 $query->setFirstLetterLastname($a_first_letter);
615 $query->setAuthenticationFilter($a_authentication_filter);
getUdfFilter()
Get udf filter.
static _getInstance()
Get instance.
setFirstLetterLastname($a_fll)
set first letter lastname filter
setUdfFilter($a_val)
Set udf filter.
setOffset($a_offset)
Set offset.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
setCourseGroupFilter($a_cg_id)
Set course / group filter object_id of course or group.
setRoleFilter($a_role_id)
Set role filter obj_id of role.
setNoCourseFilter($a_no_course)
Enable no course filter.
if(!array_key_exists('StateId', $_REQUEST)) $id
setUserFilter($a_filter)
Array with user ids to query against.
__construct()
Constructor.
setActionFilter($a_activation)
Set activation filter 'active' or 'inactive' or empty.
const DEFAULT_ORDER_FIELD
setAccessFilter($a_access)
set filter for user that are limited but has access
setOrderField($a_order)
Set order field (column in usr_data) Default order is 'login'.
setAuthenticationFilter($a_authentication)
Set authentication filter 'default', 'local' or 'lti'.
setLimitedAccessFilter($a_status)
Enable limited access filter.
setNoGroupFilter($a_no_group)
Enable no group filter.
static _lookupType($a_id, $a_reference=false)
lookup object type
setOrderDirection($a_dir)
Set order direction 'asc' or 'desc' Default is 'asc'.
setLimit($a_limit)
Set result limit Default is 50.
setTextFilter($a_filter)
Text (like) filter in login, firstname, lastname or email.
setUserFolder($a_fold_id)
Set user folder filter reference id of user folder or category (local user administration) ...
setLastLogin(ilDateTime $dt=null)
Set last login filter.
setAdditionalFields($a_add)
Set additional fields (columns in usr_data or 'online_time')
static getUserListData( $a_order_field, $a_order_dir, $a_offset, $a_limit, $a_string_filter="", $a_activation_filter="", $a_last_login_filter=null, $a_limited_access_filter=false, $a_no_courses_filter=false, $a_course_group_filter=0, $a_role_filter=0, $a_user_folder_filter=null, $a_additional_fields='', $a_user_filter=null, $a_first_letter="", $a_authentication_filter=null)
Get data for user administration list.