Przeglądaj źródła

Cleanup code; change date/time override field format; hide second half of form when verifying if test is void

Alan Lam 5 lat temu
rodzic
commit
1f13c1f1d8
4 zmienionych plików z 80 dodań i 131 usunięć
  1. 36 42
      controllers/test_verify_form.php
  2. 2 2
      engine/model.php
  3. 18 0
      engine/test.php
  4. 24 87
      views/test_verify_form.php

+ 36 - 42
controllers/test_verify_form.php

@@ -13,16 +13,7 @@
 $customer = $project->getCustomer();
 $customer = $project->getCustomer();
 $tester = $test->getTester();
 $tester = $test->getTester();
 
 
-$json = json_decode($template->getJSON());
-$fields = array_merge($json->beforeTest, [(object) ["type" => "hr"]], $json->duringTest);
-$values = $test->getValues();
-
-$names = array_map(function($value) { return $value->name; }, $values);
-
-$values = array_combine(
-	array_map(function($value) { return $value->name; }, $values),
-	array_map(function($value) { return $value->value; }, $values)
-);
+$fields = $test->getFieldsForVerifyForm();
 
 
 $directory = $test->getDirectory();
 $directory = $test->getDirectory();
 
 
@@ -40,7 +31,7 @@ if($submit) {
 		$accept_tester_invoice = http::value("accept_tester_invoice");
 		$accept_tester_invoice = http::value("accept_tester_invoice");
 		$reject_tester_invoice = http::value("reject_tester_invoice");
 		$reject_tester_invoice = http::value("reject_tester_invoice");
 
 
-		if(($accept || $reject) && $test->status != Test::STATUS_PENDING_VERIFICATION) {
+		if(($accept || $reject) && $test->getStatus() !== Test::STATUS_PENDING_VERIFICATION) {
 			throw new Exception("This test is no longer pending verification.");
 			throw new Exception("This test is no longer pending verification.");
 		}
 		}
 
 
@@ -71,14 +62,16 @@ if($submit) {
 			$test->pass = $pass_override;
 			$test->pass = $pass_override;
 		}
 		}
 
 
-		$start_override = http::getDateTimeFromFields("start_override");
+		$start_override = HTTP::value("start_override");
 		if($start_override) {
 		if($start_override) {
-			$unix_start = strtotime($start_override);
+			$dt_start = new DateTime($start_override, new DateTimeZone(TIMEZONE));
+			$unix_start = $dt_start->format("U");
 		}
 		}
 
 
-		$end_override = http::getDateTimeFromFields("end_override");
+		$end_override = HTTP::value("end_override");
 		if($end_override) {
 		if($end_override) {
-			$unix_end = strtotime($end_override);
+			$dt_end = new DateTime($end_override, new DateTimeZone(TIMEZONE));
+			$unix_end = $dt_end->format("U");
 		}
 		}
 
 
 		if($unix_start > $unix_end) {
 		if($unix_start > $unix_end) {
@@ -101,7 +94,7 @@ if($submit) {
 			$test->test_fee = $tester_fee;
 			$test->test_fee = $tester_fee;
 		}
 		}
 
 
-		$test->test_travel_cost = HTTP::value("travel_cost", "float");
+		$test->test_travel_cost = HTTP::value("travel_cost", "float") ?? 0;
 		if($test->test_travel_cost < 0 || $test->test_travel_cost > 999.99) $form_exception->addError("Travel costs must be between 0 and 999.99.");
 		if($test->test_travel_cost < 0 || $test->test_travel_cost > 999.99) $form_exception->addError("Travel costs must be between 0 and 999.99.");
 
 
 		// Test forms
 		// Test forms
@@ -116,7 +109,7 @@ if($submit) {
 
 
 				$value = http::value($field->name, "trim");
 				$value = http::value($field->name, "trim");
 
 
-				if(in_array($field->name, Test::TEST_FIELDS)) {
+				if(in_array($field->name, Test::TEST_FIELDS, true)) {
 					$test->{$field->name} = $value;
 					$test->{$field->name} = $value;
 				}
 				}
 				else {
 				else {
@@ -177,39 +170,40 @@ if($submit) {
 			$tester->score++;
 			$tester->score++;
 			$tester->commit();
 			$tester->commit();
 
 
-			// Save PDF
-			$mpdf = $test->getMPDF();
-			$pdf_string = $mpdf->Output("", "S");
-			$pdf_path = $directory . "/pdf.pdf";
+			if($test->isVoid() === false) {
+				$mpdf = $test->getMPDF();
+				$pdf_string = $mpdf->Output("", "S");
+				$pdf_path = $directory . "/pdf.pdf";
 
 
-			$success = file_put_contents($pdf_path, $pdf_string);
+				$success = file_put_contents($pdf_path, $pdf_string);
 
 
-			$email_customer = http::value("email_customer");
-			$email_location = http::value("email_location");
-			$email_location_area_manager = http::value("email_location_area_manager");
+				$email_customer = http::value("email_customer");
+				$email_location = http::value("email_location");
+				$email_location_area_manager = http::value("email_location_area_manager");
 
 
-			if($email_customer && $customer->email_after_test && $customer->email) {
-				$test->sendResultEmail($customer->email);
-			}
+				if($email_customer && $customer->email_after_test && $customer->email) {
+					$test->sendResultEmail($customer->email);
+				}
 
 
-			if($email_location && $customer->email_locations_after_test && $location->email) {
-				$test->sendResultEmail($location->email);
-			}
+				if($email_location && $customer->email_locations_after_test && $location->email) {
+					$test->sendResultEmail($location->email);
+				}
 
 
-			if($email_location_area_manager && $customer->email_locations_after_test && $location->area_manager_email) {
-				$test->sendResultEmail($location->area_manager_email);
-			}
+				if($email_location_area_manager && $customer->email_locations_after_test && $location->area_manager_email) {
+					$test->sendResultEmail($location->area_manager_email);
+				}
 
 
-			if(EMAIL_TEST_RESULT) {
-				$test->sendResultEmail(EMAIL_TEST_RESULT);
-			}
+				if(EMAIL_TEST_RESULT) {
+					$test->sendResultEmail(EMAIL_TEST_RESULT);
+				}
 
 
-			if(EMAIL_TEST_RESULT_COPY) {
-				$test->sendResultEmail(EMAIL_TEST_RESULT_COPY);
+				if(EMAIL_TEST_RESULT_COPY) {
+					$test->sendResultEmail(EMAIL_TEST_RESULT_COPY);
+				}
 			}
 			}
 		}
 		}
 
 
-		if($test->status_tester_invoice == Test::STATUS_TESTER_INVOICE_PENDING) {
+		if($test->getTesterInvoiceStatus() === Test::STATUS_TESTER_INVOICE_PENDING) {
 
 
 			if($accept_tester_invoice) {
 			if($accept_tester_invoice) {
 				$success = $test->markTesterInvoicePaid();
 				$success = $test->markTesterInvoicePaid();
@@ -236,7 +230,7 @@ if($submit) {
 
 
 $projects = $customer->getProjects();
 $projects = $customer->getProjects();
 
 
-$future_projects = array_filter($projects, function($p) use ($project) {
+$future_projects = array_filter($projects, static function(Project $p) use ($project) {
 	if($p->id == $project->id) return false;
 	if($p->id == $project->id) return false;
 	if($p->template_id != $project->template_id) return false;
 	if($p->template_id != $project->template_id) return false;
 	$unix_deadline = Util::getUnixTimeFromUTC($p->dts_deadline);
 	$unix_deadline = Util::getUnixTimeFromUTC($p->dts_deadline);
@@ -244,5 +238,5 @@ $future_projects = array_filter($projects, function($p) use ($project) {
 });
 });
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("test_verify_form", compact("test", "tester", "location", "project", "future_projects", "customer", "template", "fields", "values", "tester_message"));
+View::include("test_verify_form", compact("test", "tester", "location", "project", "future_projects", "customer", "template", "fields", "tester_message"));
 View::includeOnce("footer");
 View::includeOnce("footer");

+ 2 - 2
engine/model.php

@@ -539,7 +539,7 @@ abstract class Model {
 			$fields = $id_field;
 			$fields = $id_field;
 			foreach($fields as $field) {
 			foreach($fields as $field) {
 				$value = $this->model_data->$field ?? null;
 				$value = $this->model_data->$field ?? null;
-				if(is_null($value)) return null;
+				if($value === null) return null;
 				$values[] = $this->model_data->$field;
 				$values[] = $this->model_data->$field;
 			}
 			}
 			return $values;
 			return $values;
@@ -548,7 +548,7 @@ abstract class Model {
 		return $this->model_data->$id_field ?? null;
 		return $this->model_data->$id_field ?? null;
 	}
 	}
 
 
-	public final function getModelData() {
+	final public function getModelData() {
 		return clone $this->model_data;
 		return clone $this->model_data;
 	}
 	}
 
 

+ 18 - 0
engine/test.php

@@ -802,4 +802,22 @@ class Test extends Model {
 		return $this->getStatus() === self::STATUS_ASSIGNED;
 		return $this->getStatus() === self::STATUS_ASSIGNED;
 	}
 	}
 
 
+	/**
+	 * @return array
+	 * @throws Exception
+	 */
+	public function getFieldsForVerifyForm(): array {
+		$json = json_decode($this->getProject()->getTemplate()->getJSON());
+
+		if($this->isVoid()) {
+			return $json->beforeTest;
+		}
+
+		return array_merge($json->beforeTest, [(object) ["type" => "hr"]], $json->duringTest);
+	}
+
+	public function getTesterInvoiceStatus(): int {
+		return $this->status_tester_invoice;
+	}
+
 }
 }

+ 24 - 87
views/test_verify_form.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 
 /**
 /**
  * @controller test.php
  * @controller test.php
@@ -11,10 +11,11 @@
  * @var Customer $customer
  * @var Customer $customer
  * @var Template $template
  * @var Template $template
  * @var array $fields
  * @var array $fields
- * @var array $values
  * @var string $tester_message
  * @var string $tester_message
  */
  */
 
 
+$values = $test->getValues(true);
+
 $test_details = [];
 $test_details = [];
 
 
 $test_details["Project"] = sprintf('<a href="/account/projects/%d">%s</a>', $test->project_id, $project->getNameHtml());
 $test_details["Project"] = sprintf('<a href="/account/projects/%d">%s</a>', $test->project_id, $project->getNameHtml());
@@ -39,7 +40,7 @@ if($test->dts_end) {
 	]);
 	]);
 }
 }
 
 
-if(in_array($test->status, [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED])) {
+if(in_array($test->getStatus(), [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED], true)) {
 	$test_details["Verified"] = Util::getDisplayDateTime(strtotime($test->dts_verified . " UTC"));
 	$test_details["Verified"] = Util::getDisplayDateTime(strtotime($test->dts_verified . " UTC"));
 	$test_details["Retest"] = $test->retest ? "Yes" : "No";
 	$test_details["Retest"] = $test->retest ? "Yes" : "No";
 }
 }
@@ -272,98 +273,34 @@ function render_card_list_group($details) {
 							</div>
 							</div>
 						</div>
 						</div>
 						<hr />
 						<hr />
-						<div class="row mb-1">
-							<label class="col-sm-4 col-form-label" for="pass-override">Pass Override</label>
-							<div class="col-sm">
-								<select class="form-control" name="pass_override" id="pass-override">
-									<option value="">None</option>
-									<option value="1">Pass</option>
-									<option value="0">Fail</option>
-								</select>
+						<?php
+						if($template->hasPassFail()) {
+							?>
+							<div class="row mb-1">
+								<label class="col-sm-4 col-form-label" for="pass-override">Pass Override</label>
+								<div class="col-sm">
+									<select class="form-control" name="pass_override" id="pass-override">
+										<option value="">None</option>
+										<option value="1">Pass</option>
+										<option value="0">Fail</option>
+									</select>
+								</div>
 							</div>
 							</div>
-						</div>
+							<?php
+						}
+						?>
 						<div class="row mb-1">
 						<div class="row mb-1">
-							<label class="col-sm-4 col-form-label" for="start-override-day">Start Override</label>
+							<label class="col-sm-4 col-form-label" for="start-override">Start Override</label>
 
 
 							<div class="col-sm">
 							<div class="col-sm">
-								<select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
-									<option value="">Day</option>
-									<?php
-									Form::renderDayOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
-									<option value="">Month</option>
-									<?php
-									Form::renderMonthOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
-									<option value="">Year</option>
-									<?php
-									Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
-									<option value="">HH</option>
-									<?php
-									Form::renderHourOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="start_override_minute" id="start-override-minute">
-									<option value="">MM</option>
-									<?php
-									Form::renderMinuteOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="start_override_second" id="start-override-second">
-									<option value="">SS</option>
-									<?php
-									Form::renderSecondOptions();
-									?>
-								</select>
+								<input class="form-control" type="datetime-local" name="start_override" id="start-override" />
 							</div>
 							</div>
 
 
 						</div>
 						</div>
 						<div class="row mb-1">
 						<div class="row mb-1">
-							<label class="col-sm-4 col-form-label" for="end-override-day">End Override</label>
+							<label class="col-sm-4 col-form-label" for="end-override">End Override</label>
 							<div class="col-sm">
 							<div class="col-sm">
-								<select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
-									<option value="">Day</option>
-									<?php
-									Form::renderDayOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
-									<option value="">Month</option>
-									<?php
-									Form::renderMonthOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
-									<option value="">Year</option>
-									<?php
-									Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
-									<option value="">HH</option>
-									<?php
-									Form::renderHourOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="end_override_minute" id="end-override-minute">
-									<option value="">MM</option>
-									<?php
-									Form::renderMinuteOptions();
-									?>
-								</select>
-								<select class="form-control w-auto d-inline-block" name="end_override_second" id="end-override-second">
-									<option value="">SS</option>
-									<?php
-									Form::renderSecondOptions();
-									?>
-								</select>
+								<input class="form-control" type="datetime-local" name="end_override" id="end-override" />
 							</div>
 							</div>
 						</div>
 						</div>
 						<div class="row mb-1">
 						<div class="row mb-1">
@@ -395,7 +332,7 @@ function render_card_list_group($details) {
 									<div class="input-group-prepend">
 									<div class="input-group-prepend">
 										<span class="input-group-text">£</span>
 										<span class="input-group-text">£</span>
 									</div>
 									</div>
-									<input class="form-control" type="number" step="0.01" min="0" max="999.99" name="travel_cost" id="travel-cost" placeholder="Enter travel costs" value="<?=htmlspecialchars($test->test_travel_cost)?>" required />
+									<input class="form-control" type="number" step="0.01" min="0" max="999.99" name="travel_cost" id="travel-cost" placeholder="Enter travel costs" value="<?=htmlspecialchars($test->test_travel_cost)?>" />
 								</div>
 								</div>
 							</div>
 							</div>
 						</row>
 						</row>