diff --git a/zefixAPI.php b/zefixAPI.php index 588424f..7d8f6ee 100644 --- a/zefixAPI.php +++ b/zefixAPI.php @@ -107,15 +107,26 @@ function sendAPICommunityRequest(string $username, string $password): string|boo return $response; } + function communityCSV(string $username, string $password): string { $response = sendAPICommunityRequest($username, $password); $communityArray = json_decode($response, true); - $csvOutput = 'id,bfsId,Kanton,Gemeindename,registryOfCommerceId,replacedById,alternateNames\n'; - // Create CSV rows + + $csvOutput = "id,bfsId,Kanton,Gemeindename,registryOfCommerceId,replacedById\n"; foreach ($communityArray as $item) { - $csvOutput .= implode(',', $item) . "\n"; + $row = [ + $item['id'] ?? '', + $item['bfsId'] ?? '', + $item['canton'] ?? '', + $item['name'] ?? '', + $item['registryOfficeId'] ?? '', + $item['replacedById'] ?? '' + ]; + + $csvOutput .= implode(',', $row) . "\n"; } + return $csvOutput; }