| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- /**
- * @var Test $test
- * @var FormException $form_exception
- */
- use Carbon\CarbonImmutable;
- if($test->dts_start && $test->dts_end) {
- $dt_start = $test->getDateTimeStart()->setTimezone(TIMEZONE);
- $dt_end = $test->getDateTimeEnd()->setTimezone(TIMEZONE);
- $duration = $dt_end->diffInMinutes($dt_start);
- /** @var string[] $values */
- $values = $test->getValues(true);
- $line_of_sight = (bool) ($values["play_machine_line_of_sight"] ?? false);
- $play_minutes = (int) ($values["play_minutes"] ?? 0);
- $challenge_stage = (int) $test->challenge_stage;
- // Calculate minimum duration
- $min_duration = 0;
- if($test->challenge_stage >= 2) {
- if($line_of_sight) {
- $min_duration += 1;
- }
- else {
- $min_duration += 2;
- }
- }
- $min_duration += $play_minutes;
- if(in_array($challenge_stage, [4, 5]) && $play_minutes < 3) {
- $form_exception->addError("Please confirm that you played for at least 3 minutes because you have selected After Play / No Challenge.");
- }
- if($duration < $min_duration) {
- $form_exception->addError("Please check the entry and exit times. Based on the information you have given, the minimum test duration is $min_duration minute(s).");
- }
- if((int) $test->challenge_stage === 5) {
- $bar_time = $values["bar_time"] ?? null;
- if(!$bar_time) {
- $form_exception->addError("Bar arrival time must be filled in if you were not challenged.");
- }
- else {
- $dt_bar_min = $dt_start->addMinutes($min_duration);
- $dt_bar = CarbonImmutable::instance($dt_start)->setTimeFromTimeString($bar_time);
- $start_time = $dt_start->format("H:i");
- $end_time = $dt_end->format("H:i");
- $min_bar_time = $dt_bar_min->format("H:i");
- if($dt_bar < $dt_bar_min) {
- $form_exception->addError("Bar arrival time needs to be $min_bar_time or after.");
- }
- if($dt_bar < $dt_bar_min || $dt_bar > $dt_end) {
- $form_exception->addError("Bar arrival time must be on or after $min_bar_time.");
- }
- }
- }
- }
|