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