Alan Lam 8 лет назад
Родитель
Сommit
bdf7109eae
3 измененных файлов с 28 добавлено и 98 удалено
  1. 23 25
      controllers/test.php
  2. 5 20
      engine/template.php
  3. 0 53
      public/js/app-test.js

+ 23 - 25
controllers/test.php

@@ -59,9 +59,25 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 				// Parse after the test form
 				$fields = $json->duringTest;
 
+				// Start/End times
 				if($is_started) {
-					$duration = http::value("duration", "int");
-					if(!$duration) $form_exception->addError("Duration was not submitted.");
+					$start_override = http::getDateTimeFromFields("start_override");
+					$end_override = http::getDateTimeFromFields("end_override");
+
+					$start_unix = null;
+					$end_unix = null;
+
+					if($start_override && $end_override) {
+						$start_unix = strtotime($start_override);
+						$end_unix = strtotime($end_override);
+
+						if($start_unix > $end_unix) $form_exception->addError("Entry Time must not be after Exit Time.");
+						if(!$start_unix && $end_unix && $test->dts_start) {
+							$recorded_start_unix = Util::getUnixTimeFromUTC($test->dts_start);
+							if($end_unix < $recorded_start_unix) $form_exception->addError("Exit Time cannot be later than the recorded Entry Time.");
+						}
+					}
+
 				}
 
 			}
@@ -131,24 +147,6 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 
 			}
 
-			// Date/Time Overrides
-			$start_override = http::getDateTimeFromFields("start_override");
-			$end_override = http::getDateTimeFromFields("end_override");
-
-			$start_unix = null;
-			$end_unix = null;
-
-			if($start_override && $end_override) {
-				$start_unix = strtotime($start_override);
-				$end_unix = strtotime($end_override);
-
-				if($start_unix > $end_unix) $form_exception->addError("Test Start date/time must not be after Test End date/time.");
-				if(!$start_unix && $end_unix && $test->dts_start) {
-					$recorded_start_unix = Util::getUnixTimeFromUTC($test->dts_start);
-					if($end_unix < $recorded_start_unix) $form_exception->addError("Test End date/time cannot be later than the recorded start date/time.");
-				}
-			}
-
 			if($form_exception->hasErrors()) throw $form_exception;
 
 			date_default_timezone_set("UTC");
@@ -161,6 +159,8 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 				$success = $test->commit();
 				if(!$success) throw new Exception("Failed to save test. Please try again later.");
 
+				Core::addAlert("success", "Photos uploaded successfully.");
+
 				HTTP::redirect("/account/tests/$id");
 
 			}
@@ -170,15 +170,13 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 				$test->status = Test::STATUS_PENDING_VERIFICATION;
 
 				if($is_started) {
-					$unix_start = strtotime($test->dts_start);
-					$unix_end = $unix_start + floor($duration / 1000); // $duration is milliseconds
-
-					$test->dts_end = date("Y-m-d H:i:s", $unix_end);
-
 					if($start_unix && $end_unix) {
 						$test->dts_start = date("Y-m-d H:i:s", $start_unix);
 						$test->dts_end = date("Y-m-d H:i:s", $end_unix);
 					}
+					else if($end_unix) {
+						$test->dts_end = date("Y-m-d H:i:s", $end_unix);
+					}
 				}
 
 				$test->pass = ($test->challenge_stage <= 2) ? 1 : 0; // Pass = Challenged during browsing or before

+ 5 - 20
engine/template.php

@@ -66,22 +66,7 @@ class Template extends Model {
 		?>
 		<form method="post" id="test-form">
 
-			<input type="hidden" name="duration" id="duration" value="" required />
-
-			<div class="bg-light text-center p-3 mb-3" style="position: sticky; top: 104px; z-index: 1000;" id="test-stop-button-container">
-
-				<div>
-					<button class="btn btn-block btn-success mb-3" type="button" id="test-start-button">
-						Start Timer
-					</button>
-					<button class="btn btn-block btn-danger mb-3" type="button" id="test-stop-button" style="display: none;">
-						Stop Timer
-					</button>
-					<small><span id="test-duration-span">Photos uploaded successfully.<br />Please use the timer to record the duration that you were in the venue.<br /> Alternatively press <span class="text-danger">Stop Timer</span> immediately to skip the timer and note the duration in Additional Notes.</span></small>
-				</div>
-			</div>
-
-			<div class="collapse" id="test-main-form-container">
+			<div id="test-main-form-container">
 				<div class="alert alert-info">
 					<i class="fal fa-fw fa-info-circle"></i>
 					Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
@@ -93,12 +78,12 @@ class Template extends Model {
 				}
 				?>
 
-				<h3>Date/Time Overrides</h3>
+				<h3>Entry/Exit Times</h3>
 
-				<p>If you are submitting this form outside of the actual test, please use the following fields to specify when you did the test.</p>
+				<p>Please confirm your entry and exit times below. Please try to be as accurate as possible.</p>
 
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="start-override-hour">Test Start</label>
+					<label class="col-sm-4 col-form-label" for="start-override-hour">Entry Time</label>
 					<div class="col-sm">
 						<select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
 							<option value="">HH</option>
@@ -140,7 +125,7 @@ class Template extends Model {
 				</div>
 
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="end-override-hour">Test End</label>
+					<label class="col-sm-4 col-form-label" for="end-override-hour">Exit Time</label>
 					<div class="col-sm">
 						<select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
 							<option value="">HH</option>

+ 0 - 53
public/js/app-test.js

@@ -19,11 +19,6 @@ function initialiseTestForm() {
 
 	$form = $("#test-form");
 
-	$stopButtonContainer = $("#test-stop-button-container");
-
-	$startButton = $("#test-start-button");
-	$stopButton = $("#test-stop-button");
-
 	$testMainFormContainer = $("#test-main-form-container");
 	$submitButton = $("#test-submit-button");
 
@@ -31,40 +26,6 @@ function initialiseTestForm() {
 
 	$submitStatus = $("#test-submit-status");
 
-	$startButton.on("click", function(event) {
-		event.preventDefault();
-
-		var date = new Date();
-		testStartTime = date.getTime();
-
-		$startButton.detach();
-		$stopButton.show();
-
-		updateDurationText();
-		durationInterval = setInterval(updateDurationText, 1000);
-
-	});
-
-	$stopButton.on("click", function(event) {
-
-		event.preventDefault();
-
-		clearInterval(durationInterval);
-
-		var date = new Date();
-		var testEndTime = date.getTime();
-
-		var testDuration = testEndTime - testStartTime;
-
-		$("#duration").val(testDuration);
-
-		$stopButtonContainer.addClass("d-none");
-
-		$testMainFormContainer.collapse("show");
-
-	});
-
-
 	$form.on("submit", function(event) {
 
 		event.preventDefault();
@@ -94,8 +55,6 @@ function initialiseTestForm() {
 					$submitStatus.html("Error, please try again later.");
 					$submitButton.removeAttr("disabled");
 				}
-
-				console.log(data);
 			},
 			error: function(request, status, error) {
 				console.log(request, status, error);
@@ -106,16 +65,4 @@ function initialiseTestForm() {
 		});
 
 	});
-}
-
-function updateDurationText() {
-
-	var date = new Date();
-	var testEndTime = date.getTime();
-
-	var duration = testEndTime - testStartTime;
-	var secs = Math.floor(duration / 1000) % 60;
-	var mins = Math.floor(duration / 60000);
-
-	$("#test-duration-span").text(mins + " min. " + secs + " sec.");
 }