ILIAS  release_8 Revision v8.24
class.ilTestEvaluationData.php
Go to the documentation of this file.
1<?php
2
30{
37
43 private $test;
44
51
58
64 public $arrFilter;
65
70 public $datasets;
71
76
77 public function __sleep()
78 {
79 return array('questionTitles', 'participants', 'statistics', 'arrFilter', 'datasets', 'test');
80 }
81
87 public function __construct(ilObjTest $test = null)
88 {
89 $this->participants = array();
90 $this->questionTitles = array();
91 if ($test !== null) {
92 $this->test = $test;
93
97 );
98 }
99
100 $this->generateOverview();
101 }
102 }
103
105 {
107 }
108
113 {
114 $this->accessFilteredParticipantList = $accessFilteredParticipantList;
115 }
116
117 protected function checkParticipantAccess($activeId): bool
118 {
119 if ($this->getAccessFilteredParticipantList() === null) {
120 return true;
121 }
122
123 return $this->getAccessFilteredParticipantList()->isActiveIdInList($activeId);
124 }
125
126 protected function loadRows(): array
127 {
128 global $DIC; /* @var ILIAS\DI\Container $DIC */
129
130 $query = "
131 SELECT usr_data.usr_id,
132 usr_data.firstname,
133 usr_data.lastname,
134 usr_data.title,
135 usr_data.login,
136 tst_pass_result.*,
137 tst_active.submitted,
138 tst_active.last_finished_pass
139 FROM tst_pass_result, tst_active
140 LEFT JOIN usr_data
141 ON tst_active.user_fi = usr_data.usr_id
142 WHERE tst_active.active_id = tst_pass_result.active_fi
143 AND tst_active.test_fi = %s
144 ORDER BY usr_data.lastname,
145 usr_data.firstname,
146 tst_pass_result.active_fi,
147 tst_pass_result.pass,
148 tst_pass_result.tstamp
149 ";
150
151 $result = $DIC->database()->queryF(
152 $query,
153 array('integer'),
154 array($this->getTest()->getTestId())
155 );
156
157 $rows = array();
158
159 while ($row = $DIC->database()->fetchAssoc($result)) {
160 if (!$this->checkParticipantAccess($row['active_fi'])) {
161 continue;
162 }
163
164 $rows[] = $row;
165 }
166
167 return $rows;
168 }
169
170 public function generateOverview()
171 {
172 include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
173 include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
174
175 $this->participants = array();
176
177 $pass = null;
178 $checked = array();
179 $thissets = 0;
180
181 foreach ($this->loadRows() as $row) {
182 $thissets++;
183
184 $remove = false;
185
186 if (!$this->participantExists($row["active_fi"])) {
187 $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
188
189 $this->getParticipant($row["active_fi"])->setName(
190 $this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"])
191 );
192
193 $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
194
195 $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
196
197 $this->getParticipant($row["active_fi"])->setSubmitted($row['submitted']);
198
199 $this->getParticipant($row["active_fi"])->setLastFinishedPass($row['last_finished_pass']);
200 }
201
202 if (!is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"]))) {
203 $pass = new ilTestEvaluationPassData();
204 $pass->setPass($row["pass"]);
205 $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
206 }
207
208 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints((float) $row["points"]);
209 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setObligationsAnswered($row["obligations_answered"]);
210
211 if ($row["questioncount"] == 0) {
212 $data = ilObjTest::_getQuestionCountAndPointsForPassOfParticipant($row['active_fi'], $row['pass']);
213 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
214 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
215 } else {
216 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
217 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
218 }
219
220 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
221 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
222 $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setExamId((string) $row["exam_id"]);
223
224 $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setRequestedHintsCount($row['hint_count']);
225 $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setDeductedHintPoints($row['hint_points']);
226 }
227 }
228
229 public function getTest(): ilObjTest
230 {
231 return $this->test;
232 }
233
234 public function setTest($test)
235 {
236 $this->test = &$test;
237 }
238
239 public function setDatasets($datasets)
240 {
241 $this->datasets = $datasets;
242 }
243
244 public function getDatasets(): int
245 {
246 return $this->datasets;
247 }
248
249 public function addQuestionTitle($question_id, $question_title)
250 {
251 $this->questionTitles[$question_id] = $question_title;
252 }
253
254 public function getQuestionTitles(): array
255 {
257 }
258
259 public function getQuestionTitle($question_id)
260 {
261 if (array_key_exists($question_id, $this->questionTitles)) {
262 return $this->questionTitles[$question_id];
263 } else {
264 return "";
265 }
266 }
267
268 public function calculateStatistics()
269 {
270 include_once "./Modules/Test/classes/class.ilTestStatistics.php";
271 $this->statistics = new ilTestStatistics($this);
272 }
273
275 {
276 $finishedParticipants = 0;
277
278 foreach ($this->participants as $active_id => $participant) {
279 if (!$participant->isSubmitted()) {
280 continue;
281 }
282
283 $finishedParticipants++;
284 }
285
286 return $finishedParticipants;
287 }
288
289 public function getParticipants(): array
290 {
291 if (is_array($this->arrFilter) && count($this->arrFilter) > 0) {
292 $filtered_participants = [];
293 $courseids = [];
294 $groupids = [];
295
296 if (array_key_exists('group', $this->arrFilter)) {
297 $ids = ilObject::_getIdsForTitle($this->arrFilter['group'], 'grp', true);
298 $groupids = array_merge($groupids, $ids);
299 }
300 if (array_key_exists('course', $this->arrFilter)) {
301 $ids = ilObject::_getIdsForTitle($this->arrFilter['course'], 'crs', true);
302 $courseids = array_merge($courseids, $ids);
303 }
304 foreach ($this->participants as $active_id => $participant) {
305 $remove = false;
306 if (array_key_exists('name', $this->arrFilter)) {
307 if (!(strpos(strtolower($participant->getName()), strtolower((string) $this->arrFilter['name'])) !== false)) {
308 $remove = true;
309 }
310 }
311 if (!$remove) {
312 if (array_key_exists('group', $this->arrFilter)) {
313 $groups = ilParticipants::_getMembershipByType($participant->getUserID(), ["grp"]);
314 $foundfilter = false;
315 if (count(array_intersect($groupids, $groups))) {
316 $foundfilter = true;
317 }
318 if (!$foundfilter) {
319 $remove = true;
320 }
321 }
322 }
323 if (!$remove) {
324 if (array_key_exists('course', $this->arrFilter)) {
325 $courses = ilParticipants::_getMembershipByType($participant->getUserID(), ["crs"]);
326 $foundfilter = false;
327 if (count(array_intersect($courseids, $courses))) {
328 $foundfilter = true;
329 }
330 if (!$foundfilter) {
331 $remove = true;
332 }
333 }
334 }
335 if (!$remove) {
336 if (array_key_exists('active_id', $this->arrFilter)) {
337 if ($active_id != $this->arrFilter['active_id']) {
338 $remove = true;
339 }
340 }
341 }
342 if (!$remove) {
343 $filtered_participants[$active_id] = $participant;
344 }
345 }
346 return $filtered_participants;
347 } else {
348 return $this->participants;
349 }
350 }
351
352 public function resetFilter()
353 {
354 $this->arrFilter = array();
355 }
356
357 /*
358 * Set an output filter for getParticipants
359 *
360 * @param string $by name, course, group
361 * @param string $text Filter text
362 */
363 public function setFilter($by, $text)
364 {
365 $this->arrFilter = array($by => $text);
366 }
367
368 /*
369 * Set an output filter for getParticipants
370 *
371 * @param array $arrFilter filter values
372 */
373 public function setFilterArray($arrFilter)
374 {
375 $this->arrFilter = $arrFilter;
376 }
377
378 public function addParticipant($active_id, $participant)
379 {
380 $this->participants[$active_id] = $participant;
381 }
382
387 public function getParticipant($active_id): ilTestEvaluationUserData
388 {
389 return $this->participants[$active_id];
390 }
391
392 public function participantExists($active_id): bool
393 {
394 return array_key_exists($active_id, $this->participants);
395 }
396
397 public function removeParticipant($active_id)
398 {
399 unset($this->participants[$active_id]);
400 }
401
402 public function getStatistics(): object
403 {
404 return $this->statistics;
405 }
406
407 public function getParticipantIds(): array
408 {
409 return array_keys($this->participants);
410 }
411} // END ilTestEvaluationData
static _getQuestionCountAndPointsForPassOfParticipant($active_id, $pass)
static _getIdsForTitle(string $title, string $type='', bool $partial_match=false)
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
addQuestionTitle($question_id, $question_title)
addParticipant($active_id, $participant)
setAccessFilteredParticipantList($accessFilteredParticipantList)
__construct(ilObjTest $test=null)
Constructor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$query
$rows
Definition: xhr_table.php:10