Переглянути джерело

Allow Retests to be created at any time on Verify Form

Alan Lam 7 роки тому
батько
коміт
b1d4990a82
2 змінених файлів з 31 додано та 27 видалено
  1. 13 12
      controllers/test.php
  2. 18 15
      views/test_verify_form.php

+ 13 - 12
controllers/test.php

@@ -362,6 +362,17 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 			$success = $test->commit();
 			if(!$success) throw new Exception("Failed to update the test. Please try again later.");
 
+
+			if($retest_project) {
+				$retest = new Test;
+				$retest->project_id = $retest_project->id;
+				$retest->location_id = $location->id;
+				$retest->status = Test::STATUS_UNASSIGNED;
+				$retest->dts_created = Util::getDateTime();
+				$retest->retest = 1;
+				$success = $retest->commit();
+			}
+
 			// If rejected, recreate empty test for the location
 			if($reject) {
 				$new_test = new Test;
@@ -377,16 +388,6 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 				$tester->score++;
 				$tester->commit();
 
-				if(!$test->pass && $retest_project) {
-					$retest = new Test;
-					$retest->project_id = $retest_project->id;
-					$retest->location_id = $location->id;
-					$retest->status = Test::STATUS_UNASSIGNED;
-					$retest->dts_created = Util::getDateTime();
-					$retest->retest = 1;
-					$success = $retest->commit();
-				}
-
 				// Save PDF
 				$mpdf = $test->getMPDF();
 				$pdf_string = $mpdf->Output("", "S");
@@ -445,6 +446,8 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 	}
 
 	$projects = $customer->getProjects();
+
+	/** @var Project[] $future_projects */
 	$future_projects = array_filter($projects, function($p) use ($project) {
 		if($p->id == $project->id) return false;
 		if($p->template_id != $project->template_id) return false;
@@ -465,5 +468,3 @@ else if(Core::$user->level >= User::LEVEL_VENUE) {
 else {
 	throw new Exception(__("Invalid request."));
 }
-
-?>

+ 18 - 15
views/test_verify_form.php

@@ -2,6 +2,8 @@
 
 /**
  * @var Test $test
+ * @var Project[] $future_projects
+ * @var string $tester_message
  */
 
 $test_details = [
@@ -373,24 +375,25 @@ function render_card_list_group($details) {
 							</div>
 						</div>
 
+                        <div class="row mb-1">
+                            <label class="col-sm-4 col-form-label" for="retest-project-id">Create Retest</label>
+                            <div class="col-sm">
+                                <select class="form-control" name="retest_project_id" id="retest-project-id">
+                                    <option value="0">None</option>
+									<?php
+									foreach($future_projects as $future_project) {
+										?>
+                                        <option value="<?=$future_project->id?>"><?=htmlspecialchars($future_project->name)?></option>
+										<?php
+									}
+									?>
+                                </select>
+                            </div>
+                        </div>
+
 						<?php
 						if($test->status == Test::STATUS_PENDING_VERIFICATION) {
 							?>
-							<div class="row mb-1">
-								<div class="col-sm-4 col-form-label">Create Retest</div>
-								<div class="col-sm">
-									<select class="form-control" name="retest_project_id">
-										<option value="0">None</option>
-										<?php
-										foreach($future_projects as $future_project) {
-											?>
-											<option value="<?=$future_project->id?>"><?=htmlspecialchars($future_project->name)?></option>
-											<?php
-										}
-										?>
-									</select>
-								</div>
-							</div>
 							<?php
 							if($customer->email) {
 								?>