ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMStListCourses.php
Go to the documentation of this file.
1<?php
2
9{
10
17 public static function getData(array $arr_usr_ids = array(), array $options = array())
18 {
19 global $DIC;
20
21 //Permission Filter
23
24 if (!empty($options['filters']['lp_status']) || $options['filters']['lp_status'] === 0) {
26 }
27 $tmp_table_user_matrix = ilMyStaffAccess::getInstance()->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($DIC->user()
29
30 $_options = array(
31 'filters' => array(),
32 'sort' => array(),
33 'limit' => array(),
34 'count' => false,
35 );
36 $options = array_merge($_options, $options);
37
38 $select = 'SELECT crs_ref.ref_id AS crs_ref_id, crs.title AS crs_title, reg_status, lp_status, usr_data.usr_id AS usr_id, usr_data.login AS usr_login, usr_data.lastname AS usr_lastname, usr_data.firstname AS usr_firstname, usr_data.email AS usr_email FROM (
39 SELECT reg.obj_id, reg.usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED . ' AS reg_status, lp.status AS lp_status FROM obj_members
40 AS reg
41 LEFT JOIN ut_lp_marks AS lp on lp.obj_id = reg.obj_id AND lp.usr_id = reg.usr_id
42 WHERE ' . $DIC->database()->in('reg.usr_id', $arr_usr_ids, false, 'integer') . '
43 UNION
44 SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST . ' AS reg_status, 0 AS lp_status FROM crs_waiting_list AS waiting
45 WHERE ' . $DIC->database()->in('waiting.usr_id', $arr_usr_ids, false, 'integer') . '
46 UNION
47 SELECT obj_id, usr_id, ' . ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED . ' AS reg_status, 0 AS lp_status FROM il_subscribers AS requested
48 WHERE ' . $DIC->database()->in('requested.usr_id', $arr_usr_ids, false, 'integer') . '
49 ) AS memb
50
51 INNER JOIN object_data AS crs on crs.obj_id = memb.obj_id AND crs.type = ' . $DIC->database()
52 ->quote(ilMyStaffAccess::DEFAULT_CONTEXT, 'text') . '
53 INNER JOIN object_reference AS crs_ref on crs_ref.obj_id = crs.obj_id
54 INNER JOIN usr_data on usr_data.usr_id = memb.usr_id AND usr_data.active = 1';
55
56 $select .= static::createWhereStatement($arr_usr_ids, $options['filters'], $tmp_table_user_matrix);
57
58 if ($options['count']) {
59 $result = $DIC->database()->query($select);
60
61 return $DIC->database()->numRows($result);
62 }
63
64 if ($options['sort']) {
65 $select .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
66 }
67
68 if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
69 $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
70 }
71 $result = $DIC->database()->query($select);
72 $crs_data = array();
73
74 while ($crs = $DIC->database()->fetchAssoc($result)) {
75 $list_course = new ilMStListCourse();
76 $list_course->setCrsRefId($crs['crs_ref_id']);
77 $list_course->setCrsTitle($crs['crs_title']);
78 $list_course->setUsrRegStatus($crs['reg_status']);
79 $list_course->setUsrLpStatus($crs['lp_status']);
80 $list_course->setUsrLogin($crs['usr_login']);
81 $list_course->setUsrLastname($crs['usr_lastname']);
82 $list_course->setUsrFirstname($crs['usr_firstname']);
83 $list_course->setUsrEmail($crs['usr_email']);
84 $list_course->setUsrId($crs['usr_id']);
85
86 $crs_data[] = $list_course;
87 }
88
89 return $crs_data;
90 }
91
92
102 protected static function createWhereStatement(array $arr_usr_ids, array $arr_filter, $tmp_table_user_matrix)
103 {
104 global $DIC;
105
106 $where = array();
107
108 $where[] = '(crs_ref.ref_id, usr_data.usr_id) IN (SELECT * FROM ' . $tmp_table_user_matrix . ')';
109
110 if (count($arr_usr_ids)) {
111 $where[] = $DIC->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer');
112 }
113
114 if (!empty($arr_filter['crs_title'])) {
115 $where[] = '(crs.title LIKE ' . $DIC->database()->quote('%' . $arr_filter['crs_title'] . '%', 'text') . ')';
116 }
117
118 if ($arr_filter['course'] > 0) {
119 $where[] = '(crs_ref.ref_id = ' . $DIC->database()->quote($arr_filter['course'], 'integer') . ')';
120 }
121
122 if (!empty($arr_filter['lp_status']) || $arr_filter['lp_status'] === 0) {
123 switch ($arr_filter['lp_status']) {
125 //if a user has the lp status not attempted it could be, that the user hase no records in table ut_lp_marks
126 $where[] = '(lp_status = ' . $DIC->database()->quote($arr_filter['lp_status'], 'integer') . ' OR lp_status is NULL)';
127 break;
128 default:
129 $where[] = '(lp_status = ' . $DIC->database()->quote($arr_filter['lp_status'], 'integer') . ')';
130 break;
131 }
132 }
133
134 if (!empty($arr_filter['memb_status'])) {
135 $where[] = '(reg_status = ' . $DIC->database()->quote($arr_filter['memb_status'], 'integer') . ')';
136 }
137
138 if (!empty($arr_filter['user'])) {
139 $where[] = "(" . $DIC->database()->like("usr_data.login", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database()
140 ->like("usr_data.firstname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database()
141 ->like("usr_data.lastname", "text", "%" . $arr_filter['user'] . "%") . " " . "OR " . $DIC->database()
142 ->like("usr_data.email", "text", "%" . $arr_filter['user'] . "%") . ") ";
143 }
144
145 if (!empty($arr_filter['org_unit'])) {
146 $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $DIC->database()
147 ->quote($arr_filter['org_unit'], 'integer') . ')';
148 }
149
150 if (!empty($where)) {
151 return ' WHERE ' . implode(' AND ', $where) . ' ';
152 } else {
153 return '';
154 }
155 }
156}
$result
An exception for terminatinating execution or to throw for unit testing.
const LP_STATUS_NOT_ATTEMPTED_NUM
Class ilMStListCourse.
Class ilMStListCourses.
static createWhereStatement(array $arr_usr_ids, array $arr_filter, $tmp_table_user_matrix)
Returns the WHERE Part for the Queries using parameter $user_ids AND local variable $filters.
static getData(array $arr_usr_ids=array(), array $options=array())
const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX
global $DIC
Definition: saml.php:7