map on home
This commit is contained in:
parent
a5cd69961f
commit
56f62c45bb
14 changed files with 588 additions and 15 deletions
|
@ -471,6 +471,61 @@ final class AdminController extends AbstractController
|
|||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/stats/{insee_code}/followup-graph/{theme}', name: 'admin_followup_theme_graph', requirements: ['insee_code' => '\\d+'])]
|
||||
public function followupThemeGraph(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_admin');
|
||||
}
|
||||
|
||||
$themes = \App\Service\FollowUpService::getFollowUpThemes();
|
||||
if (!isset($themes[$theme])) {
|
||||
$this->addFlash('error', 'Thème non reconnu.');
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
}
|
||||
|
||||
// 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']);
|
||||
|
||||
$this->actionLogger->log('followup_theme_graph', [
|
||||
'insee_code' => $insee_code,
|
||||
'theme' => $theme,
|
||||
'theme_label' => $themes[$theme] ?? 'Unknown'
|
||||
]);
|
||||
|
||||
return $this->render('admin/followup_theme_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(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/placeType/{osm_kind}/{osm_id}', name: 'app_admin_by_osm_id')]
|
||||
public function placeType(string $osm_kind, string $osm_id): Response
|
||||
{
|
||||
|
@ -484,11 +539,7 @@ final class AdminController extends AbstractController
|
|||
]);
|
||||
return $this->redirectToRoute('app_admin_commerce', ['id' => $place->getId()]);
|
||||
} else {
|
||||
$this->actionLogger->log('ERROR_admin/placeType', ['osm_kind' => $osm_kind, 'osm_id' => $osm_id,
|
||||
'name' => $place->getName(),
|
||||
'code_insee' => $place->getZipCode(),
|
||||
'uuid' => $place->getUuidForUrl()
|
||||
]);
|
||||
$this->actionLogger->log('ERROR_admin/placeType', ['osm_kind' => $osm_kind, 'osm_id' => $osm_id]);
|
||||
$this->addFlash('error', 'Le lieu n\'existe pas.');
|
||||
$this->actionLogger->log('ERROR_admin/placeType', ['osm_kind' => $osm_kind, 'osm_id' => $osm_id]);
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
|
|
|
@ -120,12 +120,67 @@ class PublicController extends AbstractController
|
|||
{
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findAll();
|
||||
|
||||
// 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
|
||||
$cityName = $stat->getName() ?: $stat->getZone();
|
||||
$coordinates = $this->getCityCoordinates($cityName, $stat->getZone());
|
||||
|
||||
if ($coordinates) {
|
||||
$citiesForMap[] = [
|
||||
'name' => $cityName,
|
||||
'zone' => $stat->getZone(),
|
||||
'coordinates' => $coordinates,
|
||||
'placesCount' => $stat->getPlacesCount(),
|
||||
'completionPercent' => $stat->getCompletionPercent(),
|
||||
'population' => $stat->getPopulation(),
|
||||
'url' => $this->generateUrl('app_admin_stats', ['insee_code' => $stat->getZone()])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('public/home.html.twig', [
|
||||
'controller_name' => 'PublicController',
|
||||
'stats' => $stats
|
||||
'stats' => $stats,
|
||||
'citiesForMap' => $citiesForMap,
|
||||
'maptiler_token' => $_ENV['MAPTILER_TOKEN'] ?? null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les coordonnées d'une ville via l'API Nominatim
|
||||
*/
|
||||
private function getCityCoordinates(string $cityName, string $inseeCode): ?array
|
||||
{
|
||||
// Cache simple pour éviter trop d'appels API
|
||||
$cacheKey = 'city_coords_' . $inseeCode;
|
||||
|
||||
// Vérifier le cache (ici on utilise une approche simple)
|
||||
// En production, vous pourriez utiliser le cache Symfony
|
||||
|
||||
$query = urlencode($cityName . ', France');
|
||||
$url = "https://nominatim.openstreetmap.org/search?q={$query}&format=json&limit=1&countrycodes=fr";
|
||||
|
||||
try {
|
||||
$response = file_get_contents($url);
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (!empty($data) && isset($data[0]['lat']) && isset($data[0]['lon'])) {
|
||||
return [
|
||||
'lat' => (float) $data[0]['lat'],
|
||||
'lon' => (float) $data[0]['lon']
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// En cas d'erreur, on retourne null
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#[Route('/edit/{zipcode}/{name}/{uuid}', name: 'app_public_edit')]
|
||||
public function edit_with_uuid($zipcode, $name, $uuid): Response
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue