location_csv_export.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Exports;
  3. class LocationCsvExport {
  4. /** @var \Location[] */
  5. private $locations = [];
  6. public function __construct(array $locations) {
  7. $this->locations = $locations;
  8. }
  9. public function export(string $filename): void {
  10. header("Content-Type: text/csv; charset=utf-8");
  11. header("Content-Disposition: attachment; filename=$filename");
  12. $handle = fopen("php://output", "wb");
  13. fputcsv($handle, [
  14. "ID", "Internal ID", "City", "Legal Entity", "Brand", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude", "Archived", "Closed",
  15. ]);
  16. foreach($this->locations as $location) {
  17. fputcsv($handle, [
  18. $location->id,
  19. $location->internal_id,
  20. $location->city,
  21. $location->legal_entity_name,
  22. $location->brand,
  23. $location->region,
  24. $location->area_manager,
  25. $location->area_manager_email,
  26. "",
  27. "",
  28. $location->name,
  29. $location->address_1,
  30. $location->postal_code,
  31. $location->email,
  32. $location->latitude,
  33. $location->longitude,
  34. $location->archived,
  35. $location->closed,
  36. ]);
  37. }
  38. fclose($handle);
  39. }
  40. }