locations = $locations; } /** * @param string $filename * @return void * @throws Exception */ public function export(string $filename): void { header("Content-Type: text/csv; charset=utf-8"); header("Content-Disposition: attachment; filename=$filename"); $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", "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, $location->internal_id, $location->city, $location->legal_entity_name, $location->brand, $location->region, $location->area_manager, $location->area_manager_email, "", "", $location->name, $location->address_1, $location->postal_code, $location->email, $location->latitude, $location->longitude, $location->archived, $location->closed, $location->dts_created, $entry ? $entry->dts : "", $entry ? $entry->getUser()->getDisplayName() : "", $last_test_date, $last_test_result ]); } fclose($handle); } }