Sfoglia il codice sorgente

Add last test date and result to locations export

Alan Lam 6 mesi fa
parent
commit
01593d33f6
3 ha cambiato i file con 26 aggiunte e 2 eliminazioni
  1. 20 1
      engine/exports/location_csv_export.php
  2. 1 1
      engine/location.php
  3. 5 0
      engine/test.php

+ 20 - 1
engine/exports/location_csv_export.php

@@ -4,6 +4,7 @@ namespace Exports;
 
 
 use Exception;
 use Exception;
 use Location;
 use Location;
+use Test;
 
 
 class LocationCsvExport {
 class LocationCsvExport {
 
 
@@ -26,12 +27,28 @@ class LocationCsvExport {
 		$handle = fopen("php://output", "wb");
 		$handle = fopen("php://output", "wb");
 
 
 		fputcsv($handle, [
 		fputcsv($handle, [
-			"ID", "Internal ID", "City", "Legal Entity", "Brand", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude", "Archived", "Closed", "Created", "Updated", "Updated By"
+			"ID", "Internal ID", "City", "Legal Entity", "Brand", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude", "Archived", "Closed", "Created", "Updated", "Updated By", "Last Test Date", "Last Gaming Test Result",
 		]);
 		]);
 
 
 		foreach($this->locations as $location) {
 		foreach($this->locations as $location) {
 			$entries = $location->getUpdateLogEntries([], ["limit" => 1]);
 			$entries = $location->getUpdateLogEntries([], ["limit" => 1]);
 			$entry = $entries[0] ?? null;
 			$entry = $entries[0] ?? null;
+			$completed_tests = $location->getCompletedTests();
+			/** @var Test $completed_test */
+			$completed_test = array_shift($completed_tests);
+
+			$last_test_date = "";
+			$last_test_result = "";
+
+			if($completed_test) {
+				$last_test_date = $completed_test->getDisplayDate();
+				if($completed_test->isVoid()) {
+					$last_test_result = "Void";
+				}
+				else {
+					$last_test_result = $completed_test->isPass() ? "Pass" : "Fail";
+				}
+			}
 
 
 			fputcsv($handle, [
 			fputcsv($handle, [
 				$location->id,
 				$location->id,
@@ -55,6 +72,8 @@ class LocationCsvExport {
 				$location->dts_created,
 				$location->dts_created,
 				$entry ? $entry->dts : "",
 				$entry ? $entry->dts : "",
 				$entry ? $entry->getUser()->getDisplayName() : "",
 				$entry ? $entry->getUser()->getDisplayName() : "",
+				$last_test_date,
+				$last_test_result
 			]);
 			]);
 		}
 		}
 
 

+ 1 - 1
engine/location.php

@@ -159,7 +159,7 @@ class Location extends Model {
 	}
 	}
 
 
 	/**
 	/**
-	 * @return Test[]
+	 * @return Test[] in date descending order
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
 	public function getCompletedTests(array $nvp = []): array {
 	public function getCompletedTests(array $nvp = []): array {

+ 5 - 0
engine/test.php

@@ -980,6 +980,11 @@ class Test extends Model {
 		return Util::getDateTimeFromUtcString($this->dts_due);
 		return Util::getDateTimeFromUtcString($this->dts_due);
 	}
 	}
 
 
+	public function getDisplayDate(): string {
+		$dt = $this->getDateTimeStart();
+		return $dt ? $dt->setTimezone(TIMEZONE)->format("d/m/Y") : "";
+	}
+
 	public function getDateTimeStart(): ?CarbonImmutable {
 	public function getDateTimeStart(): ?CarbonImmutable {
 		return Util::getDateTimeFromUtcString($this->dts_start);
 		return Util::getDateTimeFromUtcString($this->dts_start);
 	}
 	}