Procházet zdrojové kódy

Add ability to control whether to attach previous test PDF when verifying tests

Alan Lam před 5 roky
rodič
revize
fd8052fd5e
3 změnil soubory, kde provedl 38 přidání a 12 odebrání
  1. 14 5
      controllers/test_verify_form.php
  2. 11 7
      engine/test.php
  3. 13 0
      views/test_verify_form.php

+ 14 - 5
controllers/test_verify_form.php

@@ -184,25 +184,34 @@ if($submit) {
 				$email_location = http::value("email_location");
 				$email_location = http::value("email_location");
 				$email_location_area_manager = http::value("email_location_area_manager");
 				$email_location_area_manager = http::value("email_location_area_manager");
 
 
+				$include_previous_test = (bool) http::value("include_previous_test");
+
+				$email_addresses = [];
+
 				if($email_customer && $customer->email_after_test && $customer->email) {
 				if($email_customer && $customer->email_after_test && $customer->email) {
-					$test->sendResultEmail($customer->email);
+					$email_addresses[] = $customer->email;
 				}
 				}
 
 
 				if($email_location && $customer->email_locations_after_test && $location->email) {
 				if($email_location && $customer->email_locations_after_test && $location->email) {
-					$test->sendResultEmail($location->email);
+					$email_addresses[] = $location->email;
 				}
 				}
 
 
 				if($email_location_area_manager && $customer->email_locations_after_test && $location->area_manager_email) {
 				if($email_location_area_manager && $customer->email_locations_after_test && $location->area_manager_email) {
-					$test->sendResultEmail($location->area_manager_email);
+					$email_addresses[] = $location->area_manager_email;
 				}
 				}
 
 
 				if(EMAIL_TEST_RESULT) {
 				if(EMAIL_TEST_RESULT) {
-					$test->sendResultEmail(EMAIL_TEST_RESULT);
+					$email_addresses[] = EMAIL_TEST_RESULT;
 				}
 				}
 
 
 				if(EMAIL_TEST_RESULT_COPY) {
 				if(EMAIL_TEST_RESULT_COPY) {
-					$test->sendResultEmail(EMAIL_TEST_RESULT_COPY);
+					$email_addresses[] = EMAIL_TEST_RESULT_COPY;
 				}
 				}
+
+				foreach($email_addresses as $email_address) {
+					$test->sendResultEmail($email_address, $include_previous_test);
+				}
+
 			}
 			}
 		}
 		}
 
 

+ 11 - 7
engine/test.php

@@ -313,10 +313,11 @@ class Test extends Model {
 
 
 	/**
 	/**
 	 * @param string $to_address
 	 * @param string $to_address
+	 * @param bool $include_previous_test
 	 * @return bool
 	 * @return bool
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
-	public function sendResultEmail(string $to_address): bool {
+	public function sendResultEmail(string $to_address, bool $include_previous_test): bool {
 
 
 		$location = $this->getLocation();
 		$location = $this->getLocation();
 		$project = $this->getProject();
 		$project = $this->getProject();
@@ -367,14 +368,17 @@ class Test extends Model {
 
 
 		// Previous test
 		// Previous test
 		$previous_pdf_path = $previous_pdf_name = null;
 		$previous_pdf_path = $previous_pdf_name = null;
-		$previous_test = $this->getPreviousTest();
-		if($previous_test && $previous_test->hasPDF()) {
-			$builder->addParagraph("The previous test result has also been attached for your reference.");
 
 
-			$previous_dt = new DateTime($previous_test->dts_start, new DateTimeZone("UTC"));
+		if($include_previous_test) {
+			$previous_test = $this->getPreviousTest();
+			if($previous_test && $previous_test->hasPDF()) {
+				$builder->addParagraph("The previous test result has also been attached for your reference.");
 
 
-			$previous_pdf_path = $previous_test->getPDFPath();
-			$previous_pdf_name = implode(" - ", array_filter([$location->internal_id, $previous_dt->format("jS M Y")])) . ".pdf";
+				$previous_dt = new DateTime($previous_test->dts_start, new DateTimeZone("UTC"));
+
+				$previous_pdf_path = $previous_test->getPDFPath();
+				$previous_pdf_name = implode(" - ", array_filter([$location->internal_id, $previous_dt->format("jS M Y")])) . ".pdf";
+			}
 		}
 		}
 
 
 		$content = $builder->build();
 		$content = $builder->build();

+ 13 - 0
views/test_verify_form.php

@@ -438,6 +438,19 @@ function render_card_list_group($details) {
 								<?php
 								<?php
 							}
 							}
 							?>
 							?>
+							<div class="row mb-1">
+								<div class="col-sm-4">
+									<label class="form-check-label" for="include-previous-test"><?=htmlspecialchars(__("Previous Test"))?></label>
+								</div>
+								<div class="col-sm">
+									<div class="custom-control custom-checkbox">
+										<input class="custom-control-input" type="checkbox" name="include_previous_test" id="include-previous-test" value="1" checked />
+										<label class="custom-control-label" for="include-previous-test">
+											<?=htmlspecialchars(__("Attach PDF"))?>
+										</label>
+									</div>
+								</div>
+							</div>
 
 
 							<div class="row mb-1">
 							<div class="row mb-1">
 								<label class="col-sm-4 col-form-label" for="tester-message">Message to Tester (if rejecting)</label>
 								<label class="col-sm-4 col-form-label" for="tester-message">Message to Tester (if rejecting)</label>