From 5f8a506c84ff30f3ca541db48eb6329a74ced637 Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 18 May 2021 07:58:48 +0200 Subject: [PATCH] addresses: add postcode in address reference load command --- .../Command/LoadAddressReferenceCommand.php | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php index 2f2f56800..64ee10e5f 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php @@ -51,7 +51,7 @@ class LoadAddressReferenceCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output): int { - $addressReferenceArray = static::fetchVendeeBAL(); + $addressReferenceArray = $this->fetchWFS(); $em = $this->entityManager; foreach($addressReferenceArray as $a) { @@ -78,10 +78,11 @@ 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() */ - public static function fetchVendeeBAL(): array + private function fetchWFS(): array { - $dataSource = 'Vendée Base d\'adresses locale'; + $dataSource = 'BAL GeoVendee'; + $countryCode = 'FR'; $addressReferenceArray = array(); @@ -92,35 +93,43 @@ class LoadAddressReferenceCommand extends Command $jsonContent = json_decode($wfsContent, true); - dump($jsonContent); + foreach ($jsonContent['features'] as $key => $value) { - dump($key); - dump($value); $a = new AddressReference(); $x = $value['geometry']['coordinates'][0]; - $y = $value['geometry']['coordinates'][1]; //TODO get the coordinates in EPSG:4326 + $y = $value['geometry']['coordinates'][1]; - $lon = -1.4 + 0.01 * rand(-5, 5); - $lat = 46.5 + 0.01 * rand(-5, 5); //TODO temp + $lon = -1.4 + 0.01 * rand(-5, 5); //TODO temp: get the coordinates in EPSG:4326 + $lat = 46.5 + 0.01 * rand(-5, 5); //TODO temp: get the coordinates in EPSG:4326 $point = Point::fromLonLat($lon, $lat); + $em = $this->entityManager; + + $country = $em + ->getRepository('ChillMainBundle:Country') + ->findOneBy(array('countryCode' => $countryCode)); + + $postcode = $em + ->getRepository('ChillMainBundle:PostalCode') + ->findOneBy(array('code' => $value['properties']['CODE_POST'], 'country' => $country)); + $a->setRefId($value['properties']['OBJECTID']); $a->setStreet($value['properties']['NOM_AFNOR']); $a->setStreetNumber($value['properties']['NUMERO']); $a->setPoint($point); - //$a->setPostcode('1000'); //TODO find postal code from the postal code in $value['properties']['CODE_POST'] //TODO store postcode if not found??? + $a->setPostcode($postcode); $a->setMunicipalityCode($value['properties']['CODE_INSEE']); $a->setSource($dataSource); $addressReferenceArray[] = $a; } - dump($addressReferenceArray); - return $addressReferenceArray; } + + }