Alan Lam 2 лет назад
Родитель
Сommit
50f9881fe1

+ 24 - 0
engine/helpers/pdf_helper.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace Helpers;
+
+class PdfHelper {
+
+	public static function getImageConfig(string $path): array {
+		[$image_width, $image_height] = getimagesize($path);
+
+		$width = null;
+		$height = null;
+		if($image_height > $image_width) {
+			$height = "8cm";
+		}
+		else {
+			$width = "100%";
+		}
+
+		$contents = file_get_contents($path);
+
+		return compact("width", "height", "contents");
+	}
+
+}

+ 23 - 0
template_processing/age_verification_greene_king/test_pdf.php

@@ -3,6 +3,7 @@
 /**
  * @var Template $template
  * @var Test $test
+ * @var Mpdf $mpdf
  * @var array $values
  * @var string $location_text
  * @var Customer $customer
@@ -14,8 +15,19 @@
  * @var string $duration_text
  */
 
+use Helpers\PdfHelper;
+use Mpdf\Mpdf;
+
 $pass_image = $test->pass ? "pass.png" : "fail.png";
 
+// Bar Receipt
+$receipt_path_pattern = $test->getDirectory() . "/bar_receipt.*";
+$receipt_config = null;
+foreach(glob($receipt_path_pattern) as $receipt_path) {
+	$receipt_config = PdfHelper::getImageConfig($receipt_path);
+	$mpdf->imageVars["bar_receipt"] = $receipt_config["contents"];
+}
+
 ?>
 
 <h3 class="section">Test Result</h3>
@@ -256,6 +268,17 @@ $pass_image = $test->pass ? "pass.png" : "fail.png";
 		</div>
 	</div>
 
+	<?php
+	if($receipt_config) {
+		?>
+		<div class="subheader">
+			<strong>Receipt</strong>
+		</div>
+		<img src="var:bar_receipt" width="<?=$receipt_config["width"]?>" height="<?=$receipt_config["height"]?>" alt="" />
+		<?php
+	}
+	?>
+
 </div>
 
 <div style="float: right; width: 49.5%">

+ 4 - 12
template_processing/mystery_shop/test_pdf.php

@@ -1,5 +1,6 @@
 <?php
 
+use Helpers\PdfHelper;
 use Mpdf\Mpdf;
 
 /**
@@ -65,18 +66,9 @@ if(!file_exists($location_photo_path)) {
 	$location_photo_path = "public/img/no_image_4_3.png";
 }
 
-[$image_width, $image_height] = getimagesize($location_photo_path);
+$image_config = PdfHelper::getImageConfig($location_photo_path);
 
-$width = "";
-$height = "";
-if($image_height > $image_width) {
-	$height = "8cm";
-}
-else {
-	$width = "100%";
-}
-
-$mpdf->imageVars["location_photo"] = file_get_contents($location_photo_path);
+$mpdf->imageVars["location_photo"] = $image_config["contents"];
 
 ?>
 
@@ -216,7 +208,7 @@ $mpdf->imageVars["location_photo"] = file_get_contents($location_photo_path);
 	<div class="subheader">
 		<strong>Location Photo</strong>
 	</div>
-	<img src="var:location_photo" width="<?=$width?>" height="<?=$height?>" alt="" />
+	<img src="var:location_photo" width="<?=$image_config["width"]?>" height="<?=$image_config["height"]?>" alt="" />
 </div>
 
 <div style="float: right; width: 49.5%">