| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace Exports;
- class LocationCsvExport {
- /** @var \Location[] */
- private $locations = [];
- public function __construct(array $locations) {
- $this->locations = $locations;
- }
- 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", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude"
- ]);
- foreach($this->locations as $location) {
- fputcsv($handle, [
- $location->id,
- $location->internal_id,
- $location->city,
- $location->legal_entity_name,
- $location->region,
- $location->area_manager,
- $location->area_manager_email,
- "",
- "",
- $location->name,
- $location->address_1,
- $location->postal_code,
- $location->email,
- $location->latitude,
- $location->longitude,
- ]);
- }
- fclose($handle);
- }
- }
|