ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestEvaluationUserData.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
31 require_once './Modules/Test/classes/inc.AssessmentConstants.php';
32 
34 {
35  private $questionTitles;
36  public string $name;
37  public string $login = '';
38  public ?int $user_id = null;
39  protected bool $submitted;
40  public float $reached;
41  public float $maxpoints;
42  public string $mark;
43  public string $mark_official;
45  public int $numberOfQuestions;
46  public string $timeOfWork;
47  public int $firstVisit;
48  public int $lastVisit;
49  public bool $passed;
50 
54  public array $passes;
55  public ?int $lastFinishedPass;
59  public array $questions;
60 
64  private int $passScoring;
65 
66  public function __sleep()
67  {
68  return array('questions', 'passes', 'passed', 'lastVisit', 'firstVisit', 'timeOfWork', 'numberOfQuestions',
69  'questionsWorkedThrough', 'mark_official', 'mark', 'maxpoints', 'reached', 'user_id', 'login',
70  'name', 'passScoring');
71  }
72 
73  public function __construct(int $passScoring)
74  {
75  $this->passes = [];
76  $this->questions = [];
77  $this->passed = false;
78  $this->passScoring = $passScoring;
79  }
80 
81  public function getPassScoring(): int
82  {
83  return $this->passScoring;
84  }
85 
86  public function setPassScoring(int $passScoring): void
87  {
88  $this->passScoring = $passScoring;
89  }
90 
91  public function getPassed(): bool
92  {
93  return $this->passed;
94  }
95 
96  public function setPassed(bool $passed): void
97  {
98  $this->passed = $passed;
99  }
100 
101  public function getName(): string
102  {
103  return $this->name;
104  }
105 
106  public function setName($name): void
107  {
108  $this->name = $name;
109  }
110 
111  public function getLogin(): string
112  {
113  return $this->login;
114  }
115 
116  public function setLogin(string $login): void
117  {
118  $this->login = $login;
119  }
120 
121  public function isSubmitted(): bool
122  {
123  return $this->submitted;
124  }
125 
126  public function setSubmitted(bool $submitted): void
127  {
128  $this->submitted = $submitted;
129  }
130 
131  public function getReached(): float
132  {
133  return $this->getReachedPoints($this->getScoredPass());
134  }
135 
136  public function setReached(float $reached): void
137  {
138  $this->reached = $reached;
139  }
140 
141  public function getMaxpoints(): float
142  {
143  return $this->getAvailablePoints($this->getScoredPass());
144  }
145 
146  public function setMaxpoints(float $max_points): void
147  {
148  $this->maxpoints = $max_points;
149  }
150 
151  public function getReachedPointsInPercent(): float
152  {
153  return $this->getMaxPoints() ? $this->getReached() / $this->getMaxPoints() * 100.0 : 0;
154  }
155 
156  public function getMark(): string
157  {
158  return $this->mark;
159  }
160 
161  public function setMark(string $a_mark): void
162  {
163  $this->mark = $a_mark;
164  }
165 
166  public function getQuestionsWorkedThrough(): int
167  {
168  $questionpass = $this->getScoredPass();
169  if (!isset($this->passes[$questionpass])) {
170  $questionpass = 0;
171  }
172 
173  if (isset($this->passes[$questionpass])) {
174  return $this->passes[$questionpass]->getNrOfAnsweredQuestions();
175  }
176 
177  return 0;
178  }
179 
180  public function setQuestionsWorkedThrough(int $nr): void
181  {
182  $this->questionsWorkedThrough = $nr;
183  }
184 
185  public function getNumberOfQuestions(): int
186  {
187  $questionpass = $this->getScoredPass();
188  if (!isset($this->passes[$questionpass])) {
189  $questionpass = 0;
190  }
191 
192  if (isset($this->passes[$questionpass])) {
193  return $this->passes[$questionpass]->getQuestionCount();
194  }
195 
196  return 0;
197  }
198 
199  public function setNumberOfQuestions(int $nr): void
200  {
201  $this->numberOfQuestions = $nr;
202  }
203 
204  public function getQuestionsWorkedThroughInPercent(): float
205  {
206  return $this->getNumberOfQuestions() ? $this->getQuestionsWorkedThrough() / $this->getNumberOfQuestions() * 100.0 : 0;
207  }
208 
209  public function getTimeOfWork(): int
210  {
211  $time = 0;
212  foreach ($this->passes as $pass) {
213  $time += $pass->getWorkingTime();
214  }
215  return $time;
216  }
217 
218  public function setTimeOfWork(string $time_of_work): void
219  {
220  $this->timeOfWork = $time_of_work;
221  }
222 
223  public function getFirstVisit(): int
224  {
225  return $this->firstVisit;
226  }
227 
228  public function setFirstVisit(int $time): void
229  {
230  $this->firstVisit = $time;
231  }
232 
233  public function getLastVisit(): int
234  {
235  return $this->lastVisit;
236  }
237 
238  public function setLastVisit(int $time): void
239  {
240  $this->lastVisit = $time;
241  }
242 
246  public function getPasses(): array
247  {
248  return $this->passes;
249  }
250 
251  public function addPass(int $pass_nr, ilTestEvaluationPassData $pass): void
252  {
253  $this->passes[$pass_nr] = $pass;
254  }
255 
256  public function getPass(int $pass_nr): ?ilTestEvaluationPassData
257  {
258  return $this->passes[$pass_nr] ?? null;
259  }
260 
261  public function getPassCount(): int
262  {
263  return count($this->passes);
264  }
265 
266  public function getScoredPass(): int
267  {
268  if ($this->getPassScoring() === 1) {
269  return $this->getBestPass();
270  }
271 
272  return $this->getLastPass();
273  }
278  public function getBestPass(): int
279  {
280  $bestpoints = 0;
281  $bestpass = null;
282 
283  $obligationsAnsweredPassExists = $this->doesObligationsAnsweredPassExist();
284 
285  foreach ($this->passes as $pass) {
286  $reached = $this->getReachedPointsInPercentForPass($pass->getPass());
287 
288  if (($reached > $bestpoints
289  && ($pass->areObligationsAnswered() || !$obligationsAnsweredPassExists))
290  || !isset($bestpass)) {
291  $bestpoints = $reached;
292  $bestpass = $pass->getPass();
293  }
294  }
295 
296  return (int) $bestpass;
297  }
298 
299  public function getLastPass(): int
300  {
301  $lastpass = 0;
302  foreach (array_keys($this->passes) as $pass) {
303  if ($pass > $lastpass) {
304  $lastpass = $pass;
305  }
306  }
307  return $lastpass;
308  }
309 
310  public function getFinishedPasses(): int
311  {
312  return $this->getLastFinishedPass() === null ? 0 : $this->getLastFinishedPass() + 1;
313  }
314 
315  public function getLastFinishedPass(): ?int
316  {
318  }
319 
320  public function setLastFinishedPass(?int $pass = null): void
321  {
322  $this->lastFinishedPass = $pass;
323  }
324  public function addQuestionTitle(int $question_id, string $question_title): void
325  {
326  $this->questionTitles[$question_id] = $question_title;
327  }
328 
333  public function getQuestionTitles(): array
334  {
335  return $this->questionTitles;
336  }
337 
341  public function getQuestions(int $pass = 0): ?array
342  {
343  return $this->questions[$pass] ?? null;
344  }
345 
346  public function addQuestion(int $original_id, int $question_id, float $max_points, int $sequence = null, int $pass = 0): void
347  {
348  if (!isset($this->questions[$pass])) {
349  $this->questions[$pass] = [];
350  }
351 
352  $this->questions[$pass][] = [
353  'id' => $question_id, // the so called "aid" from any historical time
354  'o_id' => $original_id, // when the "aid" was valid this was the "id"
355  'points' => $max_points,
356  'sequence' => $sequence
357  ];
358  }
359 
363  public function getQuestion(int $index, int $pass = 0): ?array
364  {
365  return $this->questions[$pass][$index] ?? null;
366  }
367 
368  public function getQuestionCount(int $pass = 0): int
369  {
370  $count = 0;
371  if (array_key_exists($pass, $this->passes)) {
372  $count = $this->passes[$pass]->getQuestionCount();
373  }
374  return $count;
375  }
376 
377  public function getReachedPoints(int $pass = 0): float
378  {
379  $reached = 0;
380  if (array_key_exists($pass, $this->passes)) {
381  $reached = $this->passes[$pass]->getReachedPoints();
382  }
383  $reached = ($reached < 0) ? 0 : $reached;
384  $reached = round($reached, 2);
385  return $reached;
386  }
387 
388  public function getAvailablePoints(int $pass = 0): float
389  {
390  if (!isset($this->passes[$pass])) {
391  $pass = 0;
392  }
393 
394  if (!isset($this->passes[$pass])) {
395  return 0;
396  }
397 
398  $available = $this->passes[$pass]->getMaxPoints();
399  $available = round($available, 2);
400 
401  return $available;
402  }
403 
404  public function getReachedPointsInPercentForPass(int $pass = 0): float
405  {
406  $reached = $this->getReachedPoints($pass);
407  $available = $this->getAvailablePoints($pass);
408  $percent = ($available > 0) ? $reached / $available : 0;
409  return $percent;
410  }
411 
412  public function setUserID(int $user_id): void
413  {
414  $this->user_id = $user_id;
415  }
416 
417  public function getUserID(): ?int
418  {
419  return $this->user_id;
420  }
421 
422  public function setMarkOfficial(string $a_mark_official): void
423  {
424  $this->mark_official = $a_mark_official;
425  }
426 
427  public function getMarkOfficial(): string
428  {
429  return $this->mark_official;
430  }
431 
437  {
438  if ($this->getPassScoring() === 1) {
439  return $this->getBestPassObject();
440  }
441 
442  return $this->getLastPassObject();
443  }
444 
449  {
450  return $this->getRequestedHintsCount($this->getScoredPass());
451  }
452 
453  public function getExamIdFromScoredPass(): string
454  {
455  $examId = '';
456  $scoredPass = $this->getScoredPass();
457 
458  if (isset($this->passes[$scoredPass]) && $this->passes[$scoredPass] instanceof ilTestEvaluationPassData) {
459  $examId = $this->passes[$scoredPass]->getExamId();
460  }
461 
462  return $examId;
463  }
464 
470  public function getRequestedHintsCount(int $pass): int
471  {
472  if (!isset($this->passes[$pass]) || !($this->passes[$pass] instanceof ilTestEvaluationPassData)) {
473  throw new ilTestException("invalid pass index given: $pass");
474  }
475 
476  $requestedHintsCount = $this->passes[$pass]->getRequestedHintsCount();
477 
478  return $requestedHintsCount;
479  }
480 
486  {
487  $bestpoints = 0;
488  $bestpassObject = 0;
489 
490  $obligationsAnsweredPassExists = $this->doesObligationsAnsweredPassExist();
491 
492  foreach ($this->passes as $pass) {
493  $reached = $this->getReachedPointsInPercentForPass($pass->getPass());
494 
495  if ($reached >= $bestpoints && ($pass->areObligationsAnswered() || !$obligationsAnsweredPassExists)) {
496  $bestpoints = $reached;
497  $bestpassObject = $pass;
498  }
499  }
500 
501  return $bestpassObject;
502  }
503 
509  {
510  $lastpassIndex = 0;
511 
512  foreach (array_keys($this->passes) as $passIndex) {
513  if ($passIndex > $lastpassIndex) {
514  $lastpassIndex = $passIndex;
515  }
516  }
517 
518  $lastpassObject = $this->passes[$lastpassIndex];
519 
520  return $lastpassObject;
521  }
522 
527  public function doesObligationsAnsweredPassExist(): bool
528  {
529  foreach ($this->passes as $pass) {
530  if ($pass->areObligationsAnswered()) {
531  return true;
532  }
533  }
534 
535  return false;
536  }
537 
542  public function areObligationsAnswered(): bool
543  {
544  return $this->getScoredPassObject()->areObligationsAnswered();
545  }
546 }
setMarkOfficial(string $a_mark_official)
getBestPass()
This is used in the export of test results Aligned with ilObjTest::_getBestPass: from passes with equ...
int $passScoring
Pass Scoring (Last pass = 0, Best pass = 1)
addPass(int $pass_nr, ilTestEvaluationPassData $pass)
addQuestionTitle(int $question_id, string $question_title)
Base Exception for all Exceptions relating to Modules/Test.
getScoredPassObject()
returns the object of class ilTestEvaluationPassData that relates to the the scored test pass (best p...
getRequestedHintsCount(int $pass)
returns the count of hints requested by participant for given testpass
getBestPassObject()
returns the object of class ilTestEvaluationPassData that relates to the the best test pass ...
getLastPassObject()
returns the object of class ilTestEvaluationPassData that relates to the the last test pass ...
doesObligationsAnsweredPassExist()
returns the fact wether a test pass with all obligations answered exists or not
getRequestedHintsCountFromScoredPass()
returns the count of hints requested by participant for scored testpass
addQuestion(int $original_id, int $question_id, float $max_points, int $sequence=null, int $pass=0)
areObligationsAnswered()
returns the fact wether all obligations in the scored test pass are answered or not ...