ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestParticipantList.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once 'Modules/Test/classes/class.ilTestParticipant.php';
6
15class ilTestParticipantList implements Iterator
16{
20 protected $participants = array();
21
25 protected $testObj;
26
31 {
32 $this->testObj = $testObj;
33 }
34
38 public function getTestObj()
39 {
40 return $this->testObj;
41 }
42
46 public function setTestObj($testObj)
47 {
48 $this->testObj = $testObj;
49 }
50
54 public function addParticipant(ilTestParticipant $participant)
55 {
56 $this->participants[] = $participant;
57 }
58
59 public function getParticipantByUsrId($usrId)
60 {
61 foreach ($this as $participant) {
62 if ($participant->getUsrId() != $usrId) {
63 continue;
64 }
65
66 return $participant;
67 }
68 }
69
74 public function getParticipantByActiveId($activeId)
75 {
76 foreach ($this as $participant) {
77 if ($participant->getActiveId() != $activeId) {
78 continue;
79 }
80
81 return $participant;
82 }
83 }
84
88 public function hasUnfinishedPasses()
89 {
90 foreach ($this as $participant) {
91 if ($participant->hasUnfinishedPasses()) {
92 return true;
93 }
94 }
95
96 return false;
97 }
98
102 public function hasScorings()
103 {
104 foreach ($this as $participant) {
105 if ($participant->getScoring() instanceof ilTestParticipantScoring) {
106 return true;
107 }
108 }
109
110 return false;
111 }
112
113 public function getAllUserIds()
114 {
115 $usrIds = array();
116
117 foreach ($this as $participant) {
118 $usrIds[] = $participant->getUsrId();
119 }
120
121 return $usrIds;
122 }
123
124 public function getAllActiveIds()
125 {
126 $activeIds = array();
127
128 foreach ($this as $participant) {
129 $activeIds[] = $participant->getActiveId();
130 }
131
132 return $activeIds;
133 }
134
135 public function isActiveIdInList($activeId)
136 {
137 foreach ($this as $participant) {
138 if ($participant->getActiveId() == $activeId) {
139 return true;
140 }
141 }
142
143 return false;
144 }
145
146 public function getAccessFilteredList(callable $userAccessFilter)
147 {
148 $usrIds = call_user_func_array($userAccessFilter, [$this->getAllUserIds()]);
149
150 $accessFilteredList = new self($this->getTestObj());
151
152 foreach ($this as $participant) {
153 if (in_array($participant->getUsrId(), $usrIds)) {
154 $participant = clone $participant;
155 $accessFilteredList->addParticipant($participant);
156 }
157 }
158
159 return $accessFilteredList;
160 }
161
162 public function current()
163 {
164 return current($this->participants);
165 }
166 public function next()
167 {
168 return next($this->participants);
169 }
170 public function key()
171 {
172 return key($this->participants);
173 }
174 public function valid()
175 {
176 return key($this->participants) !== null;
177 }
178 public function rewind()
179 {
180 return reset($this->participants);
181 }
182
186 public function initializeFromDbRows($dbRows)
187 {
188 foreach ($dbRows as $rowKey => $rowData) {
189 $participant = new ilTestParticipant();
190
191 if ((int) $rowData['active_id']) {
192 $participant->setActiveId((int) $rowData['active_id']);
193 }
194
195 $participant->setUsrId((int) $rowData['usr_id']);
196
197 $participant->setLogin($rowData['login']);
198 $participant->setLastname($rowData['lastname']);
199 $participant->setFirstname($rowData['firstname']);
200 $participant->setMatriculation($rowData['matriculation']);
201
202 $participant->setActiveStatus((bool) $rowData['active']);
203
204 if (isset($rowData['clientip'])) {
205 $participant->setClientIp($rowData['clientip']);
206 }
207
208 $participant->setFinishedTries((int) $rowData['tries']);
209 $participant->setTestFinished((bool) $rowData['test_finished']);
210 $participant->setUnfinishedPasses((bool) $rowData['unfinished_passes']);
211
212 $this->addParticipant($participant);
213 }
214 }
215
219 public function getScoredParticipantList()
220 {
221 require_once 'Modules/Test/classes/class.ilTestParticipantScoring.php';
222
223 $scoredParticipantList = new self($this->getTestObj());
224
225 global $DIC; /* @var ILIAS\DI\Container $DIC */
226
227 $res = $DIC->database()->query($this->buildScoringsQuery());
228
229 while ($row = $DIC->database()->fetchAssoc($res)) {
230 if (ilObjTest::_getResultPass($row['active_fi']) != $row['pass']) {
231 assQuestion::_updateTestResultCache($row['active_fi']);
232 }
233 }
234
235 $res = $DIC->database()->query($this->buildScoringsQuery());
236
237 while ($row = $DIC->database()->fetchAssoc($res)) {
238 $scoring = new ilTestParticipantScoring();
239
240 $scoring->setActiveId((int) $row['active_fi']);
241 $scoring->setScoredPass((int) $row['pass']);
242
243 $scoring->setAnsweredQuestions((int) $row['answeredquestions']);
244 $scoring->setTotalQuestions((int) $row['questioncount']);
245
246 $scoring->setReachedPoints((float) $row['reached_points']);
247 $scoring->setMaxPoints((float) $row['max_points']);
248
249 $scoring->setPassed((bool) $row['passed']);
250 $scoring->setFinalMark((string) $row['mark_short']);
251
252 $this->getParticipantByActiveId($row['active_fi'])->setScoring($scoring);
253
254 $scoredParticipantList->addParticipant(
255 $this->getParticipantByActiveId($row['active_fi'])
256 );
257 }
258
259 return $scoredParticipantList;
260 }
261
262 public function buildScoringsQuery()
263 {
264 global $DIC; /* @var ILIAS\DI\Container $DIC */
265
266 $IN_activeIds = $DIC->database()->in(
267 'tres.active_fi',
268 $this->getAllActiveIds(),
269 false,
270 'integer'
271 );
272
273 if (false && !$this->getTestObj()->isDynamicTest()) { // BH: keep for the moment
274 $closedScoringsOnly = "
275 INNER JOIN tst_active tact
276 ON tact.active_id = tres.active_fi
277 AND tact.last_finished_pass = tact.last_started_pass
278 ";
279 } else {
280 $closedScoringsOnly = '';
281 }
282
283 $query = "
284 SELECT * FROM tst_result_cache tres
285
286 INNER JOIN tst_pass_result pres
287 ON pres.active_fi = tres.active_fi
288 AND pres.pass = tres.pass
289
290 $closedScoringsOnly
291
292 WHERE $IN_activeIds
293 ";
294
295 return $query;
296 }
297
298 public function getParticipantsTableRows()
299 {
300 $rows = array();
301
302 foreach ($this as $participant) {
303 $row = array(
304 'usr_id' => $participant->getUsrId(),
305 'active_id' => $participant->getActiveId(),
306 'login' => $participant->getLogin(),
307 'clientip' => $participant->getClientIp(),
308 'firstname' => $participant->getFirstname(),
309 'lastname' => $participant->getLastname(),
310 'name' => $this->buildFullname($participant),
311 'started' => ($participant->getActiveId() > 0) ? 1 : 0,
312 'unfinished' => $participant->hasUnfinishedPasses() ? 1 : 0,
313 'finished' => $participant->isTestFinished() ? 1 : 0,
314 'access' => $this->lookupLastAccess($participant->getActiveId()),
315 'tries' => $this->lookupNrOfTries($participant->getActiveId())
316 );
317
318 $rows[] = $row;
319 }
320
321 return $rows;
322 }
323
324 public function getScoringsTableRows()
325 {
326 $rows = array();
327
328 foreach ($this as $participant) {
329 if (!$participant->hasScoring()) {
330 continue;
331 }
332
333 $row = array(
334 'usr_id' => $participant->getUsrId(),
335 'active_id' => $participant->getActiveId(),
336 'login' => $participant->getLogin(),
337 'firstname' => $participant->getFirstname(),
338 'lastname' => $participant->getLastname(),
339 'name' => $this->buildFullname($participant)
340 );
341
342 if ($participant->getScoring()) {
343 $row['scored_pass'] = $participant->getScoring()->getScoredPass();
344 $row['answered_questions'] = $participant->getScoring()->getAnsweredQuestions();
345 $row['total_questions'] = $participant->getScoring()->getTotalQuestions();
346 $row['reached_points'] = $participant->getScoring()->getReachedPoints();
347 $row['max_points'] = $participant->getScoring()->getMaxPoints();
348 $row['percent_result'] = $participant->getScoring()->getPercentResult();
349 $row['passed_status'] = $participant->getScoring()->isPassed();
350 $row['final_mark'] = $participant->getScoring()->getFinalMark();
351 $row['last_scored_access'] = ilObjTest::lookupLastTestPassAccess(
352 $participant->getActiveId(),
353 $participant->getScoring()->getScoredPass()
354 );
355 $row['finished_passes'] = $participant->getFinishedTries();
356 $row['has_unfinished_passes'] = $participant->hasUnfinishedPasses();
357 }
358
359 $rows[] = $row;
360 }
361
362 return $rows;
363 }
364
369 public function lookupNrOfTries($activeId)
370 {
371 $maxPassIndex = ilObjTest::_getMaxPass($activeId);
372
373 if ($maxPassIndex !== null) {
374 $nrOfTries = $maxPassIndex + 1;
375 return $nrOfTries;
376 }
377
378 return null;
379 }
380
385 protected function lookupLastAccess($activeId)
386 {
387 if (!$activeId) {
388 return '';
389 }
390
391 return $this->getTestObj()->_getLastAccess($activeId);
392 }
393
398 protected function buildFullname(ilTestParticipant $participant)
399 {
400 if ($this->getTestObj()->getFixedParticipants() && !$participant->getActiveId()) {
401 return $this->buildInviteeFullname($participant);
402 }
403
404 return $this->buildParticipantsFullname($participant);
405 }
406
411 protected function buildInviteeFullname(ilTestParticipant $participant)
412 {
413 global $DIC; /* @var ILIAS\DI\Container $DIC */
414
415 if (strlen($participant->getFirstname() . $participant->getLastname()) == 0) {
416 return $DIC->language()->txt("deleted_user");
417 }
418
419 if ($this->getTestObj()->getAnonymity()) {
420 return $DIC->language()->txt('anonymous');
421 }
422
423 return trim($participant->getLastname() . ", " . $participant->getFirstname());
424 }
425
430 protected function buildParticipantsFullname(ilTestParticipant $participant)
431 {
432 require_once 'Modules/Test/classes/class.ilObjTestAccess.php';
434 }
435}
An exception for terminatinating execution or to throw for unit testing.
static _updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker=null)
@TODO Move this to a proper place.
static _getParticipantData($active_id)
Retrieves a participant name from active id.
static _getResultPass($active_id)
Retrieves the pass number that should be counted for a given user.
static lookupLastTestPassAccess($activeId, $passIndex)
static _getMaxPass($active_id)
Retrieves the maximum pass of a given user for a given test in which the user answered at least one q...
buildParticipantsFullname(ilTestParticipant $participant)
buildInviteeFullname(ilTestParticipant $participant)
getAccessFilteredList(callable $userAccessFilter)
addParticipant(ilTestParticipant $participant)
buildFullname(ilTestParticipant $participant)
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
$rows
Definition: xhr_table.php:10