| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace Exports;
- use Customer;
- use Location;
- class LocationKmlExport {
- /** @var Location[] */
- private $locations = [];
- /** @var Customer */
- private $customer;
- public function __construct(array $locations) {
- $this->locations = $locations;
- }
- public function export(string $filename): void {
- header("Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8");
- header("Content-Disposition: attachment; filename=$filename");
- $xml = simplexml_load_string(file_get_contents(ROOT_DIR . "/files/empty.kml"));
- $folder_node = $xml->addChild("Folder");
- $folder_node->addChild("name", $this->customer->name);
- $folder_node->addChild("open", 1);
- $folder_node->addChild("description", $this->customer->name . " Locations");
- foreach($this->locations as $location) {
- $placemark_node = $folder_node->addChild("Placemark");
- $placemark_node->addChild("name", htmlspecialchars($location->name));
- $placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
- $point_node = $placemark_node->addChild("Point");
- $point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
- }
- echo $xml->asXML();
- }
- /**
- * @param Customer $customer
- */
- public function setCustomer(Customer $customer): void {
- $this->customer = $customer;
- }
- }
|