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; } }