Przeglądaj źródła

Validate bar arrival time

Alan Lam 2 lat temu
rodzic
commit
aff0be3eee

+ 22 - 0
template_processing/age_verification_greene_king/test_validate.php

@@ -5,12 +5,15 @@
  * @var FormException $form_exception
  * @var FormException $form_exception
  */
  */
 
 
+use Carbon\CarbonImmutable;
+
 if($test->dts_start && $test->dts_end) {
 if($test->dts_start && $test->dts_end) {
 	$dt_start = $test->getDateTimeStart();
 	$dt_start = $test->getDateTimeStart();
 	$dt_end = $test->getDateTimeEnd();
 	$dt_end = $test->getDateTimeEnd();
 
 
 	$duration = $dt_end->diffInMinutes($dt_start);
 	$duration = $dt_end->diffInMinutes($dt_start);
 
 
+	/** @var string[] $values */
 	$values = $test->getValues(true);
 	$values = $test->getValues(true);
 
 
 	$line_of_sight = (bool) ($values["play_machine_line_of_sight"] ?? false);
 	$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) {
 	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).");
 		$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.");
+			}
+		}
+	}
+
+
 }
 }