ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcAssMemberState.php
Go to the documentation of this file.
1<?php
2
47{
48 protected int $ass_id;
49 protected int $user_id;
51 protected int $time;
52 protected ilLanguage $lng;
53
58 protected ?int $member_id;
59 protected ?int $team_id = 0;
60 protected bool $is_team = false;
62
63 protected function __construct(
64 ilExAssignment $a_ass,
65 ilObjUser $a_user,
67 int $a_time,
69 ?ilExAssignmentTeam $a_team = null
70 ) {
71 $this->time = $a_time;
72 $this->ass_id = $a_ass->getId();
73 $this->user_id = $a_user->getId();
74 $this->member_id = $a_user->getId();
75 $this->lng = $lng;
76
77 $this->assignment = $a_ass;
78
79 // check team status
80 $this->is_team = false;
81 if ($this->assignment->getType() == ilExAssignment::TYPE_UPLOAD_TEAM) {
82 if ($a_team->getId()) {
83 $this->member_id = $a_team->getId();
84 $this->team_id = $a_team->getId();
85 $this->is_team = true;
86 }
87 }
88
89 $this->idl = $a_idl;
90 }
91
92 // Get instance by IDs (recommended for consumer code)
93 public static function getInstanceByIds(
94 int $a_ass_id,
95 int $a_user_id = 0
97 global $DIC;
98
99 $lng = $DIC->language();
100 $user = ($a_user_id > 0)
101 ? new ilObjUser($a_user_id)
102 : $DIC->user();
103
104 $ass = new ilExAssignment($a_ass_id);
105
106 $member_id = $user->getId();
107 $is_team = false;
108 $team = null;
109 if ($ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM) { // better move this to ilExcIndividualDeadline
110 $team = ilExAssignmentTeam::getInstanceByUserId($a_ass_id, $user->getId());
111 if ($team->getId()) {
112 $member_id = $team->getId();
113 $is_team = true;
114 }
115 }
116
117 // note: team may be not null, but is_team still false
119
120 return self::getInstance($ass, $user, $idl, time(), $lng, $team);
121 }
122
126 public static function getInstance(
127 ilExAssignment $a_ass,
128 ilObjUser $a_user,
130 int $a_time,
132 ?ilExAssignmentTeam $a_team = null
134 return new self($a_ass, $a_user, $a_idl, $a_time, $lng, $a_team);
135 }
136
138 {
139 return $this->idl;
140 }
141
142 public function getGeneralStart(): ?int
143 {
144 return $this->assignment->getStartTime();
145 }
146
151 public function getGeneralStartPresentation(): string
152 {
153 if ($this->getGeneralStart()) {
154 return $this->getTimePresentation($this->getGeneralStart());
155 }
156 return "";
157 }
158
159 public function getIndividualStart(): int
160 {
161 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
162 return $this->idl->getStartingTimestamp();
163 }
164 return 0;
165 }
166
167 public function hasGenerallyStarted(): bool
168 {
169 return !$this->assignment->notStartedYet();
170 }
171
177 public function getCalculatedDeadline(): int
178 {
179 $calculated_deadline = 0;
180 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
181 if ($this->idl->getStartingTimestamp() && $this->assignment->getRelativeDeadline()) {
182 $calculated_deadline = $this->idl->getStartingTimestamp() + ($this->assignment->getRelativeDeadline() * 24 * 60 * 60);
183 }
184 if ($this->assignment->getRelDeadlineLastSubmission() > 0 &&
185 $calculated_deadline > $this->assignment->getRelDeadlineLastSubmission()) {
186 $calculated_deadline = $this->assignment->getRelDeadlineLastSubmission();
187 }
188 }
189 return $calculated_deadline;
190 }
191
192 public function getRelativeDeadlineStartLeadText(): string
193 {
194 $start_in_time = true;
195 if ($this->assignment->getRelDeadlineLastSubmission() > 0) {
196 $starting_now = time() + ($this->assignment->getRelativeDeadline() * 24 * 60 * 60);
197 if ($starting_now > $this->assignment->getRelDeadlineLastSubmission()) {
198 $start_in_time = false;
199 }
200 }
201 if ($start_in_time) {
202 $lead_text = sprintf(
203 $this->lng->txt("exc_rel_start_lead_text"),
204 $this->assignment->getRelativeDeadline()
205 );
206 if ($this->assignment->getRelDeadlineLastSubmission() > 0) {
207 $lead_text .= ", <br>" . sprintf(
208 $this->lng->txt("exc_rel_start_latest_lead_text"),
209 $this->getLastSubmissionOfRelativeDeadlinePresentation()
210 );
211 }
212 } else {
213 return sprintf(
214 $this->lng->txt("exc_hand_in_lead_text"),
215 $this->getRemainingTimePresentationOfLastSubmissionOfRelativeDeadline()
216 );
217 }
218 return $lead_text;
219 }
220
227 {
229 $last_deadline = $this->assignment->getRelDeadlineLastSubmission();
230 if ($last_deadline - $this->time <= 0) {
231 $time_str = $lng->txt("exc_time_over_short");
232 } else {
233 $time_str = ilLegacyFormElementsUtil::period2String(new ilDateTime($last_deadline, IL_CAL_UNIX));
234 }
235
236 return $time_str;
237 }
238
239
240 public function getRelativeDeadline(): int
241 {
242 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
243 return $this->assignment->getRelativeDeadline();
244 }
245 return 0;
246 }
247
249 {
250 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
251 return $this->assignment->getRelDeadlineLastSubmission();
252 }
253 return 0;
254 }
255
256 public function getRelativeDeadlinePresentation(): string
257 {
258 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
259 return $this->getRelativeDeadline() . " " . $this->lng->txt("days");
260 }
261 return "";
262 }
263
269 public function getOfficialDeadline(): int
270 {
271 $dl = $this->idl->getIndividualDeadline(); // team or user individual deadline
272
273 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_ABSOLUTE) { // absolute deadline
274 return max($this->assignment->getDeadline(), $dl); // take what's greater: idl or abs deadline
275 }
276
277 // relative deadline: take max idl or calculated deadline
278 return max($this->getCalculatedDeadline(), $dl);
279 }
280
285 public function getOfficialDeadlinePresentation(): string
286 {
287 if ($this->getOfficialDeadline() > 0) {
288 return $this->getTimePresentation($this->getOfficialDeadline());
289 }
290
291 return "";
292 }
293
299 {
300 if ($this->getLastSubmissionOfRelativeDeadline() > 0) {
301 return $this->getTimePresentation($this->getLastSubmissionOfRelativeDeadline());
302 }
303
304 return "";
305 }
306
307 // Check if official deadline exists and has ended
308 public function exceededOfficialDeadline(): bool
309 {
310 $od = $this->getOfficialDeadline();
311 if ($od && $od < time()) {
312 return true;
313 }
314 return false;
315 }
316
322 public function getRemainingTimePresentation(): string
323 {
325 $official_deadline = $this->getOfficialDeadline();
326 if ($official_deadline == 0) {
327 return $lng->txt("exc_no_deadline_specified");
328 }
329 if ($official_deadline - $this->time <= 0) {
330 $time_str = $lng->txt("exc_time_over_short");
331 } else {
332 $time_str = ilLegacyFormElementsUtil::period2String(new ilDateTime($official_deadline, IL_CAL_UNIX));
333 }
334
335 return $time_str;
336 }
337
338 public function getRemainingPeerReviewPresentation(): string
339 {
341 $official_deadline = $this->getPeerReviewDeadline();
342 if ($official_deadline == 0) {
343 return $lng->txt("exc_no_deadline_specified");
344 }
345 if ($official_deadline - $this->time <= 0) {
346 $time_str = $lng->txt("exc_time_over_short");
347 } else {
348 $time_str = ilLegacyFormElementsUtil::period2String(new ilDateTime($official_deadline, IL_CAL_UNIX));
349 }
350
351 return $time_str;
352 }
353
354 public function getRemainingTimeLeadText(): string
355 {
357 return sprintf($this->lng->txt("exc_hand_in_lead_text"), $this->getRemainingTimePresentation());
358 }
359
360 public function getPeerReviewLeadText(): string
361 {
363 if ($this->assignment->getPeerReviewDeadline() > 0) {
364 return sprintf(
365 $this->lng->txt("exc_peer_reviews_in_lead_text"),
366 $this->getRemainingPeerReviewPresentation()
367 );
368 } else {
369 return $this->lng->txt("exc_review_anytime");
370 }
371 }
372
373 public function getIndividualDeadline(): int
374 {
375 if ($this->idl->getIndividualDeadline() > $this->getCommonDeadline()) {
376 return $this->idl->getIndividualDeadline();
377 }
378 return 0;
379 }
380
385 public function getIndividualDeadlinePresentation(): string
386 {
387 if ($this->getIndividualDeadline() > 0) {
388 return $this->getTimePresentation($this->getIndividualDeadline());
389 }
390
391 return "";
392 }
393
394 // Get common deadline (no individual deadline or grace period included)
395 public function getCommonDeadline(): int
396 {
397 if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_ABSOLUTE) { // absolute deadline
398 return $this->assignment->getDeadline();
399 }
400
401 return $this->getCalculatedDeadline();
402 }
403
408 public function getCommonDeadlinePresentation(): string
409 {
410 if ($this->getCommonDeadline() > 0) {
411 return $this->getTimePresentation($this->getCommonDeadline());
412 }
413
414 return "no deadline";
415 }
416
417 // Get effective deadline (max of official deadline and grace end period) for the user
418 public function getEffectiveDeadline(): int
419 {
420 return max($this->getOfficialDeadline(), $this->assignment->getExtendedDeadline());
421 }
422
423 public function getPeerReviewDeadline(): int
424 {
425 if ($this->assignment->getPeerReview() &&
426 $this->assignment->getPeerReviewDeadline()) {
427 return $this->assignment->getPeerReviewDeadline();
428 }
429 return 0;
430 }
431
436 public function getPeerReviewDeadlinePresentation(): string
437 {
438 if ($this->getPeerReviewDeadline() > 0) {
439 return $this->getTimePresentation($this->getPeerReviewDeadline());
440 }
441
442 return "no peer review deadline";
443 }
444
445 // Is peer reviewing currently allowed
446 public function isPeerReviewAllowed(): bool
447 {
448 if ($this->assignment->getPeerReview() && $this->hasSubmissionEndedForAllUsers()
449 && ($this->getPeerReviewDeadline() == 0 || $this->getPeerReviewDeadline() > $this->time)) {
450 return true;
451 }
452
453 return false;
454 }
455
456 public function isReceivedFeedbackAccessible(): bool
457 {
458 if (!$this->isPeerReviewAllowed()) {
459 return false;
460 }
461 $submission = new ilExSubmission($this->assignment, $this->user_id);
462 $nr_missing_fb = (int) $submission->getPeerReview()?->getNumberOfMissingFeedbacksForReceived();
463 if ((!$this->assignment->getPeerReviewDeadline() ||
464 $this->assignment->getPeerReviewDeadline() < time())) {
465
466 if ($nr_missing_fb <= 0) {
467 return true;
468 }
469 }
470 return false;
471 }
472
478 protected function getTimePresentation($a_timestamp): string
479 {
480 if ($a_timestamp > 0) {
481 return ilDatePresentation::formatDate(new ilDateTime($a_timestamp, IL_CAL_UNIX));
482 }
483
484 return "";
485 }
486
487 public function areInstructionsVisible(): bool
488 {
489 return $this->hasSubmissionStarted();
490 }
491
492 public function inLateSubmissionPhase(): bool
493 {
494 // official deadline is done, but submission still allowed
495 if ($this->getOfficialDeadline() &&
496 $this->getOfficialDeadline() < $this->time &&
497 $this->isSubmissionAllowed()) {
498 return true;
499 }
500 return false;
501 }
502
503
509 public function hasSubmissionStarted(): bool
510 {
511 $deadline_type_specific_started = false;
512 switch ($this->assignment->getDeadlineMode()) {
514 $deadline_type_specific_started = true;
515 break;
517 $deadline_type_specific_started = ($this->getIndividualStart() > 0);
518 break;
520 $deadline_type_specific_started = ($this->idl->getIndividualDeadline() > 0);
521 break;
522 }
523 if ($deadline_type_specific_started && $this->hasGenerallyStarted()) {
524 return true;
525 }
526 return false;
527 }
528
529 // Check if the submission phase has ended for the current user
530 public function hasSubmissionEnded(): bool
531 {
532 if ($this->getEffectiveDeadline() == 0) {
533 return false;
534 }
535
536 if ($this->time > $this->getEffectiveDeadline()) {
537 return true;
538 }
539 return false;
540 }
541
545 public function hasEnded(): bool
546 {
547 if ($this->hasSubmissionEnded()) {
548 if (!$this->assignment->getPeerReview() || ($this->getPeerReviewDeadline() !== 0 && $this->getPeerReviewDeadline() < $this->time)) {
549 return true;
550 }
551 }
552 return false;
553 }
554
555 public function isFuture(): bool
556 {
557 return !$this->hasGenerallyStarted();
558 }
559
560 // Has submission ended for all users
561 public function hasSubmissionEndedForAllUsers(): bool
562 {
563 $global_subm_end = max($this->getEffectiveDeadline(), $this->assignment->getLastPersonalDeadline());
564
565 if ($global_subm_end == 0) {
566 return false;
567 }
568
569 if ($this->time > $global_subm_end) {
570 return true;
571 }
572 return false;
573 }
574
575 public function isSubmissionAllowed(): bool
576 {
577 if ($this->hasSubmissionStarted() && !$this->hasSubmissionEnded()) {
578 return true;
579 }
580 return false;
581 }
582
583 // Is global feedback file accessible?
584 public function isGlobalFeedbackFileAccessible(ilExSubmission $submission): bool
585 {
586 if (!$this->assignment->getFeedbackFile()) {
587 return false;
588 }
589
590 // global feedback / sample solution
591 if ($this->assignment->getFeedbackDate() == ilExAssignment::FEEDBACK_DATE_DEADLINE) {
592 $access = $this->hasSubmissionEndedForAllUsers();
593 } elseif ($this->assignment->getFeedbackDate() == ilExAssignment::FEEDBACK_DATE_CUSTOM) {
594 $access = $this->assignment->afterCustomDate();
595 } else {
596 $access = $submission->hasSubmitted();
597 }
598
599 return $access;
600 }
601
602 public function needsIndividualDeadline(): bool
603 {
604 if ($this->assignment->getDeadlineMode() === ilExAssignment::DEADLINE_ABSOLUTE_INDIVIDUAL && $this->idl->getIndividualDeadline() === 0) {
605 return true;
606 }
607 return false;
608 }
609
610 public function hasRequestedIndividualDeadline(): bool
611 {
612 return $this->idl->getRequested();
613 }
614
615}
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByUserId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
Exercise assignment.
Exercise submission //TODO: This class has many static methods related to delivered "files".
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRemainingTimePresentationOfLastSubmissionOfRelativeDeadline()
Remaining time for last submission of relative deadline.
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
static getInstance(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, int $a_time, ilLanguage $lng, ?ilExAssignmentTeam $a_team=null)
Usually you should prefer to use getInstanceByIds.
getOfficialDeadline()
Get official deadline (individual deadline, fixed deadline or calculated deadline (using relative dea...
getRemainingTimePresentation()
Remaining time presentation (based on official deadline)
hasSubmissionStarted()
Check if the submission phase has started for the current user (if the assignment is generally starte...
hasEnded()
Check if assignment has ended for current user.
int $member_id
either user id or team id, if this is a team assignment and the user is member of a team,...
isGlobalFeedbackFileAccessible(ilExSubmission $submission)
__construct(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, int $a_time, ilLanguage $lng, ?ilExAssignmentTeam $a_team=null)
ilExcIndividualDeadline $idl
getCalculatedDeadline()
Calculated deadline is only given, if a relative deadline is given and the user started the assignmen...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $a_ass_id, int $a_participant_id, bool $a_is_team=false)
language handling
static period2String(ilDateTime $a_from, $a_to=null)
Return a string of time period.
User class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26