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" ]); foreach($this->locations as $location) { $entries = $location->getUpdateLogEntries([], ["limit" => 1]); $entry = $entries[0] ?? null; 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() : "", ]); } fclose($handle); } }