Query usr_data.
275 {
277
279
280
281 $udf_fields = array();
282
283 $join = "";
284
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);
293 } else {
294 $this->default_fields[] =
$f;
295 }
296 }
297 }
298 }
299
300
301 $udf_def = array();
302 if (count($udf_fields) > 0) {
303 include_once './Services/User/classes/class.ilUserDefinedFields.php';
305 }
306
307
308 foreach ($udf_fields as $id) {
310 ? "udf_text"
311 : "udf_clob";
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) ";
313 }
314
315
316 $count_query = "SELECT count(usr_data.usr_id) cnt" .
317 " FROM usr_data";
318
319 $all_multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
320 $multi_fields = array();
321
322 $sql_fields = array();
323 foreach ($this->default_fields as $idx => $field) {
324 if (!$field) {
325 continue;
326 }
327
328 if (in_array($field, $all_multi_fields)) {
329 $multi_fields[] = $field;
330 } elseif (!stristr($field, ".")) {
331 $sql_fields[] = "usr_data." . $field;
332 } else {
333 $sql_fields[] = $field;
334 }
335 }
336
337
338 foreach ($udf_fields as $id) {
339 $sql_fields[] = "ud_" . $id . ".value udf_" . $id;
340 }
341
342
343 $query =
"SELECT " . implode(
",", $sql_fields) .
344 " FROM usr_data" .
345 $join;
346
347 $count_query = $count_query . " " .
348 $join;
349
350
351 $query .=
" WHERE usr_data.usr_id <> " .
$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
352
353
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');
359 }
360
361 $count_query .= " AND " . $count_user_filter . " ";
362 $where = " AND";
363
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;
368 $where = " AND";
369 }
370
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;
379 $where = " AND";
380 }
381
382 if ($this->activation != "") {
383 if ($this->activation == "inactive") {
384 $add = $where .
" usr_data.active = " .
$ilDB->quote(0,
"integer") .
" ";
385 } else {
386 $add = $where .
" usr_data.active = " .
$ilDB->quote(1,
"integer") .
" ";
387 }
389 $count_query .= $add;
390 $where = " AND";
391 }
392
393 if ($this->last_login instanceof
ilDateTime) {
395 $add = $where . " usr_data.last_login < " .
398 $count_query .= $add;
399 $where = " AND";
400 }
401 }
402 if ($this->limited_access) {
403 $add = $where .
" usr_data.time_limit_unlimited= " .
$ilDB->quote(0,
"integer");
405 $count_query .= $add;
406 $where = " AND";
407 }
408
409
412 $udf_id = explode("_", $k)[1];
414 $add = $where .
" " .
$ilDB->like(
"ud_" . $udf_id .
".value",
"text",
"%" .
$f .
"%");
415 } else {
416 $add = $where .
" ud_" . $udf_id .
".value = " .
$ilDB->quote(
$f,
"text");
417 }
419 $count_query .= $add;
420 $where = " AND";
421 }
422 }
423
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');
428
429 $add = $where . ' (' . $unlimited . ' OR (' . $from . ' AND ' . $until . '))';
431 $count_query .= $add;
432 $where = " AND";
433 }
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;
442 $where = " AND";
443 }
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;
452 $where = " AND";
453 }
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;
463 $where = " AND";
464 }
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;
472 $where = " AND";
473 }
474
475 if ($this->user_folder) {
476 $add = $where .
" " .
$ilDB->in(
'usr_data.time_limit_owner', $this->user_folder,
false,
'integer');
478 $count_query .= $add;
479 $where = " AND";
480 }
481
482 if ($this->authentication_method != "") {
483 $add = $where .
" usr_data.auth_mode = " .
$ilDB->quote($this->authentication_method,
"text") .
" ";
485 $count_query .= $add;
486 $where = " AND";
487 }
488
489
490 switch ($this->order_field) {
491 case "access_until":
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";
494 } else {
495 $query .=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
496 }
497 break;
498
499 case "online_time":
500 if ($this->order_dir == "desc") {
501 $query .=
" ORDER BY ut_online.online_time DESC";
502 } else {
503 $query .=
" ORDER BY ut_online.online_time ASC";
504 }
505 break;
506
507 default:
508 if ($this->order_dir != "asc" && $this->order_dir != "desc") {
509 $this->order_dir = "asc";
510 }
511 if (substr($this->order_field, 0, 4) == "udf_") {
512
514 $query .=
" ORDER BY ud_" . ((int) substr($this->order_field, 4)) .
".value " . strtoupper($this->order_dir);
515 } else {
516 $query .=
' ORDER BY ' . self::DEFAULT_ORDER_FIELD .
' ' . strtoupper($this->order_dir);
517 }
518 } else {
519 if (!in_array($this->order_field, $this->default_fields)) {
520 $this->order_field = "login";
521 }
522 $query .=
" ORDER BY usr_data." . $this->order_field .
" " . strtoupper($this->order_dir);
523 }
524 break;
525 }
526
527
528 $set =
$ilDB->query($count_query);
529 $cnt = 0;
530 if ($rec =
$ilDB->fetchAssoc($set)) {
531 $cnt = $rec["cnt"];
532 }
533
535 $limit = (int) $this->limit;
536
537
540 }
541
543
544 if (sizeof($multi_fields)) {
545 $usr_ids = array();
546 }
547
548
551
552 while ($rec =
$ilDB->fetchAssoc($set)) {
554 if (sizeof($multi_fields)) {
555 $usr_ids[] = $rec["usr_id"];
556 }
557 }
558
559
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"));
564 while ($row =
$ilDB->fetchAssoc($set)) {
565 $usr_multi[$row["usr_id"]][$row["field_id"]][] = $row["value"];
566 }
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"]]);
570 }
571 }
572 }
573 return array(
"cnt" => $cnt,
"set" =>
$result);
574 }
@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
static _getInstance()
Get instance.
getUdfFilter()
Get udf filter.