location_csv_export.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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", "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->region,
  23. $location->area_manager,
  24. $location->area_manager_email,
  25. "",
  26. "",
  27. $location->name,
  28. $location->address_1,
  29. $location->postal_code,
  30. $location->email,
  31. $location->latitude,
  32. $location->longitude,
  33. $location->archived,
  34. $location->closed,
  35. ]);
  36. }
  37. fclose($handle);
  38. }
  39. }