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