From 3bc510d116507a6323a42d134a916a889b098733 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 18 May 2021 10:03:36 +0200 Subject: [PATCH] addresses: add pagination in WFS request (WIP) --- .../Command/LoadAddressReferenceCommand.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php index 64ee10e5f..91621a3dd 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php @@ -51,7 +51,9 @@ class LoadAddressReferenceCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output): int { - $addressReferenceArray = $this->fetchWFS(); + + + $addressReferenceArray = $this->fetchWFS(1, 10); $em = $this->entityManager; foreach($addressReferenceArray as $a) { @@ -62,7 +64,11 @@ class LoadAddressReferenceCommand extends Command $em->flush(); + + return 0; + + } public static function isAddressReferenceNew(AddressReference $a): bool @@ -78,22 +84,21 @@ class LoadAddressReferenceCommand extends Command * //TODO move this function in App and make the command generic by accepting a fetcher as an argument * @see \Symfony\Component\Console\Command\Command::execute() */ - private function fetchWFS(): array + private function fetchWFS(int $startIndex, int $count ): array { $dataSource = 'BAL GeoVendee'; $countryCode = 'FR'; - $addressReferenceArray = array(); $wfsUrl = 'https://carto.vendee.fr/arcgis/services/Applications/CHILL/MapServer/WFSServer?SERVICE=WFS&REQUEST=GetFeature'; - $wfsContent = file_get_contents($wfsUrl.'&version=2.0.0&TYPENAME=CHILL:Adresses&MAXFEATURES=3&OUTPUTFORMAT=geojson'); - //TODO loop for pagination + $wfsContent = file_get_contents( + $wfsUrl . '&version=2.0.0&TYPENAME=CHILL:Adresses&startIndex=' . $startIndex . '&count=' . $count . '&OUTPUTFORMAT=geojson' + ); $jsonContent = json_decode($wfsContent, true); - foreach ($jsonContent['features'] as $key => $value) { $a = new AddressReference(); @@ -130,6 +135,4 @@ class LoadAddressReferenceCommand extends Command return $addressReferenceArray; } - - }