26{
27 case NOT_YET_STARTED = 'not_started';
28 case RUNNING = 'running';
29 case FINISHED_BY_UNKNOWN = 'finished_by_unknown';
30 case FINISHED_BY_ADMINISTRATOR = 'finished_by_administrator';
31 case FINISHED_BY_DURATION = 'finished_by_duration';
32 case FINISHED_BY_PARTICIPANT = 'finished_by_participant';
33 case FINISHED_BY_CRONJOB = 'finished_by_cronjob';
34
36 {
37 return in_array($this, [
38 self::FINISHED_BY_UNKNOWN,
39 self::FINISHED_BY_ADMINISTRATOR,
40 self::FINISHED_BY_CRONJOB,
41 self::FINISHED_BY_DURATION,
42 self::FINISHED_BY_PARTICIPANT,
43 ]);
44 }
45
46 public static function build(
int $current_attempt, ?
int $last_finished_attempt, ?
string $finalized_by):
StatusOfAttempt
47 {
48 if ($last_finished_attempt === null || $current_attempt > $last_finished_attempt) {
49 return StatusOfAttempt::RUNNING;
50 }
51
52 if ($finalized_by === null || $finalized_by === '') {
53 return StatusOfAttempt::FINISHED_BY_UNKNOWN;
54 }
55
56 return StatusOfAttempt::tryFrom($finalized_by);
57 }
58
59 public function getTranslation(Language
$lng): string
60 {
61 return $lng->txt($this->value);
62 }
63}