mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
carte des villes et ajout de ville sur accueil
This commit is contained in:
parent
56f62c45bb
commit
a2936841f9
8 changed files with 601 additions and 30 deletions
|
@ -122,17 +122,20 @@ class PublicController extends AbstractController
|
|||
|
||||
// Préparer les données pour la carte
|
||||
$citiesForMap = [];
|
||||
|
||||
foreach ($stats as $stat) {
|
||||
if ($stat->getZone() && $stat->getZone() !== 'undefined' && preg_match('/^\d+$/', $stat->getZone())) {
|
||||
// Récupérer les coordonnées de la ville via l'API Nominatim
|
||||
if ($stat->getZone() && $stat->getZone() !== 'undefined' && preg_match('/^\d+$/', $stat->getZone()) && $stat->getZone() !== '00000') {
|
||||
$cityName = $stat->getName() ?: $stat->getZone();
|
||||
$coordinates = $this->getCityCoordinates($cityName, $stat->getZone());
|
||||
|
||||
if ($coordinates) {
|
||||
// Utiliser les coordonnées stockées si disponibles
|
||||
if ($stat->getLat() && $stat->getLon()) {
|
||||
$citiesForMap[] = [
|
||||
'name' => $cityName,
|
||||
'zone' => $stat->getZone(),
|
||||
'coordinates' => $coordinates,
|
||||
'coordinates' => [
|
||||
'lat' => (float) $stat->getLat(),
|
||||
'lon' => (float) $stat->getLon()
|
||||
],
|
||||
'placesCount' => $stat->getPlacesCount(),
|
||||
'completionPercent' => $stat->getCompletionPercent(),
|
||||
'population' => $stat->getPopulation(),
|
||||
|
@ -165,17 +168,36 @@ class PublicController extends AbstractController
|
|||
$url = "https://nominatim.openstreetmap.org/search?q={$query}&format=json&limit=1&countrycodes=fr";
|
||||
|
||||
try {
|
||||
$response = file_get_contents($url);
|
||||
// Ajouter un délai pour respecter les limites de l'API Nominatim
|
||||
usleep(100000); // 0.1 seconde entre les appels
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'timeout' => 5, // Timeout de 5 secondes
|
||||
'user_agent' => 'OSM-Commerces/1.0'
|
||||
]
|
||||
]);
|
||||
|
||||
$response = file_get_contents($url, false, $context);
|
||||
|
||||
if ($response === false) {
|
||||
error_log("DEBUG: Échec de récupération des coordonnées pour $cityName ($inseeCode)");
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (!empty($data) && isset($data[0]['lat']) && isset($data[0]['lon'])) {
|
||||
error_log("DEBUG: Coordonnées trouvées pour $cityName ($inseeCode): " . $data[0]['lat'] . ", " . $data[0]['lon']);
|
||||
return [
|
||||
'lat' => (float) $data[0]['lat'],
|
||||
'lon' => (float) $data[0]['lon']
|
||||
];
|
||||
} else {
|
||||
error_log("DEBUG: Aucune coordonnée trouvée pour $cityName ($inseeCode)");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// En cas d'erreur, on retourne null
|
||||
error_log("DEBUG: Exception lors de la récupération des coordonnées pour $cityName ($inseeCode): " . $e->getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -601,4 +623,61 @@ class PublicController extends AbstractController
|
|||
'logs' => $logs
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/add-city', name: 'app_public_add_city')]
|
||||
public function addCity(): Response
|
||||
{
|
||||
return $this->render('public/add_city.html.twig', [
|
||||
'controller_name' => 'PublicController',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/stats/{insee_code}/followup-graph/{theme}', name: 'app_public_followup_graph', requirements: ['insee_code' => '\\d+', 'theme' => '[a-zA-Z0-9_]+'])]
|
||||
public function publicFollowupGraph(string $insee_code, string $theme): Response
|
||||
{
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
if (!$stats) {
|
||||
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
|
||||
$themes = \App\Service\FollowUpService::getFollowUpThemes();
|
||||
if (!isset($themes[$theme])) {
|
||||
$this->addFlash('error', 'Thème non reconnu.');
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
|
||||
// Récupérer toutes les données de followup pour ce thème
|
||||
$followups = $stats->getCityFollowUps();
|
||||
$countData = [];
|
||||
$completionData = [];
|
||||
|
||||
foreach ($followups as $fu) {
|
||||
if ($fu->getName() === $theme . '_count') {
|
||||
$countData[] = [
|
||||
'date' => $fu->getDate()->format('Y-m-d'),
|
||||
'value' => $fu->getMeasure()
|
||||
];
|
||||
}
|
||||
if ($fu->getName() === $theme . '_completion') {
|
||||
$completionData[] = [
|
||||
'date' => $fu->getDate()->format('Y-m-d'),
|
||||
'value' => $fu->getMeasure()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Trier par date
|
||||
usort($countData, fn($a, $b) => $a['date'] <=> $b['date']);
|
||||
usort($completionData, fn($a, $b) => $a['date'] <=> $b['date']);
|
||||
|
||||
return $this->render('public/followup_graph.html.twig', [
|
||||
'stats' => $stats,
|
||||
'theme' => $theme,
|
||||
'theme_label' => $themes[$theme],
|
||||
'count_data' => json_encode($countData),
|
||||
'completion_data' => json_encode($completionData),
|
||||
'icons' => \App\Service\FollowUpService::getFollowUpIcons(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue