diff --git a/src/Controller/PublicController.php b/src/Controller/PublicController.php index 4d9fce5..eab440a 100644 --- a/src/Controller/PublicController.php +++ b/src/Controller/PublicController.php @@ -857,10 +857,144 @@ class PublicController extends AbstractController ]); } - #[Route('/villes', name: 'app_public_cities')] - public function seeAllCities(): Response{ + + #[Route('/cities', name: 'app_public_cities')] + public function cities(): Response + { $stats = $this->entityManager->getRepository(Stats::class)->findAll(); - return $this->render('public/cities.html.twig', ['stats' => $stats]); + // Prepare data for the map + $citiesForMap = []; + foreach ($stats as $stat) { + if ($stat->getZone() !== 'undefined' && preg_match('/^\d+$/', $stat->getZone())) { + $citiesForMap[] = [ + 'name' => $stat->getName(), + 'zone' => $stat->getZone(), + 'lat' => $stat->getLat(), + 'lon' => $stat->getLon(), + 'placesCount' => $stat->getPlacesCount(), + 'completionPercent' => $stat->getCompletionPercent(), + ]; + } + } + + return $this->render('public/cities.html.twig', [ + 'stats' => $stats, + 'citiesForMap' => $citiesForMap, + 'maptiler_token' => $_ENV['MAPTILER_TOKEN'] ?? null, + ]); } + + + #[Route('/rss/demandes', name: 'app_public_rss_demandes')] + public function rssDemandes(): Response + { + $demandes = $this->entityManager->getRepository(Demande::class)->findAllOrderedByCreatedAt(); + + $content = $this->renderView('public/rss/demandes.xml.twig', [ + 'demandes' => $demandes, + 'base_url' => $this->getParameter('router.request_context.host'), + ]); + + $response = new Response($content); + $response->headers->set('Content-Type', 'application/rss+xml'); + + return $response; + } + + #[Route('/rss/city/{insee_code}/demandes', name: 'app_public_rss_city_demandes')] + public function rssCityDemandes(string $insee_code): Response + { + $stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]); + if (!$stats) { + throw $this->createNotFoundException('Ville non trouvée'); + } + + // Récupérer les demandes pour cette ville + $demandes = $this->entityManager->getRepository(Demande::class) + ->createQueryBuilder('d') + ->where('d.insee = :insee') + ->setParameter('insee', $insee_code) + ->orderBy('d.createdAt', 'DESC') + ->getQuery() + ->getResult(); + + $content = $this->renderView('public/rss/city_demandes.xml.twig', [ + 'demandes' => $demandes, + 'city' => $stats, + 'base_url' => $this->getParameter('router.request_context.host'), + ]); + + $response = new Response($content); + $response->headers->set('Content-Type', 'application/rss+xml'); + + return $response; + } + + #[Route('/rss/city/{insee_code}/themes', name: 'app_public_rss_city_themes')] + public function rssCityThemes(string $insee_code): Response + { + $stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]); + if (!$stats) { + throw $this->createNotFoundException('Ville non trouvée'); + } + + // Récupérer les changements thématiques pour cette ville + $followups = $stats->getCityFollowUps(); + $themeChanges = []; + + foreach ($followups as $followup) { + $name = $followup->getName(); + if (str_ends_with($name, '_count')) { + $type = substr($name, 0, -6); + if (!isset($themeChanges[$type])) { + $themeChanges[$type] = []; + } + $themeChanges[$type][] = $followup; + } + } + + // Trier les changements par date pour chaque thème + foreach ($themeChanges as &$changes) { + usort($changes, function ($a, $b) { + return $b->getDate() <=> $a->getDate(); + }); + } + + $content = $this->renderView('public/rss/city_themes.xml.twig', [ + 'themeChanges' => $themeChanges, + 'city' => $stats, + 'base_url' => $this->getParameter('router.request_context.host'), + 'followup_labels' => \App\Service\FollowUpService::getFollowUpThemes(), + ]); + + $response = new Response($content); + $response->headers->set('Content-Type', 'application/rss+xml'); + + return $response; + } + + #[Route('/city/{insee_code}/demandes', name: 'app_public_city_demandes')] + public function cityDemandes(string $insee_code): Response + { + $stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]); + if (!$stats) { + throw $this->createNotFoundException('Ville non trouvée'); + } + + // Récupérer les demandes pour cette ville + $demandes = $this->entityManager->getRepository(Demande::class) + ->createQueryBuilder('d') + ->where('d.insee = :insee') + ->setParameter('insee', $insee_code) + ->orderBy('d.createdAt', 'DESC') + ->getQuery() + ->getResult(); + + return $this->render('public/city_demandes.html.twig', [ + 'demandes' => $demandes, + 'city' => $stats, + ]); + } + } diff --git a/templates/public/nav.html.twig b/templates/public/nav.html.twig index 043b6bd..93ce833 100644 --- a/templates/public/nav.html.twig +++ b/templates/public/nav.html.twig @@ -17,14 +17,14 @@