presentation thèmes par ville
This commit is contained in:
parent
5188f12ad4
commit
6f3d19245e
6 changed files with 417 additions and 63 deletions
|
@ -590,6 +590,7 @@ final class AdminController extends AbstractController
|
|||
{
|
||||
$deleteMissing = $request->query->getBoolean('deleteMissing', true);
|
||||
$disableFollowUpCleanup = $request->query->getBoolean('disableFollowUpCleanup', false);
|
||||
$debug = $request->query->getBoolean('debug', false);
|
||||
|
||||
$this->actionLogger->log('labourer', ['insee_code' => $insee_code]);
|
||||
|
||||
|
@ -599,11 +600,51 @@ final class AdminController extends AbstractController
|
|||
$this->actionLogger->log('ERROR_labourer_bad_insee', ['insee_code' => $insee_code]);
|
||||
return $this->redirectToRoute('app_public_index');
|
||||
}
|
||||
$city = null;
|
||||
$city_insee_found = null;
|
||||
$city_debug = null;
|
||||
try {
|
||||
// Récupérer ou créer les stats pour cette zone
|
||||
$stats = $this->entityManager->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
|
||||
$city = $this->motocultrice->get_city_osm_from_zip_code($insee_code);
|
||||
// Si la fonction retourne un tableau ou un objet, on tente d'en extraire le code INSEE
|
||||
if (is_array($city) && isset($city['insee'])) {
|
||||
$city_insee_found = $city['insee'];
|
||||
$city_debug = $city;
|
||||
$city = $city['name'] ?? $city_insee_found;
|
||||
} elseif (is_object($city) && isset($city->insee)) {
|
||||
$city_insee_found = $city->insee;
|
||||
$city_debug = (array)$city;
|
||||
$city = $city->name ?? $city_insee_found;
|
||||
} else {
|
||||
$city_insee_found = $insee_code;
|
||||
}
|
||||
|
||||
// Si le code INSEE trouvé ne correspond pas à celui demandé, afficher un message et stopper
|
||||
if ($city_insee_found !== $insee_code) {
|
||||
$msg = "Attention : le code INSEE trouvé (" . $city_insee_found . ") ne correspond pas à celui demandé (" . $insee_code . "). Aucune modification effectuée.";
|
||||
if ($debug) {
|
||||
return $this->render('admin/labourage_debug.html.twig', [
|
||||
'insee_code' => $insee_code,
|
||||
'city_insee_found' => $city_insee_found,
|
||||
'city_debug' => $city_debug,
|
||||
'city_name' => $city,
|
||||
'message' => $msg,
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
$this->addFlash('error', $msg);
|
||||
return $this->render('admin/labourage_debug.html.twig', [
|
||||
'insee_code' => $insee_code,
|
||||
'city_insee_found' => $city_insee_found,
|
||||
'city_debug' => $city_debug,
|
||||
'city_name' => $city,
|
||||
'message' => $msg,
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!$stats) {
|
||||
$stats = new Stats();
|
||||
$stats->setDateCreated(new \DateTime());
|
||||
|
@ -970,10 +1011,29 @@ final class AdminController extends AbstractController
|
|||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
} catch (\Exception $e) {
|
||||
$this->addFlash('error', 'Erreur lors du labourage : ' . $e->getMessage());
|
||||
die(var_dump($e));
|
||||
if ($debug) {
|
||||
return $this->render('admin/labourage_debug.html.twig', [
|
||||
'insee_code' => $insee_code,
|
||||
'city_insee_found' => $city_insee_found,
|
||||
'city_debug' => $city_debug,
|
||||
'city_name' => $city,
|
||||
'message' => $e->getMessage(),
|
||||
'stats' => $stats ?? null,
|
||||
]);
|
||||
}
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
}
|
||||
// ... (fin normale du traitement, on peut ajouter un affichage debug si besoin)
|
||||
if ($debug) {
|
||||
return $this->render('admin/labourage_debug.html.twig', [
|
||||
'insee_code' => $insee_code,
|
||||
'city_insee_found' => $city_insee_found,
|
||||
'city_debug' => $city_debug,
|
||||
'city_name' => $city,
|
||||
'message' => null,
|
||||
'stats' => $stats,
|
||||
]);
|
||||
}
|
||||
|
||||
// return $this->redirectToRoute('app_public_dashboard');
|
||||
return $this->redirectToRoute('app_admin_stats', ['insee_code' => $insee_code]);
|
||||
}
|
||||
|
||||
|
@ -1673,4 +1733,33 @@ final class AdminController extends AbstractController
|
|||
$response->setContent($csv);
|
||||
return $response;
|
||||
}
|
||||
|
||||
#[Route('/admin/test-ctc/{insee_code}', name: 'admin_test_ctc', requirements: ['insee_code' => '\d+'], defaults: ['insee_code' => null])]
|
||||
public function testCTC(Request $request, ?string $insee_code = null): Response
|
||||
{
|
||||
$json = null;
|
||||
$url = null;
|
||||
$error = null;
|
||||
$stats = null;
|
||||
if ($insee_code) {
|
||||
$stats = $this->entityManager->getRepository(\App\Entity\Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||
if ($stats) {
|
||||
$url = $stats->getCTCurlBase();
|
||||
try {
|
||||
$json = file_get_contents($url . '_last_stats.json');
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
} else {
|
||||
$error = "Aucune stats trouvée pour ce code INSEE.";
|
||||
}
|
||||
}
|
||||
return $this->render('admin/test_ctc.html.twig', [
|
||||
'insee_code' => $insee_code,
|
||||
'url' => $url ? $url . '_last_stats.json' : null,
|
||||
'json' => $json,
|
||||
'error' => $error,
|
||||
'stats' => $stats
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue