| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Exports;
- use Exception;
- use Location;
- class LocationCsvExport {
- /** @var Location[] */
- private array $locations;
- public function __construct(array $locations) {
- $this->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);
- }
- }
|