Query usr_data.
209 {
211
212 $ut_join = "";
213 if (is_array($this->additional_fields))
214 {
215 foreach ($this->additional_fields as $f)
216 {
217 if (!in_array($f, $this->default_fields))
218 {
219 if($f == "online_time")
220 {
221 $this->default_fields[] = "ut_online.online_time";
222 $ut_join = " LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id";
223 }
224 else
225 {
226 $this->default_fields[] = $f;
227 }
228 }
229 }
230 }
231
232 $count_query = "SELECT count(usr_id) cnt".
233 " FROM usr_data";
234
235 $all_multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
236 $multi_fields = array();
237
238 $sql_fields = array();
239 foreach($this->default_fields as $idx => $field)
240 {
241 if(!$field)
242 {
243 continue;
244 }
245
246 if(in_array($field, $all_multi_fields))
247 {
248 $multi_fields[] = $field;
249 }
250 else if(!stristr($field, "."))
251 {
252 $sql_fields[] = "usr_data.".$field;
253 }
254 else
255 {
256 $sql_fields[] = $field;
257 }
258 }
259
260
261 $query =
"SELECT ".implode($sql_fields,
",").
262 " FROM usr_data".
263 $ut_join;
264
265
266 $query.=
" WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
267
268
269 if($this->users and is_array(($this->users)))
270 {
271 $query .=
' AND '.$ilDB->in(
'usr_data.usr_id',$this->users,
false,
'integer');
272 }
273
274 $count_query.= " WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
275 $where = " AND";
276
277 if ($this->first_letter != "")
278 {
279 $add = $where.
" (".
$ilDB->upper(
$ilDB->substr(
"usr_data.lastname", 1, 1)).
" = ".
$ilDB->upper(
$ilDB->quote($this->first_letter,
"text")).
") ";
281 $count_query.= $add;
282 $where = " AND";
283 }
284
285 if ($this->text_filter != "")
286 {
287 $add = $where.
" (".
$ilDB->like(
"usr_data.login",
"text",
"%".$this->text_filter.
"%").
" ".
288 "OR ".$ilDB->like("usr_data.firstname", "text", "%".$this->text_filter."%")." ".
289 "OR ".$ilDB->like("usr_data.lastname", "text", "%".$this->text_filter."%")." ".
290 "OR ".$ilDB->like("usr_data.email", "text", "%".$this->text_filter."%").") ";
292 $count_query.= $add;
293 $where = " AND";
294 }
295
296 if ($this->activation != "")
297 {
298 if ($this->activation == "inactive")
299 {
300 $add = $where.
" usr_data.active = ".
$ilDB->quote(0,
"integer").
" ";
301 }
302 else
303 {
304 $add = $where.
" usr_data.active = ".
$ilDB->quote(1,
"integer").
" ";
305 }
307 $count_query.= $add;
308 $where = " AND";
309 }
310
312 {
314 {
315 $add = $where." usr_data.last_login < ".
318 $count_query.= $add;
319 $where = " AND";
320 }
321 }
322 if ($this->limited_access)
323 {
324 $add = $where.
" usr_data.time_limit_unlimited= ".
$ilDB->quote(0,
"integer");
326 $count_query.= $add;
327 $where = " AND";
328 }
329 if ($this->no_courses)
330 {
331 $add = $where." usr_data.usr_id NOT IN (".
332 "SELECT DISTINCT ud.usr_id ".
333 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
334 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
335 "WHERE od.title LIKE 'il_crs_%')";
337 $count_query.= $add;
338 $where = " AND";
339 }
340 if ($this->no_groups)
341 {
342 $add = $where." usr_data.usr_id NOT IN (".
343 "SELECT DISTINCT ud.usr_id ".
344 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
345 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
346 "WHERE od.title LIKE 'il_grp_%')";
348 $count_query.= $add;
349 $where = " AND";
350 }
351 if ($this->crs_grp > 0)
352 {
354 $add = $where." usr_data.usr_id IN (".
355 "SELECT DISTINCT ud.usr_id ".
356 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
357 "JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
358 "WHERE od.title = ".$ilDB->quote("il_".$cgtype."_member_".$this->crs_grp, "text").")";
360 $count_query.= $add;
361 $where = " AND";
362 }
363 if ($this->role > 0)
364 {
365 $add = $where." usr_data.usr_id IN (".
366 "SELECT DISTINCT ud.usr_id ".
367 "FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
368 "WHERE rbac_ua.rol_id = ".$ilDB->quote($this->role, "integer").")";
370 $count_query.= $add;
371 $where = " AND";
372 }
373
374 if($this->user_folder)
375 {
376 $add = $where.
" ".
$ilDB->in(
'usr_data.time_limit_owner',$this->user_folder,
false,
'integer');
378 $count_query.= $add;
379 $where = " AND";
380 }
381
382
383 switch($this->order_field)
384 {
385 case "access_until":
386 if ($this->order_dir == "desc")
387 {
388 $query.=
" ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
389 }
390 else
391 {
392 $query.=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
393 }
394 break;
395
396 case "online_time":
397 if ($this->order_dir == "desc")
398 {
399 $query.=
" ORDER BY ut_online.online_time DESC";
400 }
401 else
402 {
403 $query.=
" ORDER BY ut_online.online_time ASC";
404 }
405 break;
406
407 default:
408 if (!in_array($this->order_field, $this->default_fields))
409 {
410 $this->order_field = "login";
411 }
412 if ($this->order_dir != "asc" && $this->order_dir != "desc")
413 {
414 $this->order_dir = "asc";
415 }
416 $query .=
" ORDER BY usr_data.".$this->order_field.
" ".strtoupper($this->order_dir);
417 break;
418 }
419
420
421 $set =
$ilDB->query($count_query);
422 $cnt = 0;
423 if ($rec =
$ilDB->fetchAssoc($set))
424 {
425 $cnt = $rec["cnt"];
426 }
427
429 $limit = (int) $this->limit;
430
431
433 {
435 }
436
438
439 if(sizeof($multi_fields))
440 {
441 $usr_ids = array();
442 }
443
444
447 while($rec =
$ilDB->fetchAssoc($set))
448 {
450
451 if(sizeof($multi_fields))
452 {
453 $usr_ids[] = $rec["usr_id"];
454 }
455 }
456
457
458 if(sizeof($multi_fields) && sizeof($usr_ids))
459 {
460 $usr_multi = array();
461 $set =
$ilDB->query(
"SELECT * FROM usr_data_multi".
462 " WHERE ".
$ilDB->in(
"usr_id", $usr_ids,
"",
"integer"));
464 {
465 $usr_multi[
$row[
"usr_id"]][
$row[
"field_id"]][] =
$row[
"value"];
466 }
467 foreach(
$result as $idx => $item)
468 {
469 if(isset($usr_multi[$item["usr_id"]]))
470 {
471 $result[$idx] = array_merge($item, $usr_multi[$item[
"usr_id"]]);
472 }
473 }
474 }
475
476 return array(
"cnt" => $cnt,
"set" =>
$result);
477 }
@classDescription Date and time handling
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.
static _lookupType($a_id, $a_reference=false)
lookup object type