ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Participant.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
28 private ?\DateTimeImmutable $running_attempt_start = null;
29
30 public function __construct(
31 private readonly int $user_id,
32 private readonly ?int $active_id = null,
33 private readonly ?int $test_id = null,
34 private readonly ?string $anonymous_id = null,
35 private readonly string $firstname = '',
36 private readonly string $lastname = '',
37 private readonly string $login = '',
38 private readonly string $matriculation = '',
39 private int $extra_time = 0,
40 private readonly int $attempts = 0,
41 private ?string $client_ip_from = null,
42 private ?string $client_ip_to = null,
43 private readonly ?int $invitation_date = null,
44 private readonly ?bool $submitted = null,
45 private readonly ?int $last_started_attempt = null,
46 private readonly ?int $last_finished_attempt = null,
47 private readonly bool $unfinished_attempts = false,
48 private readonly ?\DateTimeImmutable $first_access = null,
49 private readonly ?\DateTimeImmutable $last_access = null,
50 private readonly bool $scoring_finalized = false
51 ) {
52 }
53
54 public function getUserId(): int
55 {
56 return $this->user_id;
57 }
58
59 public function getActiveId(): ?int
60 {
61 return $this->active_id;
62 }
63
64 public function getTestId(): ?int
65 {
66 return $this->test_id;
67 }
68
69 public function getAnonymousId(): ?string
70 {
71 return $this->anonymous_id;
72 }
73
74 public function getFirstname(): string
75 {
76 return $this->firstname;
77 }
78
79 public function getLastname(): string
80 {
81 return $this->lastname;
82 }
83
84 public function getLogin(): string
85 {
86 return $this->login;
87 }
88
89 public function getMatriculation(): string
90 {
91 return $this->matriculation;
92 }
93
94 public function getExtraTime(): int
95 {
96 return $this->extra_time;
97 }
98
99 public function withAddedExtraTime(int $extra_time): self
100 {
101 $clone = clone $this;
102 $clone->extra_time += $extra_time;
103 return $clone;
104 }
105
106 public function getAttempts(): int
107 {
108 return $this->attempts;
109 }
110
111 public function getClientIpFrom(): ?string
112 {
113 return $this->client_ip_from;
114 }
115
116 public function withClientIpFrom(?string $ip): self
117 {
118 if ($ip === '') {
119 $ip = null;
120 }
121 $clone = clone $this;
122 $clone->client_ip_from = $ip;
123 return $clone;
124 }
125
126 public function getClientIpTo(): ?string
127 {
128 return $this->client_ip_to;
129 }
130
131 public function withClientIpTo(?string $ip): self
132 {
133 if ($ip === '') {
134 $ip = null;
135 }
136 $clone = clone $this;
137 $clone->client_ip_to = $ip;
138 return $clone;
139 }
140
141 public function isInvitedParticipant(): bool
142 {
143 return $this->invitation_date > 0;
144 }
145
146 public function getSubmitted(): ?bool
147 {
148 return $this->submitted;
149 }
150
151 public function getTotalDuration(?int $processing_time): int
152 {
153 if (!$processing_time) {
154 return 0;
155 }
156
157 return $processing_time + $this->extra_time * 60;
158 }
159
160 public function getLastStartedAttempt(): ?int
161 {
162 return $this->last_started_attempt;
163 }
164
165 public function getLastFinishedAttempt(): ?int
166 {
167 return $this->last_finished_attempt;
168 }
169
170 public function hasUnfinishedAttempts(): bool
171 {
172 return $this->unfinished_attempts;
173 }
174
175 public function getFirstAccess(): ?\DateTimeImmutable
176 {
177 return $this->first_access;
178 }
179
180 public function getLastAccess(): ?\DateTimeImmutable
181 {
182 return $this->last_access;
183 }
184
186 {
187 return $this->attempt_overview?->hasAnsweredQuestions() ?? false;
188 }
189
190 public function getRemainingDuration(
191 int $processing_time,
192 bool $reset_time_on_new_attempt
193 ): int {
194 $remaining = $this->getTotalDuration($processing_time);
195
196 $start = $this->getFirstAccess()?->getTimestamp();
197 if ($reset_time_on_new_attempt) {
198 $start = $this->running_attempt_start?->getTimestamp();
199 }
200
201 if ($start === null) {
202 return $remaining;
203 }
204
205 $remaining += $start;
206 if ($this->submitted) {
207 $remaining -= $this->getLastAccess()?->getTimestamp() ?? time();
208 } else {
209 $remaining -= time();
210 }
211
212 return max(0, $remaining);
213 }
214
216 {
217 return $this->attempt_overview;
218 }
219
220 public function withAttemptOverviewInformation(?AttemptOverview $attempt_overview): self
221 {
222 $clone = clone $this;
223 $clone->attempt_overview = $attempt_overview;
224 return $clone;
225 }
226
227 public function withRunningAttemptStart(\DateTimeImmutable $start_date): self
228 {
229 $clone = clone $this;
230 $clone->running_attempt_start = $start_date;
231 return $clone;
232 }
233
234 public function isScoringFinalized(): bool
235 {
236 return $this->scoring_finalized;
237 }
238}
getTotalDuration(?int $processing_time)
__construct(private readonly int $user_id, private readonly ?int $active_id=null, private readonly ?int $test_id=null, private readonly ?string $anonymous_id=null, private readonly string $firstname='', private readonly string $lastname='', private readonly string $login='', private readonly string $matriculation='', private int $extra_time=0, private readonly int $attempts=0, private ?string $client_ip_from=null, private ?string $client_ip_to=null, private readonly ?int $invitation_date=null, private readonly ?bool $submitted=null, private readonly ?int $last_started_attempt=null, private readonly ?int $last_finished_attempt=null, private readonly bool $unfinished_attempts=false, private readonly ?\DateTimeImmutable $first_access=null, private readonly ?\DateTimeImmutable $last_access=null, private readonly bool $scoring_finalized=false)
Definition: Participant.php:30
withRunningAttemptStart(\DateTimeImmutable $start_date)
withAttemptOverviewInformation(?AttemptOverview $attempt_overview)
getRemainingDuration(int $processing_time, bool $reset_time_on_new_attempt)
DateTimeImmutable $running_attempt_start
Definition: Participant.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Participant.php:21