1
0

test_validate.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. /**
  3. * @var Test $test
  4. * @var FormException $form_exception
  5. */
  6. $project = $test->getProject();
  7. if($test->dts_start && $test->dts_end && $project && $project->browse_time && $project->play_time) {
  8. $dt_start = $test->getDateTimeStart()->setTimezone(TIMEZONE);
  9. $dt_end = $test->getDateTimeEnd()->setTimezone(TIMEZONE);
  10. $duration = $dt_end->diffInMinutes($dt_start);
  11. /** @var string[] $values */
  12. $values = $test->getValues(true);
  13. $play_minutes = (int) ($values["play_minutes"] ?? 0);
  14. $challenge_stage = (int) $test->challenge_stage;
  15. // Calculate minimum duration
  16. $min_duration = 0;
  17. if($test->challenge_stage >= 3) {
  18. $min_duration += $project->browse_time;
  19. }
  20. if($test->challenge_stage >= 4) {
  21. $min_duration += $project->play_time;
  22. }
  23. if($play_minutes < $project->play_time && in_array($challenge_stage, [4, 5])) {
  24. $form_exception->addError("Please confirm that you played for at least {$project->play_time} minutes because you have selected After Play / No Challenge.");
  25. }
  26. if($duration < $min_duration) {
  27. $form_exception->addError("Please check the entry and exit times. Based on the information you have given, you should have been at the venue for $min_duration minutes or more.");
  28. }
  29. }