Parcourir la source

Add last test date and result to locations export

Alan Lam il y a 6 mois
Parent
commit
01593d33f6
3 fichiers modifiés avec 26 ajouts et 2 suppressions
  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 Location;
+use Test;
 
 class LocationCsvExport {
 
@@ -26,12 +27,28 @@ class LocationCsvExport {
 		$handle = fopen("php://output", "wb");
 
 		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) {
 			$entries = $location->getUpdateLogEntries([], ["limit" => 1]);
 			$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, [
 				$location->id,
@@ -55,6 +72,8 @@ class LocationCsvExport {
 				$location->dts_created,
 				$entry ? $entry->dts : "",
 				$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
 	 */
 	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);
 	}
 
+	public function getDisplayDate(): string {
+		$dt = $this->getDateTimeStart();
+		return $dt ? $dt->setTimezone(TIMEZONE)->format("d/m/Y") : "";
+	}
+
 	public function getDateTimeStart(): ?CarbonImmutable {
 		return Util::getDateTimeFromUtcString($this->dts_start);
 	}