mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
address reference: command for loading addresse reference (WIP)
This commit is contained in:
parent
b51575fc49
commit
bbb9dc2561
@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
namespace Chill\MainBundle\Command;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Doctrine\Model\Point;
|
||||||
|
use Chill\MainBundle\Entity\AddressReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Champs-Libres
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class LoadAddressReferenceCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EntityManager
|
||||||
|
*/
|
||||||
|
private $entityManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LoadAddressReferenceCommand constructor.
|
||||||
|
*
|
||||||
|
* @param EntityManager $entityManager
|
||||||
|
*/
|
||||||
|
public function __construct(EntityManager $entityManager)
|
||||||
|
{
|
||||||
|
$this->entityManager=$entityManager;
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-PHPdoc)
|
||||||
|
* @see \Symfony\Component\Console\Command\Command::configure()
|
||||||
|
*/
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName('chill:main:address-reference:populate')
|
||||||
|
->setDescription('Load or update countries in db. This command does not delete or update existing address reference,'.
|
||||||
|
'but will add new address reference entities based on their timestamp');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-PHPdoc)
|
||||||
|
* @see \Symfony\Component\Console\Command\Command::execute()
|
||||||
|
*/
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$addressReferenceArray = static::fetchVendeeBAL();
|
||||||
|
$em = $this->entityManager;
|
||||||
|
|
||||||
|
foreach($addressReferenceArray as $a) {
|
||||||
|
if (static::isAddressReferenceNew($a)) {
|
||||||
|
$em->persist($a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isAddressReferenceNew(AddressReference $a): bool
|
||||||
|
{
|
||||||
|
$cond = true;
|
||||||
|
// TODO: write this function
|
||||||
|
|
||||||
|
return $cond;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* //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
|
||||||
|
{
|
||||||
|
|
||||||
|
$dataSource = 'Vendée Base d\'adresses locale';
|
||||||
|
|
||||||
|
$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
|
||||||
|
|
||||||
|
$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
|
||||||
|
|
||||||
|
$lon = -1.4 + 0.01 * rand(-5, 5);
|
||||||
|
$lat = 46.5 + 0.01 * rand(-5, 5); //TODO temp
|
||||||
|
|
||||||
|
$point = Point::fromLonLat($lon, $lat);
|
||||||
|
|
||||||
|
$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->setMunicipalityCode($value['properties']['CODE_INSEE']);
|
||||||
|
$a->setSource($dataSource);
|
||||||
|
|
||||||
|
$addressReferenceArray[] = $a;
|
||||||
|
}
|
||||||
|
|
||||||
|
dump($addressReferenceArray);
|
||||||
|
|
||||||
|
return $addressReferenceArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,7 +7,7 @@ services:
|
|||||||
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
||||||
tags:
|
tags:
|
||||||
- { name: console.command }
|
- { name: console.command }
|
||||||
|
|
||||||
Chill\MainBundle\Command\ChillUserSendRenewPasswordCodeCommand:
|
Chill\MainBundle\Command\ChillUserSendRenewPasswordCodeCommand:
|
||||||
arguments:
|
arguments:
|
||||||
$logger: '@Psr\Log\LoggerInterface'
|
$logger: '@Psr\Log\LoggerInterface'
|
||||||
@ -44,3 +44,9 @@ services:
|
|||||||
$entityManager: '@doctrine.orm.entity_manager'
|
$entityManager: '@doctrine.orm.entity_manager'
|
||||||
tags:
|
tags:
|
||||||
- { name: console.command }
|
- { name: console.command }
|
||||||
|
|
||||||
|
Chill\MainBundle\Command\LoadAddressReferenceCommand:
|
||||||
|
arguments:
|
||||||
|
$entityManager: '@doctrine.orm.entity_manager'
|
||||||
|
tags:
|
||||||
|
- { name: console.command }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user