mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
up infos habitants sur stats
This commit is contained in:
parent
21d4d5b850
commit
918527e15e
16 changed files with 559 additions and 240 deletions
|
@ -131,10 +131,8 @@ final class AdminController extends AbstractController
|
|||
// Récupérer ou créer les stats pour cette zone
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $zip_code]);
|
||||
|
||||
|
||||
$city = $this->motocultrice->get_city_osm_from_zip_code($zip_code);
|
||||
if (!$stats) {
|
||||
|
||||
$stats = new Stats();
|
||||
$stats->setZone($zip_code)
|
||||
->setPlacesCount(0)
|
||||
|
@ -144,11 +142,27 @@ final class AdminController extends AbstractController
|
|||
->setAvecAccessibilite(0)
|
||||
->setAvecNote(0)
|
||||
->setCompletionPercent(0);
|
||||
$this->entityManager->persist($stats);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
$this->entityManager->persist($stats);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
$stats->setName($city);
|
||||
|
||||
// Récupérer la population via l'API
|
||||
$population = null;
|
||||
try {
|
||||
$apiUrl = 'https://geo.api.gouv.fr/communes/' . $zip_code . '?fields=population';
|
||||
$response = file_get_contents($apiUrl);
|
||||
if ($response !== false) {
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['population'])) {
|
||||
$population = (int)$data['population'];
|
||||
$stats->setPopulation($population);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ne rien faire si l'API échoue
|
||||
}
|
||||
|
||||
// Récupérer toutes les données
|
||||
$places = $this->motocultrice->labourer($zip_code);
|
||||
$processedCount = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue