17 public static function getUserListData($a_order_field, $a_order_dir, $a_offset, $a_limit,
18 $a_string_filter =
"", $a_activation_filter =
"", $a_last_login_filter = null,
19 $a_limited_access_filter =
false, $a_no_courses_filter =
false,
20 $a_course_group_filter = 0, $a_role_filter = 0, $a_user_folder_filter = null,
21 $a_additional_fields =
'', $a_user_filter = null, $a_first_letter =
"")
23 global
$ilDB, $rbacreview;
25 $fields = array(
"usr_id",
"login",
"firstname",
"lastname",
"email",
26 "time_limit_until",
"time_limit_unlimited",
"time_limit_owner",
"last_login",
"active");
29 if (is_array($a_additional_fields))
31 foreach ($a_additional_fields as $f)
33 if (!in_array($f, $fields))
35 if($f ==
"online_time")
37 $fields[] =
"ut_online.online_time";
38 $ut_join =
" LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id";
49 $count_query =
"SELECT count(usr_id) cnt".
52 $sql_fields = array();
53 foreach($fields as $idx => $field)
55 if(!stristr($field,
"."))
57 $sql_fields[] =
"usr_data.".$field;
61 $sql_fields[] = $field;
66 $query =
"SELECT ".implode($sql_fields,
",").
71 $query.=
" WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
74 if($a_user_filter and is_array(($a_user_filter)))
76 $query .=
' AND '.$ilDB->in(
'usr_data.usr_id',$a_user_filter,
false,
'integer');
79 $count_query.=
" WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
82 if ($a_first_letter !=
"")
84 $add = $where.
" (".$ilDB->upper($ilDB->substr(
"usr_data.lastname", 1, 1)).
" = ".$ilDB->upper($ilDB->quote($a_first_letter,
"text")).
") ";
90 if ($a_string_filter !=
"")
92 $add = $where.
" (".$ilDB->like(
"usr_data.login",
"text",
"%".$a_string_filter.
"%").
" ".
93 "OR ".$ilDB->like(
"usr_data.firstname",
"text",
"%".$a_string_filter.
"%").
" ".
94 "OR ".$ilDB->like(
"usr_data.lastname",
"text",
"%".$a_string_filter.
"%").
" ".
95 "OR ".$ilDB->like(
"usr_data.email",
"text",
"%".$a_string_filter.
"%").
") ";
100 if ($a_activation_filter !=
"")
102 if ($a_activation_filter ==
"inactive")
104 $add = $where.
" usr_data.active = ".$ilDB->quote(0,
"integer").
" ";
108 $add = $where.
" usr_data.active = ".$ilDB->quote(1,
"integer").
" ";
115 if (is_object($a_last_login_filter))
117 if ($a_last_login_filter->get(
IL_CAL_UNIX) < time())
119 $add = $where.
" usr_data.last_login < ".
126 if ($a_limited_access_filter)
128 $add = $where.
" usr_data.time_limit_unlimited= ".$ilDB->quote(0,
"integer");
133 if ($a_no_courses_filter)
135 $add = $where.
" usr_data.usr_id NOT IN (".
136 "SELECT DISTINCT ud.usr_id ".
137 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
138 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
139 "WHERE od.title LIKE 'il_crs_%')";
144 if ($a_course_group_filter > 0)
147 $add = $where.
" usr_data.usr_id IN (".
148 "SELECT DISTINCT ud.usr_id ".
149 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
150 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
151 "WHERE od.title = ".$ilDB->quote(
"il_".$cgtype.
"_member_".$a_course_group_filter,
"text").
")";
156 if ($a_role_filter > 0)
158 $add = $where.
" usr_data.usr_id IN (".
159 "SELECT DISTINCT ud.usr_id ".
160 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
161 "WHERE rbac_ua.rol_id = ".$ilDB->quote($a_role_filter,
"integer").
")";
167 if(!is_null($a_user_folder_filter))
169 $add = $where.
" ".$ilDB->in(
'usr_data.time_limit_owner',$a_user_folder_filter,
false,
'integer');
176 switch($a_order_field)
179 if ($a_order_dir ==
"desc")
181 $query.=
" ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
185 $query.=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
190 if ($a_order_dir ==
"desc")
192 $query.=
" ORDER BY ut_online.online_time DESC";
196 $query.=
" ORDER BY ut_online.online_time ASC";
201 if (!in_array($a_order_field, $fields))
203 $a_order_field =
"login";
205 if ($a_order_dir !=
"asc" && $a_order_dir !=
"desc")
207 $a_order_dir =
"asc";
209 $query .=
" ORDER BY usr_data.".$a_order_field.
" ".strtoupper($a_order_dir);
214 $set = $ilDB->query($count_query);
216 if ($rec = $ilDB->fetchAssoc($set))
221 $offset = (int) $a_offset;
222 $limit = (int) $a_limit;
230 $ilDB->setLimit($limit, $offset);
233 $set = $ilDB->query(
$query);
235 while($rec = $ilDB->fetchAssoc($set))
239 return array(
"cnt" => $cnt,
"set" =>
$result);