ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilMStListUsers.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31{
32 private Container $dic;
33
38 public function __construct(Container $dic)
39 {
40 $this->dic = $dic;
41 }
42
43 final public function getData(array $arr_usr_ids = array(), array $options = array()): ListFetcherResult
44 {
45 //Permissions
46 if (count($arr_usr_ids) == 0) {
47 return new ListFetcherResult([], 0);
48 }
49
50 $_options = array(
51 'filters' => array(),
52 'sort' => array(),
53 'limit' => array(),
54 'count' => false,
55 );
56 $options = array_merge($_options, $options);
57
58 $select = 'SELECT
59 usr_id,
60 login,
61 gender,
62 firstname,
63 lastname,
64 title,
65 institution,
66 department,
67 street,
68 zipcode,
69 city,
70 country,
71 hobby,
72 email,
73 second_email,
74 matriculation,
75 active
76 FROM ' . $this->dic->database()->quoteIdentifier('usr_data') .
77
78 self::createWhereStatement($arr_usr_ids, $options['filters']);
79
80 $result = $this->dic->database()->query($select);
81 $numRows = $this->dic->database()->numRows($result);
82
83 if ($options['sort']) {
84 $select .= " ORDER BY " . $options['sort']['field'] . " " . $options['sort']['direction'];
85 }
86
87 if (isset($options['limit']['start']) && isset($options['limit']['end'])) {
88 $select .= " LIMIT " . $options['limit']['start'] . "," . $options['limit']['end'];
89 }
90
91 $result = $this->dic->database()->query($select);
92 $user_data = array();
93
94 while ($user = $this->dic->database()->fetchAssoc($result)) {
95 $list_user = new ilMStListUser();
96 $list_user->setUsrId(intval($user['usr_id']));
97 $list_user->setGender($user['gender'] ?? "");
98 $list_user->setTitle($user['title'] ?? "");
99 $list_user->setInstitution($user['institution'] ?? "");
100 $list_user->setDepartment($user['department'] ?? "");
101 $list_user->setStreet($user['street'] ?? "");
102 $list_user->setZipcode($user['zipcode'] ?? "");
103 $list_user->setCity($user['city'] ?? "");
104 $list_user->setCountry($user['country'] ?? "");
105 $list_user->setHobby($user['hobby'] ?? "");
106 $list_user->setMatriculation($user['matriculation'] ?? "");
107 $list_user->setActive(intval($user['active']));
108 $list_user->setLogin($user['login']);
109 $list_user->setFirstname($user['firstname']);
110 $list_user->setLastname($user['lastname']);
111 $list_user->setEmail($user['email'] ?? "");
112 $list_user->setSecondEmail($user['second_email'] ?? "");
113
114 $user_data[] = $list_user;
115 }
116
117 return new ListFetcherResult($user_data, $numRows);
118 }
119
123 private function createWhereStatement(array $arr_usr_ids, array $arr_filter): string
124 {
125 $where = array();
126
127 $where[] = $this->dic->database()->in('usr_data.usr_id', $arr_usr_ids, false, 'integer');
128
129 if (!empty($arr_filter['user'])) {
130 $where[] = "(" . $this->dic->database()
131 ->like(
132 "usr_data.login",
133 "text",
134 "%" . $arr_filter['user'] . "%"
135 ) . " " . "OR " . $this->dic->database()
136 ->like(
137 "usr_data.firstname",
138 "text",
139 "%" . $arr_filter['user'] . "%"
140 ) . " " . "OR " . $this->dic->database()
141 ->like(
142 "usr_data.lastname",
143 "text",
144 "%" . $arr_filter['user'] . "%"
145 ) . " " . "OR " . $this->dic->database()
146 ->like(
147 "usr_data.email",
148 "text",
149 "%" . $arr_filter['user'] . "%"
150 ) . " " . "OR " . $this->dic->database()
151 ->like(
152 "usr_data.second_email",
153 "text",
154 "%" . $arr_filter['user'] . "%"
155 ) . ") ";
156 }
157
158 if (!empty($arr_filter['org_unit'])) {
159 $where[] = 'usr_data.usr_id IN (SELECT user_id FROM il_orgu_ua WHERE orgu_id = ' . $this->dic->database()
160 ->quote(
161 $arr_filter['org_unit'],
162 'integer'
163 ) . ')';
164 }
165
166 if (!empty($arr_filter['lastname'])) {
167 $where[] = '(lastname LIKE ' . $this->dic->database()->quote('%' . str_replace(
168 '*',
169 '%',
170 $arr_filter['lastname']
171 ) . '%', 'text') . ')';
172 }
173
174 if (!empty($arr_filter['firstname'])) {
175 $where[] = '(firstname LIKE ' . $this->dic->database()->quote('%' . str_replace(
176 '*',
177 '%',
178 $arr_filter['firstname']
179 ) . '%', 'text') . ')';
180 }
181
182 if (!empty($arr_filter['email'])) {
183 $where[] = '(email LIKE ' . $this->dic->database()->quote('%' . str_replace(
184 '*',
185 '%',
186 $arr_filter['email']
187 ) . '%', 'text') . ')';
188 }
189
190 if (!empty($arr_filter['second_email'])) {
191 $where[] = '(second_email LIKE ' . $this->dic->database()->quote('%' . str_replace(
192 '*',
193 '%',
194 $arr_filter['second_email']
195 ) . '%', 'text') . ')';
196 }
197
198 if (!empty($arr_filter['title'])) {
199 $where[] = '(title LIKE ' . $this->dic->database()->quote('%' . str_replace(
200 '*',
201 '%',
202 $arr_filter['title']
203 ) . '%', 'text') . ')';
204 }
205
206 if ($arr_filter['activation'] ?? false) {
207 if ($arr_filter['activation'] == 'active') {
208 $where[] = '(active = "1")';
209 }
210 if ($arr_filter['activation'] == 'inactive') {
211 $where[] = '(active = "0")';
212 }
213 }
214
215 if (!empty($where)) {
216 return ' WHERE ' . implode(' AND ', $where) . ' ';
217 } else {
218 return '';
219 }
220 }
221}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
createWhereStatement(array $arr_usr_ids, array $arr_filter)
Returns the WHERE Part for the Queries using parameter $user_ids AND local variable $filters.
getData(array $arr_usr_ids=array(), array $options=array())
__construct(Container $dic)
ilMStListUsers constructor.