Просмотр исходного кода

Add previous test result to result email

Alan Lam 6 лет назад
Родитель
Сommit
d7c15f9402
1 измененных файлов с 23 добавлено и 2 удалено
  1. 23 2
      engine/test.php

+ 23 - 2
engine/test.php

@@ -364,6 +364,19 @@ class Test extends Model {
 		$builder = new EmailBuilder;
 		$builder->addLeadParagraph($lead_paragraph);
 		$builder->addParagraph("Please see attached PDF and do not hesitate to contact us if you have any questions.");
+
+		// Previous test
+		$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"));
+
+			$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();
 
 		// Send
@@ -373,6 +386,10 @@ class Test extends Model {
 		$mail->addAddress($to_address);
 		$mail->addAttachment($pdf_path, $pdf_name);
 
+		if($previous_pdf_name) {
+			$mail->addAttachment($previous_pdf_path, $previous_pdf_name);
+		}
+
 		$mail->setSubject($subject);
 
 		$mail->send();
@@ -630,12 +647,16 @@ class Test extends Model {
 		return $this->status == Test::STATUS_PENDING_VERIFICATION;
 	}
 
+	public function getPDFPath() {
+		$directory = $this->getDirectory();
+		return sprintf("%s/pdf.pdf", $directory);
+	}
+
 	/**
 	 * @return bool
 	 */
 	public function hasPDF(): bool {
-		$directory = $this->getDirectory();
-		return file_exists($directory . "/pdf.pdf");
+		return file_exists($this->getPDFPath());
 	}
 
 	/**