ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilStudyProgrammeProgress.php
Go to the documentation of this file.
1<?php declare(strict_types = 1);
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5
21{
22 // The progress of a user on a program node can have different status that
23 // determine how the node is taken into account for calculation of the learning
24 // progress.
25
26 // User needs to be successful in the node, but currently isn't.
28 // User has completed the node successfully according to the program nodes mode.
30 // User was marked as successful in the node without actually having
31 // successfully completed the program node according to his mode.
33 // The user does not need to be successful in this node.
35 // The user does not need to be successful in this node.
36 const STATUS_FAILED = 5;
37
38 public static $STATUS = [
44 ];
45
46 const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
47 const DATE_FORMAT = 'Y-m-d';
48 const DATE_FORMAT_ENDOFDAY = 'Y-m-d 23:59:59';
49
61 protected $id;
62
68 protected $assignment_id;
69
75 protected $prg_id;
76
82 protected $usr_id;
83
91 protected $points = 0;
92
98 protected $points_cur = 0;
99
105 protected $status;
106
115 protected $completion_by;
116
117
124 protected $last_change;
125
132
139
146
152 protected $deadline;
153
159 protected $vq_date;
160
166 protected $invalidated = false;
167
171 protected $is_individual = false;
172
173
174
175 public function __construct(int $id)
176 {
177 $this->id = $id;
178 }
179
185 public function getId() : int
186 {
187 return $this->id;
188 }
189
193 public function getAssignmentId() : int
194 {
196 }
197
199 {
200 $clone = clone $this;
201 $clone->assignment_id = $assignment_id;
202 return $clone;
203 }
204
208 public function getNodeId() : int
209 {
210 return $this->prg_id;
211 }
212
214 {
215 $clone = clone $this;
216 $clone->prg_id = $prg_id;
217 return $clone;
218 }
219
223 public function getUserId() : int
224 {
225 return $this->usr_id;
226 }
227
229 {
230 $clone = clone $this;
231 $clone->usr_id = $usr_id;
232 return $clone;
233 }
234
240 public function getAmountOfPoints() : int
241 {
242 return $this->points;
243 }
244
249 {
250 if ($points < 0) {
251 throw new ilException("ilStudyProgrammeProgress::setAmountOfPoints: "
252 . "Expected a number >= 0 as argument, got '$points'");
253 }
254
255 $clone = clone $this;
256 $clone->points = $points;
257 return $clone;
258 }
259
260 public function getCurrentAmountOfPoints() : int
261 {
262 return $this->points_cur;
263 }
264
270 {
271 if ($points_cur < 0) {
272 throw new ilException("ilStudyProgrammeProgress::setAmountOfPoints: "
273 . "Expected a number >= 0 as argument, got '$points'");
274 }
275 $clone = clone $this;
276 $clone->points_cur = $points_cur;
277 return $clone;
278 }
279
285 public function getStatus() : int
286 {
287 return $this->status;
288 }
289
295 {
296 if (!in_array($status, self::$STATUS)) {
297 throw new ilException("No such status: " . "'$status'");
298 }
299
300 if (!$this->isTransitionAllowedTo($status)) {
301 throw new ilException(
302 "Changing progress with status " . $this->getStatus()
303 . " cannot change to status " . "'$status'"
304 . ' (progress_id: ' . $this->getId() . ')'
305 );
306 }
307
308 $clone = clone $this;
309 $clone->status = $status;
310 return $clone;
311 }
312
313 public function isTransitionAllowedTo(int $new_status) : bool
314 {
315 return is_null($this->status) ||
316 $this->status == $new_status ||
317 in_array($new_status, self::getAllowedTargetStatusFor($this->status));
318 }
319
320 public static function getAllowedTargetStatusFor(int $status_from) : array
321 {
322 switch ($status_from) {
324 return [
329 ];
331 return [
336 ];
338 return [
339 self::STATUS_IN_PROGRESS // deaccriditation of sub-progress might revert completion,
340 ];
342 return [
344 self::STATUS_COMPLETED, // with re-calculation of deadline, progress might directly be completed.
346 ];
348 return[
350 ];
351 }
352
353 return [];
354 }
355
361 public function getLastChangeBy()
362 {
364 }
365
366 public function getLastChange() : ?DateTimeImmutable
367 {
368 if ($this->last_change) {
369 return DateTimeImmutable::createFromFormat(self::DATE_TIME_FORMAT, $this->last_change);
370 }
371 return $this->last_change;
372 }
373
377 public function withLastChange(
378 int $last_change_by,
379 DateTimeImmutable $timestamp
381 $new_date = $timestamp->format(self::DATE_TIME_FORMAT);
382 if ($this->getLastChange() && $this->getLastChange()->format(self::DATE_TIME_FORMAT) > $new_date) {
383 throw new ilException(
384 "Cannot set last change to an earlier date:"
385 . "\ncurrent: " . $this->getLastChange()->format(self::DATE_TIME_FORMAT)
386 . "\nnew: " . $new_date,
387 1
388 );
389 }
390 $clone = clone $this;
391 $clone->last_change = $new_date;
392 $clone->last_change_by = $last_change_by;
393 return $clone;
394 }
395
396 public function getAssignmentDate() : DateTimeImmutable
397 {
398 return $this->assignment_date;
399 }
400
401 public function withAssignmentDate(DateTimeImmutable $assignment_date) : ilStudyProgrammeProgress
402 {
403 $clone = clone $this;
404 $clone->assignment_date = $assignment_date;
405 return $clone;
406 }
407
408 public function getCompletionDate() : ?DateTimeImmutable
409 {
410 return $this->completion_date;
411 }
412
417 public function getCompletionBy() : ?int
418 {
419 return $this->completion_by;
420 }
421
422 public function withCompletion(
423 int $usr_or_obj_id = null,
424 DateTimeImmutable $completion_date = null
426 $clone = clone $this;
427 $clone->completion_by = $usr_or_obj_id;
428 $clone->completion_date = $completion_date;
429 return $clone;
430 }
431
432 public function getDeadline() : ?DateTimeImmutable
433 {
434 return $this->deadline;
435 }
436
437 public function withDeadline(DateTimeImmutable $deadline = null) : ilStudyProgrammeProgress
438 {
439 $clone = clone $this;
440 $clone->deadline = $deadline;
441 return $clone;
442 }
443
444 public function getValidityOfQualification() : ?DateTimeImmutable
445 {
446 return $this->vq_date;
447 }
448
449 public function withValidityOfQualification(DateTimeImmutable $date = null) : ilStudyProgrammeProgress
450 {
451 $clone = clone $this;
452 $clone->vq_date = $date;
453 return $clone;
454 }
455
456 public function hasIndividualModifications() : bool
457 {
458 return $this->is_individual;
459 }
460
461 public function withIndividualModifications(bool $individual) : ilStudyProgrammeProgress
462 {
463 $clone = clone $this;
464 $clone->is_individual = $individual;
465 return $clone;
466 }
467
468 public function isSuccessful() : bool
469 {
470 return in_array(
471 $this->getStatus(),
472 [
473 self::STATUS_COMPLETED,
474 self::STATUS_ACCREDITED
475 ]
476 );
477 }
478
483 public function hasValidQualification(DateTimeImmutable $now) : ?bool
484 {
485 if (!$this->isSuccessful()) {
486 return null;
487 }
488 return (
489 is_null($this->getValidityOfQualification()) ||
490 $this->getValidityOfQualification()->format('Y-m-d') >= $now->format('Y-m-d')
491 );
492 }
493
494 public function isRelevant() : bool
495 {
496 return $this->getStatus() != self::STATUS_NOT_RELEVANT;
497 }
498
499 public function isFailed() : bool
500 {
501 return $this->getStatus() == self::STATUS_FAILED;
502 }
503
504 public function isAccredited() : bool
505 {
506 return $this->getStatus() == self::STATUS_ACCREDITED;
507 }
508
509 public function isInProgress() : bool
510 {
511 return $this->getStatus() == self::STATUS_IN_PROGRESS;
512 }
513
515 {
516 if (!$this->vq_date || $this->vq_date->format('Y-m-d') > date('Y-m-d')) {
517 throw new ilException("may not invalidate non-expired progress");
518 }
519 $clone = clone $this;
520 $clone->invalidated = true;
521 return $clone;
522 }
523
524 public function isInvalidated() : bool
525 {
526 return $this->invalidated;
527 }
528
532 public function isSuccessfulExpired() : bool
533 {
534 if (
535 !is_null($this->getValidityOfQualification()) &&
536 $this->getValidityOfQualification()->format('Y-m-d') < (new DateTimeImmutable())->format('Y-m-d')
537 ) {
538 return true;
539 }
540 return false;
541 }
542
543 public function markAccredited(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
544 {
545 return $this
546 ->withStatus(self::STATUS_ACCREDITED)
547 ->withCompletion($acting_usr_id, $date)
548 ->withLastChange($acting_usr_id, $date);
549 }
550
551 public function unmarkAccredited(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
552 {
553 return $this
554 ->withStatus(self::STATUS_IN_PROGRESS)
555 ->withCompletion(null, null)
556 ->withValidityOfQualification(null)
557 ->withLastChange($acting_usr_id, $date);
558 }
559
560 public function markFailed(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
561 {
562 return $this
563 ->withStatus(self::STATUS_FAILED)
564 ->withCompletion(null, null)
565 ->withLastChange($acting_usr_id, $date);
566 }
567
568 public function markNotFailed(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
569 {
570 return $this
571 ->withStatus(self::STATUS_IN_PROGRESS)
572 ->withCompletion(null, null)
573 ->withLastChange($acting_usr_id, $date);
574 }
575
576 public function succeed(DateTimeImmutable $date, int $triggering_obj_id) : ilStudyProgrammeProgress
577 {
578 return $this
579 ->withStatus(self::STATUS_COMPLETED)
580 ->withCompletion($triggering_obj_id, $date)
581 ->withLastChange($triggering_obj_id, $date);
582 }
583
584 public function markNotRelevant(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
585 {
586 return $this
587 ->withStatus(self::STATUS_NOT_RELEVANT)
588 ->withLastChange($acting_usr_id, $date)
589 ->withValidityOfQualification(null)
590 ->withDeadline(null)
591 ->withIndividualModifications(true);
592 }
593
594 public function markRelevant(DateTimeImmutable $date, int $acting_usr_id) : ilStudyProgrammeProgress
595 {
596 return $this
597 ->withStatus(self::STATUS_IN_PROGRESS)
598 ->withCompletion(null, null)
599 ->withLastChange($acting_usr_id, $date)
600 ->withIndividualModifications(true);
601 }
602}
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
An exception for terminatinating execution or to throw for unit testing.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilStudyProgrammeProgress.
withAssignmentDate(DateTimeImmutable $assignment_date)
withAmountOfPoints(int $points)
Throws when amount of points is smaller then zero.
markNotRelevant(DateTimeImmutable $date, int $acting_usr_id)
getId()
Get the id of the progress.
markRelevant(DateTimeImmutable $date, int $acting_usr_id)
withLastChange(int $last_change_by, DateTimeImmutable $timestamp)
markAccredited(DateTimeImmutable $date, int $acting_usr_id)
getAssignmentId()
Get the assignment this progress belongs to.
withCurrentAmountOfPoints(int $points_cur)
Set the amount of points the user currently has achieved on this node.
markNotFailed(DateTimeImmutable $date, int $acting_usr_id)
withCompletion(int $usr_or_obj_id=null, DateTimeImmutable $completion_date=null)
unmarkAccredited(DateTimeImmutable $date, int $acting_usr_id)
getAmountOfPoints()
Get the amount of points the user needs to achieve on the subnodes of this node.
getStatus()
Get the status the user has on this node.
getUserId()
Get the id of the user this progress is for.
withValidityOfQualification(DateTimeImmutable $date=null)
getCompletionBy()
Get the id of object or user that lead to the successful completion of this node.
static getAllowedTargetStatusFor(int $status_from)
hasValidQualification(DateTimeImmutable $now)
There may be no qualification at all (since the PRG is not passed), or the qualification is valid or ...
getLastChangeBy()
Get the id of the user/object who/which invoked the last change on this assignment.
succeed(DateTimeImmutable $date, int $triggering_obj_id)
withStatus(int $status)
Set the status of this node.
withDeadline(DateTimeImmutable $deadline=null)
markFailed(DateTimeImmutable $date, int $acting_usr_id)
getNodeId()
Get the obj_id of the program node this progress belongs to.