Alan Lam 2 лет назад
Родитель
Сommit
aff0be3eee
1 измененных файлов с 22 добавлено и 0 удалено
  1. 22 0
      template_processing/age_verification_greene_king/test_validate.php

+ 22 - 0
template_processing/age_verification_greene_king/test_validate.php

@@ -5,12 +5,15 @@
  * @var FormException $form_exception
  */
 
+use Carbon\CarbonImmutable;
+
 if($test->dts_start && $test->dts_end) {
 	$dt_start = $test->getDateTimeStart();
 	$dt_end = $test->getDateTimeEnd();
 
 	$duration = $dt_end->diffInMinutes($dt_start);
 
+	/** @var string[] $values */
 	$values = $test->getValues(true);
 
 	$line_of_sight = (bool) ($values["play_machine_line_of_sight"] ?? false);
@@ -33,4 +36,23 @@ if($test->dts_start && $test->dts_end) {
 	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 = CarbonImmutable::instance($dt_start)->setTimeFromTimeString($bar_time);
+
+			$start_time = $dt_start->format("H:i");
+			$end_time = $dt_end->format("H:i");
+
+			if($dt_bar < $dt_start || $dt_bar > $dt_end) {
+				$form_exception->addError("Bar arrival time must be between $start_time and $end_time.");
+			}
+		}
+	}
+
+
 }