Explorar o código

Allow testers to amend their test answers if the test is unverified.

Alan Lam %!s(int64=8) %!d(string=hai) anos
pai
achega
169b3337a6
Modificáronse 4 ficheiros con 115 adicións e 34 borrados
  1. 18 10
      controllers/test.php
  2. 1 1
      engine/user.php
  3. 39 0
      views/test_form.php
  4. 57 23
      views/test_list_assigned.php

+ 18 - 10
controllers/test.php

@@ -5,6 +5,10 @@ Core::addScript("public/js/app-test.js");
 $test = Test::get($id);
 if(!$test) throw new Exception("Test cannot be found.");
 
+$is_confirmed = $test->status == Test::STATUS_CONFIRMED;
+$is_started = $test->status == Test::STATUS_STARTED;
+$is_unverified = $test->status == Test::STATUS_PENDING_VERIFICATION;
+
 $location = $test->getLocation();
 $project = $test->getProject();
 $tester = $test->getTester();
@@ -27,7 +31,7 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 	if($test->status == Test::STATUS_ASSIGNED) throw new Exception("You do not have permission to view this page as you have not accepted the test yet.");
 
 	// Show completed message
-	if($test->status >= Test::STATUS_PENDING_VERIFICATION) {
+	if($test->status > Test::STATUS_PENDING_VERIFICATION) {
 		View::includeOnce("header", compact("page_title"));
 		View::include("test_form", compact("test", "location", "project", "template"));
 		View::includeOnce("footer");
@@ -48,18 +52,20 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 
 			$form_exception = new FormException;
 
-			if($test->status == Test::STATUS_CONFIRMED) {
+			if($is_confirmed) {
 				// Parse before the test form
 				$fields = $json->beforeTest;
 
 			}
 
-			if($test->status == Test::STATUS_STARTED) {
+			if($is_started || $is_unverified) {
 				// Parse after the test form
 				$fields = $json->duringTest;
 
-				$duration = http::value("duration", "int");
-				if(!$duration) $form_exception->addError("Duration was not submitted.");
+				if($is_started) {
+					$duration = http::value("duration", "int");
+					if(!$duration) $form_exception->addError("Duration was not submitted.");
+				}
 
 			}
 
@@ -131,7 +137,7 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 			if($form_exception->hasErrors()) throw $form_exception;
 
 			// Before the Test
-			if($test->status == Test::STATUS_CONFIRMED) {
+			if($is_confirmed) {
 				$test->status = Test::STATUS_STARTED;
 				$test->dts_start = Util::getDateTime();
 				$test->dts_updated = Util::getDateTime();
@@ -143,13 +149,15 @@ if(Core::$user->level == User::LEVEL_TESTER) {
 			}
 
 			// During the test
-			if($test->status == Test::STATUS_STARTED) {
+			if($is_started || $is_unverified) {
 				$test->status = Test::STATUS_PENDING_VERIFICATION;
 
-				$unix_start = strtotime($test->dts_start);
-				$unix_end = $unix_start + floor($duration / 1000); // $duration is milliseconds
+				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);
+					$test->dts_end = date("Y-m-d H:i:s", $unix_end);
+				}
 
 				$test->pass = ($test->challenge_stage <= 2) ? 1 : 0; // Pass = Challenged during browsing or before
 				$test->dts_updated = Util::getDateTime();

+ 1 - 1
engine/user.php

@@ -270,7 +270,7 @@ class User extends Model {
 	public function getPendingTests() {
 		return Test::query([
 			"tester_id" => $this->id,
-			"status" => [Test::STATUS_ASSIGNED, Test::STATUS_CONFIRMED],
+			"status" => [Test::STATUS_ASSIGNED, Test::STATUS_CONFIRMED, Test::STATUS_PENDING_VERIFICATION],
 		], [
 			"sort" => "id",
 			"order" => "desc"

+ 39 - 0
views/test_form.php

@@ -6,6 +6,45 @@ if($test->status == Test::STATUS_CONFIRMED) {
 else if($test->status == Test::STATUS_STARTED) {
 	$template->renderDuringTestForm();
 }
+else if($test->status == Test::STATUS_PENDING_VERIFICATION) {
+
+	$json = json_decode($template->json);
+	$fields = $json->duringTest;
+
+	$values = $test->getValues(true);
+
+	?>
+	<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.
+	</div>
+
+	<form method="post" id="test-form">
+	<?php
+	foreach($fields as $field) {
+
+		$name = $field->name ?? false;
+		if($name) {
+			if(isset($test->$name)) $field->value = $test->$name;
+			if(isset($values[$name])) $field->value = $values[$name];
+		}
+		Form::renderField($field);
+	}
+	?>
+		<div class="bg-light text-center p-3 mt-3">
+			<input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
+			<button class="btn btn-block btn-primary" type="submit" id="test-submit-button">Submit Test Results</button>
+			<small class="form-text text-muted d-none" id="test-no-internet-text">
+				<span class="text-danger">No Internet Connectivity</span><br />
+				Please check your Internet connectivity and try again.
+			</small>
+			<small id="test-submit-status">
+
+			</small>
+		</div>
+	</form>
+	<?php
+}
 else {
 	?>
 	<h2>Test Completed</h2>

+ 57 - 23
views/test_list_assigned.php

@@ -15,38 +15,72 @@
 	}
 	else {
 		?>
-		<div class="list-group">
+		<table class="table table-sm table-hover">
+			<thead>
+				<th>ID</th>
+				<th>Location</th>
+				<th>Date Due</th>
+				<th>Status</th>
+				<th></th>
+			</thead>
 		<?php
 		foreach($tests as $test) {
 			$location = $test->getLocation();
+			$project = $test->getProject();
+
+			$dts_due = $test->dts_due ?? $project->dts_deadline;
+			$date_due = explode(" ", $dts_due)[0];
+			$date_due = date("d/m/Y", strtotime($date_due));
+
+			$is_assigned = $test->status == Test::STATUS_ASSIGNED;
+			$is_confirmed = $test->status == Test::STATUS_CONFIRMED;
+			$is_unverified = $test->status == Test::STATUS_PENDING_VERIFICATION;
+
+			$status_text = $test->getStatusText();
+			if($is_unverified) $status_text = "Unverified";
+
 			?>
-			<div class="list-group-item">
-				<div class="row">
-					<div class="col">
-						<?=htmlspecialchars($location->name)?><br />
-						<?=htmlspecialchars($location->getDisplayAddress())?>
-					</div>
-					<div class="col-auto align-self-center">
+			<tr>
+				<td>
+					<?=$test->id?>
+				</td>
+				<td>
+					<?=htmlspecialchars($location->name)?><br />
+					<small><?=htmlspecialchars($location->getDisplayAddress())?></small>
+				</td>
+				<td class="align-middle">
+					<?=$date_due?>
+				</td>
+				<td class="text-center align-middle">
+					<span class="badge badge-lg badge-<?=$test->getStatusClass()?>">
+						<?=$status_text?>
+					</span>
+				</td>
+				<td class="text-right align-middle">
+				<?php
+				if($is_assigned) {
+					?>
+					<a class="btn btn-outline-success" href="/account/tests/<?=$test->id?>/accept">Accept</a>
+					<a class="btn btn-outline-danger" href="/account/tests/<?=$test->id?>/decline">Decline</a>
 					<?php
-					if($test->status == Test::STATUS_ASSIGNED) {
-						?>
-						<a class="btn btn-outline-success" href="/account/tests/<?=$test->id?>/accept">Accept</a>
-						<a class="btn btn-outline-danger" href="/account/tests/<?=$test->id?>/decline">Decline</a>
-						<?php
-					}
-					else {
-						?>
-						<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>" title="Begin" data-toggle="tooltip">Begin</a>
-						<?php
-					}
+				}
+				else if($is_confirmed) {
 					?>
-					</div>
-				</div>
-			</div>
+					<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">Begin</a>
+					<?php
+				}
+				else if($is_unverified) {
+					?>
+					<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">Amend</a>
+					<?php
+				}
+				?>
+				</td>
+			</tr>
 			<?php
 		}
 		?>
-		</div>
+		</table>
 		<?php
 	}