ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestEvaluationUserData.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  private array $question_titles;
29  private string $name;
30  private string $login = '';
31  private ?int $user_id = null;
32  private bool $submitted;
33  private Mark $mark;
34  private ?\DateTimeImmutable $first_visit = null;
35  private ?\DateTimeImmutable $last_visit = null;
36 
40  private array $passes = [];
41  private ?int $last_finished_pass = null;
45  private array $questions;
46 
47  public function __sleep()
48  {
49  return ['questions', 'passes', 'passed', 'lastVisit', 'firstVisit', 'timeOfWork', 'numberOfQuestions',
50  'questionsWorkedThrough', 'mark_official', 'mark', 'maxpoints', 'reached', 'user_id', 'login',
51  'name', 'passScoring'];
52  }
53 
54  public function __construct(
55  private int $pass_scoring
56  ) {
57  }
58 
59  public function getPassScoring(): int
60  {
61  return $this->pass_scoring;
62  }
63 
64  public function setPassScoring(int $passScoring): void
65  {
66  $this->pass_scoring = $passScoring;
67  }
68 
69  public function getName(): string
70  {
71  return $this->name;
72  }
73 
74  public function setName($name): void
75  {
76  $this->name = $name;
77  }
78 
79  public function getLogin(): string
80  {
81  return $this->login;
82  }
83 
84  public function setLogin(string $login): void
85  {
86  $this->login = $login;
87  }
88 
89  public function isSubmitted(): bool
90  {
91  return $this->submitted;
92  }
93 
94  public function setSubmitted(bool $submitted): void
95  {
96  $this->submitted = $submitted;
97  }
98 
99  public function getReached(): float
100  {
101  return $this->getReachedPoints($this->getScoredPass());
102  }
103 
104  public function getMaxpoints(): float
105  {
106  return $this->getAvailablePoints($this->getScoredPass());
107  }
108 
109  public function getReachedPointsInPercent(): float
110  {
111  return $this->getMaxPoints() ? $this->getReached() / $this->getMaxPoints() * 100.0 : 0.0;
112  }
113 
114  public function getMark(): Mark
115  {
116  return $this->mark;
117  }
118 
119  public function setMark(Mark $mark): void
120  {
121  $this->mark = $mark;
122  }
123 
124  public function getQuestionsWorkedThrough(): int
125  {
126  $questionpass = $this->getScoredPass();
127  if (!isset($this->passes[$questionpass])) {
128  $questionpass = 0;
129  }
130 
131  if (isset($this->passes[$questionpass])) {
132  return $this->passes[$questionpass]->getNrOfAnsweredQuestions();
133  }
134 
135  return 0;
136  }
137 
138  public function getNumberOfQuestions(): int
139  {
140  $questionpass = $this->getScoredPass();
141  if (!isset($this->passes[$questionpass])) {
142  $questionpass = 0;
143  }
144 
145  if (isset($this->passes[$questionpass])) {
146  return $this->passes[$questionpass]->getQuestionCount();
147  }
148 
149  return 0;
150  }
151 
152  public function getQuestionsWorkedThroughInPercent(): float
153  {
154  return $this->getNumberOfQuestions() ? $this->getQuestionsWorkedThrough() / $this->getNumberOfQuestions() * 100.0 : 0;
155  }
156 
157  public function getTimeOnTask(): int
158  {
159  $time = 0;
160  foreach ($this->passes as $pass) {
161  $time += $pass->getWorkingTime();
162  }
163  return $time;
164  }
165 
166  public function getFirstVisit(): ?\DateTimeImmutable
167  {
168  return $this->first_visit;
169  }
170 
171  public function setFirstVisit(?\DateTimeImmutable $time): void
172  {
173  $this->first_visit = $time;
174  }
175 
176  public function getLastVisit(): ?\DateTimeImmutable
177  {
178  return $this->last_visit;
179  }
180 
181  public function setLastVisit(?\DateTimeImmutable $time): void
182  {
183  $this->last_visit = $time;
184  }
185 
189  public function getPasses(): array
190  {
191  return $this->passes;
192  }
193 
194  public function addPass(int $pass_nr, ilTestEvaluationPassData $pass): void
195  {
196  $this->passes[$pass_nr] = $pass;
197  }
198 
199  public function getPass(int $pass_nr): ?ilTestEvaluationPassData
200  {
201  return $this->passes[$pass_nr] ?? null;
202  }
203 
204  public function getPassCount(): int
205  {
206  return count($this->passes);
207  }
208 
209  public function getScoredPass(): int
210  {
211  if ($this->getPassScoring() === 1) {
212  return $this->getBestPass();
213  }
214 
215  return $this->getLastPass();
216  }
221  public function getBestPass(): int
222  {
223  $bestpoints = 0;
224  $bestpass = null;
225 
226  foreach ($this->passes as $pass) {
227  $reached = $this->getReachedPointsInPercentForPass($pass->getPass());
228 
229  if ($reached > $bestpoints || !isset($bestpass)) {
230  $bestpoints = $reached;
231  $bestpass = $pass->getPass();
232  }
233  }
234 
235  return (int) $bestpass;
236  }
237 
238  public function getLastPass(): int
239  {
240  $lastpass = 0;
241  foreach (array_keys($this->passes) as $pass) {
242  if ($pass > $lastpass) {
243  $lastpass = $pass;
244  }
245  }
246  return $lastpass;
247  }
248 
249  public function getFinishedPasses(): int
250  {
251  return $this->getLastFinishedPass() === null ? 0 : $this->getLastFinishedPass() + 1;
252  }
253 
254  public function getLastFinishedPass(): ?int
255  {
257  }
258 
259  public function setLastFinishedPass(?int $pass = null): void
260  {
261  $this->last_finished_pass = $pass;
262  }
263  public function addQuestionTitle(int $question_id, string $question_title): void
264  {
265  $this->question_titles[$question_id] = $question_title;
266  }
267 
272  public function getQuestionTitles(): array
273  {
274  return $this->question_titles;
275  }
276 
280  public function getQuestions(int $pass = 0): ?array
281  {
282  return $this->questions[$pass] ?? null;
283  }
284 
285  public function addQuestion(int $original_id, int $question_id, float $max_points, ?int $sequence = null, int $pass = 0): void
286  {
287  if (!isset($this->questions[$pass])) {
288  $this->questions[$pass] = [];
289  }
290 
291  $this->questions[$pass][] = [
292  'id' => $question_id,
293  'o_id' => $original_id,
294  'points' => $max_points,
295  'sequence' => $sequence
296  ];
297  }
298 
302  public function getQuestion(int $index, int $pass = 0): ?array
303  {
304  return $this->questions[$pass][$index] ?? null;
305  }
306 
307  public function getQuestionByAttemptAndId(int $attempt, int $question_id): ?array
308  {
309  if (!isset($this->questions[$attempt])) {
310  return null;
311  }
312 
313  $question = array_filter(
314  $this->questions[$attempt],
315  fn(array $v): bool => $v['id'] === $question_id
316  );
317 
318  if ($question === []) {
319  return null;
320  }
321 
322  return array_shift($question);
323  }
324 
325  public function getQuestionCount(int $pass = 0): int
326  {
327  $count = 0;
328  if (array_key_exists($pass, $this->passes)) {
329  $count = $this->passes[$pass]->getQuestionCount();
330  }
331  return $count;
332  }
333 
334  public function getReachedPoints(int $pass = 0): float
335  {
336  $reached = 0;
337  if (array_key_exists($pass, $this->passes)) {
338  $reached = $this->passes[$pass]->getReachedPoints();
339  }
340  $reached = ($reached < 0) ? 0 : $reached;
341  $reached = round($reached, 2);
342  return $reached;
343  }
344 
345  public function getAvailablePoints(int $pass = 0): float
346  {
347  if (!isset($this->passes[$pass]) || !is_object($this->passes[$pass])) {
348  $pass = 0;
349  }
350  if (!isset($this->passes[$pass]) || !is_object($this->passes[$pass])) {
351  return 0.0;
352  }
353 
354  $available = $this->passes[$pass]->getMaxPoints();
355  $available = round($available, 2);
356 
357  return $available;
358  }
359 
360  public function getReachedPointsInPercentForPass(int $pass = 0): float
361  {
362  $reached = $this->getReachedPoints($pass);
363  $available = $this->getAvailablePoints($pass);
364  $percent = ($available > 0) ? $reached / $available : 0;
365  return $percent;
366  }
367 
368  public function setUserID(int $user_id): void
369  {
370  $this->user_id = $user_id;
371  }
372 
373  public function getUserID(): ?int
374  {
375  return $this->user_id;
376  }
377 
383  {
384  if ($this->getPassScoring() === 1) {
385  return $this->getBestPassObject();
386  }
387 
388  return $this->getLastPassObject();
389  }
390 
395  {
396  return $this->getRequestedHintsCount($this->getScoredPass());
397  }
398 
399  public function getExamIdFromScoredPass(): string
400  {
401  $exam_id = '';
402  $scored_pass = $this->getScoredPass();
403 
404  if (isset($this->passes[$scored_pass]) && $this->passes[$scored_pass] instanceof ilTestEvaluationPassData) {
405  $exam_id = $this->passes[$scored_pass]->getExamId();
406  }
407 
408  return $exam_id;
409  }
410 
416  public function getRequestedHintsCount(int $pass): int
417  {
418  if (!isset($this->passes[$pass]) || !($this->passes[$pass] instanceof ilTestEvaluationPassData)) {
419  throw new ilTestException("invalid pass index given: $pass");
420  }
421 
422  $requestedHintsCount = $this->passes[$pass]->getRequestedHintsCount();
423 
424  return $requestedHintsCount;
425  }
426 
432  {
433  $bestpoints = 0;
434  $bestpass_bject = 0;
435 
436  foreach ($this->passes as $pass) {
437  $reached = $this->getReachedPointsInPercentForPass($pass->getPass());
438 
439  if ($reached >= $bestpoints) {
440  $bestpoints = $reached;
441  $bestpass_bject = $pass;
442  }
443  }
444 
445  return $bestpass_bject;
446  }
447 
453  {
454  $lastpassIndex = 0;
455 
456  foreach (array_keys($this->passes) as $passIndex) {
457  if ($passIndex > $lastpassIndex) {
458  $lastpassIndex = $passIndex;
459  }
460  }
461 
462  $lastpassObject = $this->passes[$lastpassIndex];
463 
464  return $lastpassObject;
465  }
466 }
getBestPass()
This is used in the export of test results Aligned with ilObjTest::_getBestPass: from passes with equ...
A class defining marks for assessment test objects.
Definition: Mark.php:35
setFirstVisit(?\DateTimeImmutable $time)
addPass(int $pass_nr, ilTestEvaluationPassData $pass)
login()
description: > Example for rendring a login glyph.
Definition: login.php:41
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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getRequestedHintsCount(int $pass)
returns the count of hints requested by participant for given testpass
getQuestionByAttemptAndId(int $attempt, int $question_id)
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 ...
__construct(private int $pass_scoring)
setLastVisit(?\DateTimeImmutable $time)
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)