ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Participant.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
29 private ?\DateTimeImmutable $running_attempt_start = null;
30
31 public function __construct(
32 private readonly int $user_id,
33 private readonly ?int $active_id = null,
34 private readonly ?int $test_id = null,
35 private readonly ?string $anonymous_id = null,
36 private readonly string $firstname = '',
37 private readonly string $lastname = '',
38 private readonly string $login = '',
39 private readonly ?string $importname = null,
40 private readonly string $matriculation = '',
41 private int $extra_time = 0,
42 private readonly int $attempts = 0,
43 private ?string $client_ip_from = null,
44 private ?string $client_ip_to = null,
45 private readonly ?int $invitation_date = null,
46 private readonly ?bool $submitted = null,
47 private readonly ?int $last_started_attempt = null,
48 private readonly ?int $last_finished_attempt = null,
49 private readonly bool $unfinished_attempts = false,
50 private readonly ?\DateTimeImmutable $first_access = null,
51 private readonly ?\DateTimeImmutable $last_access = null,
52 private readonly bool $scoring_finalized = false
53 ) {
54 }
55
56 public function getUserId(): int
57 {
58 return $this->user_id;
59 }
60
61 public function getActiveId(): ?int
62 {
63 return $this->active_id;
64 }
65
66 public function getTestId(): ?int
67 {
68 return $this->test_id;
69 }
70
71 public function getAnonymousId(): ?string
72 {
73 return $this->anonymous_id;
74 }
75
76 public function getFirstname(): string
77 {
78 return $this->firstname;
79 }
80
81 public function getLastname(): string
82 {
83 return $this->lastname;
84 }
85
86 public function getLogin(): string
87 {
88 return $this->login;
89 }
90
91 public function getImportname(): ?string
92 {
93 return $this->importname;
94 }
95
96 public function getMatriculation(): string
97 {
98 return $this->matriculation;
99 }
100
101 public function getExtraTime(): int
102 {
103 return $this->extra_time;
104 }
105
106 public function withAddedExtraTime(int $extra_time): self
107 {
108 $clone = clone $this;
109 $clone->extra_time += $extra_time;
110 return $clone;
111 }
112
113 public function getAttempts(): int
114 {
115 return $this->attempts;
116 }
117
118 public function getClientIpFrom(): ?string
119 {
120 return $this->client_ip_from;
121 }
122
123 public function withClientIpFrom(?string $ip): self
124 {
125 if ($ip === '') {
126 $ip = null;
127 }
128 $clone = clone $this;
129 $clone->client_ip_from = $ip;
130 return $clone;
131 }
132
133 public function getClientIpTo(): ?string
134 {
135 return $this->client_ip_to;
136 }
137
138 public function withClientIpTo(?string $ip): self
139 {
140 if ($ip === '') {
141 $ip = null;
142 }
143 $clone = clone $this;
144 $clone->client_ip_to = $ip;
145 return $clone;
146 }
147
148 public function getInvitationDate(): ?int
149 {
150 return $this->invitation_date;
151 }
152
153 public function isInvitedParticipant(): bool
154 {
155 return $this->invitation_date > 0;
156 }
157
158 public function getSubmitted(): ?bool
159 {
160 return $this->submitted;
161 }
162
163 public function getTotalDuration(?int $processing_time): int
164 {
165 if (!$processing_time) {
166 return 0;
167 }
168
169 return $processing_time + $this->extra_time * 60;
170 }
171
172 public function getLastStartedAttempt(): ?int
173 {
174 return $this->last_started_attempt;
175 }
176
177 public function getLastFinishedAttempt(): ?int
178 {
179 return $this->last_finished_attempt;
180 }
181
182 public function hasUnfinishedAttempts(): bool
183 {
184 return $this->unfinished_attempts;
185 }
186
187 public function getFirstAccess(): ?\DateTimeImmutable
188 {
189 return $this->first_access;
190 }
191
192 public function getLastAccess(): ?\DateTimeImmutable
193 {
194 return $this->last_access;
195 }
196
198 {
199 return $this->attempt_overview?->hasAnsweredQuestions() ?? false;
200 }
201
202 public function getRemainingDuration(
203 int $processing_time,
204 bool $reset_time_on_new_attempt
205 ): int {
206 $remaining = $this->getTotalDuration($processing_time);
207
208 $start = $this->getFirstAccess()?->getTimestamp();
209 if ($reset_time_on_new_attempt) {
210 $start = $this->running_attempt_start?->getTimestamp();
211 }
212
213 if ($start === null) {
214 return $remaining;
215 }
216
217 $remaining += $start;
218 if ($this->submitted) {
219 $remaining -= $this->getLastAccess()?->getTimestamp() ?? time();
220 } else {
221 $remaining -= time();
222 }
223
224 return max(0, $remaining);
225 }
226
228 {
229 return $this->attempt_overview;
230 }
231
232 public function withAttemptOverviewInformation(?AttemptOverview $attempt_overview): self
233 {
234 $clone = clone $this;
235 $clone->attempt_overview = $attempt_overview;
236 return $clone;
237 }
238
239 public function withRunningAttemptStart(\DateTimeImmutable $start_date): self
240 {
241 $clone = clone $this;
242 $clone->running_attempt_start = $start_date;
243 return $clone;
244 }
245
246 public function isScoringFinalized(): bool
247 {
248 return $this->scoring_finalized;
249 }
250
251 public function getDisplayName(Language $language, bool $anonymous_test = false): string
252 {
253 if ($this->user_id === ANONYMOUS_USER_ID && $this->importname !== null && $this->importname !== '') {
254 return "{$this->importname} ({$language->txt('imported')})";
255 }
256
257 if ($anonymous_test) {
258 return $language->txt('anonymous');
259 }
260
261 if ($this->login === '' && $this->firstname === '' && $this->lastname === '') {
262 return $language->txt('user_deleted');
263 }
264
265 $display_name = '';
266
267 if ($this->lastname !== '') {
268 $display_name .= $this->lastname;
269 }
270
271 if ($this->firstname !== '') {
272 $display_name .= $display_name === ''
273 ? $this->firstname
274 : ", {$this->firstname}";
275 }
276
277 return $display_name;
278 }
279}
getDisplayName(Language $language, bool $anonymous_test=false)
getTotalDuration(?int $processing_time)
withRunningAttemptStart(\DateTimeImmutable $start_date)
withAttemptOverviewInformation(?AttemptOverview $attempt_overview)
__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 $importname=null, 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:31
getRemainingDuration(int $processing_time, bool $reset_time_on_new_attempt)
DateTimeImmutable $running_attempt_start
Definition: Participant.php:29
const ANONYMOUS_USER_ID
Definition: constants.php:27
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
$n selects a plural form, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Participant.php:21