ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 isInvitedParticipant(): bool
149 {
150 return $this->invitation_date > 0;
151 }
152
153 public function getSubmitted(): ?bool
154 {
155 return $this->submitted;
156 }
157
158 public function getTotalDuration(?int $processing_time): int
159 {
160 if (!$processing_time) {
161 return 0;
162 }
163
164 return $processing_time + $this->extra_time * 60;
165 }
166
167 public function getLastStartedAttempt(): ?int
168 {
169 return $this->last_started_attempt;
170 }
171
172 public function getLastFinishedAttempt(): ?int
173 {
174 return $this->last_finished_attempt;
175 }
176
177 public function hasUnfinishedAttempts(): bool
178 {
179 return $this->unfinished_attempts;
180 }
181
182 public function getFirstAccess(): ?\DateTimeImmutable
183 {
184 return $this->first_access;
185 }
186
187 public function getLastAccess(): ?\DateTimeImmutable
188 {
189 return $this->last_access;
190 }
191
193 {
194 return $this->attempt_overview?->hasAnsweredQuestions() ?? false;
195 }
196
197 public function getRemainingDuration(
198 int $processing_time,
199 bool $reset_time_on_new_attempt
200 ): int {
201 $remaining = $this->getTotalDuration($processing_time);
202
203 $start = $this->getFirstAccess()?->getTimestamp();
204 if ($reset_time_on_new_attempt) {
205 $start = $this->running_attempt_start?->getTimestamp();
206 }
207
208 if ($start === null) {
209 return $remaining;
210 }
211
212 $remaining += $start;
213 if ($this->submitted) {
214 $remaining -= $this->getLastAccess()?->getTimestamp() ?? time();
215 } else {
216 $remaining -= time();
217 }
218
219 return max(0, $remaining);
220 }
221
223 {
224 return $this->attempt_overview;
225 }
226
227 public function withAttemptOverviewInformation(?AttemptOverview $attempt_overview): self
228 {
229 $clone = clone $this;
230 $clone->attempt_overview = $attempt_overview;
231 return $clone;
232 }
233
234 public function withRunningAttemptStart(\DateTimeImmutable $start_date): self
235 {
236 $clone = clone $this;
237 $clone->running_attempt_start = $start_date;
238 return $clone;
239 }
240
241 public function isScoringFinalized(): bool
242 {
243 return $this->scoring_finalized;
244 }
245
246 public function getDisplayName(Language $language, bool $anonymous_test = false): string
247 {
248 if ($this->user_id === ANONYMOUS_USER_ID && $this->importname !== null && $this->importname !== '') {
249 return "{$this->importname} ({$language->txt('imported')})";
250 }
251
252 if ($anonymous_test) {
253 return $language->txt('anonymous');
254 }
255
256 $display_name = '';
257
258 if ($this->firstname) {
259 $display_name .= $this->firstname . ' ';
260 }
261 if ($this->lastname) {
262 $display_name .= $this->lastname;
263 }
264
265 return $display_name;
266 }
267}
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 $a_topic, string $a_default_lang_fallback_mod="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Participant.php:21