ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestParticipantData.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
16 protected $db;
17
21 protected $lng;
22
27
32
37
41 private $byActiveId;
42
46 private $byUserId;
47
52
57
62
64 {
65 $this->db = $db;
66 $this->lng = $lng;
67
68 $this->activeIdsFilter = array();
69 $this->userIdsFilter = array();
70 $this->anonymousIdsFilter = array();
71
72 $this->byActiveId = array();
73 $this->byUserId = array();
74 $this->byAnonymousId = array();
75
76 $this->scoredParticipantsFilterEnabled = false;
77 }
78
83 {
85 }
86
91 {
92 $this->participantAccessFilter = $participantAccessFilter;
93 }
94
99 {
101 }
102
107 {
108 $this->scoredParticipantsFilterEnabled = $scoredParticipantsFilterEnabled;
109 }
110
111 public function load($testId)
112 {
113 $this->byActiveId = array();
114 $this->byUserId = array();
115
116 $query = "
117 SELECT ta.active_id,
118 ta.user_fi user_id,
119 ta.anonymous_id,
120 ud.firstname,
121 ud.lastname,
122 ud.login,
123 ud.matriculation
124 FROM tst_active ta
125 LEFT JOIN usr_data ud
126 ON ud.usr_id = ta.user_fi
127 WHERE test_fi = %s
128 AND {$this->getConditionalExpression()}
129 AND {$this->getScoredParticipantsFilterExpression()}
130 ";
131
132 $res = $this->db->queryF($query, array('integer'), array($testId));
133
134 $rows = array();
135 $accessFilteredUsrIds = array();
136
137 while ($row = $this->db->fetchAssoc($res)) {
138 $accessFilteredUsrIds[] = $row['user_id'];
139 $rows[] = $row;
140 }
141
142 if (is_callable($this->getParticipantAccessFilter(), true)) {
143 $accessFilteredUsrIds = call_user_func_array($this->getParticipantAccessFilter(), [$accessFilteredUsrIds]);
144 }
145
146 foreach ($rows as $row) {
147 if (!in_array($row['user_id'], $accessFilteredUsrIds)) {
148 continue;
149 }
150
151 $this->byActiveId[ $row['active_id'] ] = $row;
152
153 if ($row['user_id'] == ANONYMOUS_USER_ID) {
154 $this->byAnonymousId[ $row['anonymous_id'] ] = $row;
155 } else {
156 $this->byUserId[ $row['user_id'] ] = $row;
157 }
158 }
159 }
160
162 {
164 return "ta.last_finished_pass = ta.last_started_pass";
165 }
166
167 return '1 = 1';
168 }
169
170 public function getConditionalExpression()
171 {
172 $conditions = array();
173
174 if (count($this->getActiveIdsFilter())) {
175 $conditions[] = $this->db->in('active_id', $this->getActiveIdsFilter(), false, 'integer');
176 }
177
178 if (count($this->getUserIdsFilter())) {
179 $conditions[] = $this->db->in('user_fi', $this->getUserIdsFilter(), false, 'integer');
180 }
181
182 if (count($this->getAnonymousIdsFilter())) {
183 $conditions[] = $this->db->in('anonymous_id', $this->getAnonymousIdsFilter(), false, 'integer');
184 }
185
186 if (count($conditions)) {
187 return '(' . implode(' OR ', $conditions) . ')';
188 }
189
190 return '1 = 1';
191 }
192
194 {
195 $this->activeIdsFilter = $activeIdsFilter;
196 }
197
198 public function getActiveIdsFilter()
199 {
201 }
202
204 {
205 $this->userIdsFilter = $userIdsFilter;
206 }
207
208 public function getUserIdsFilter()
209 {
211 }
212
214 {
215 $this->anonymousIdsFilter = $anonymousIdsFilter;
216 }
217
218 public function getAnonymousIdsFilter()
219 {
221 }
222
223 public function getActiveIds()
224 {
225 return array_keys($this->byActiveId);
226 }
227
228 public function getUserIds()
229 {
230 return array_keys($this->byUserId);
231 }
232
233 public function getAnonymousIds()
234 {
235 return array_keys($this->byAnonymousId);
236 }
237
238 public function getUserIdByActiveId($activeId)
239 {
240 return $this->byActiveId[$activeId]['user_id'];
241 }
242
243 public function getActiveIdByUserId($userId)
244 {
245 return $this->byUserId[$userId]['active_id'];
246 }
247
248 public function getConcatedFullnameByActiveId($activeId)
249 {
250 return "{$this->byActiveId[$activeId]['firstname']} {$this->byActiveId[$activeId]['lastname']}";
251 }
252
253 public function getFormatedFullnameByActiveId($activeId)
254 {
255 return $this->buildFormatedFullname($this->byActiveId[$activeId]);
256 }
257
259 {
260 $fullname = str_replace(' ', '', $this->byActiveId[$activeId]['lastname']);
261 $fullname .= '_' . str_replace(' ', '', $this->byActiveId[$activeId]['firstname']);
262 $fullname .= '_' . $this->byActiveId[$activeId]['login'];
263
264 return ilUtil::getASCIIFilename($fullname);
265 }
266
267 public function getOptionArray()
268 {
269 $options = array();
270
271 foreach ($this->byActiveId as $activeId => $usrData) {
272 $options[$activeId] = $this->buildFormatedFullname($usrData);
273 }
274
275 asort($options);
276
277 return $options;
278 }
279
280 private function buildFormatedFullname($usrData)
281 {
282 return sprintf(
283 $this->lng->txt('tst_participant_fullname_pattern'),
284 $usrData['firstname'],
285 $usrData['lastname']
286 );
287 }
288
289 public function getAnonymousActiveIds()
290 {
291 $anonymousActiveIds = array();
292
293 foreach ($this->byActiveId as $activeId => $active) {
294 if ($active['user_id'] == ANONYMOUS_USER_ID) {
295 $anonymousActiveIds[] = $activeId;
296 }
297 }
298
299 return $anonymousActiveIds;
300 }
301
302 public function getUserDataByActiveId($activeId)
303 {
304 if (isset($this->byActiveId[$activeId])) {
305 return $this->byActiveId[$activeId];
306 }
307
308 return null;
309 }
310}
An exception for terminatinating execution or to throw for unit testing.
language handling
setScoredParticipantsFilterEnabled($scoredParticipantsFilterEnabled)
__construct(ilDBInterface $db, ilLanguage $lng)
setAnonymousIdsFilter($anonymousIdsFilter)
setParticipantAccessFilter($participantAccessFilter)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
Interface ilDBInterface.
$row
$query
foreach($_POST as $key=> $value) $res
$rows
Definition: xhr_table.php:10