mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +02:00
retapage accueil, gestion de Demandes
This commit is contained in:
parent
d777221d0d
commit
f4c5e048ff
26 changed files with 2498 additions and 292 deletions
|
@ -489,7 +489,7 @@ final class AdminController extends AbstractController
|
|||
$progression7Days[$type] = \App\Service\FollowUpService::calculate7DayProgression($stats, $type);
|
||||
}
|
||||
$progression7Days['places'] = \App\Service\FollowUpService::calculate7DayProgression($stats, 'places');
|
||||
|
||||
|
||||
// --- Ajout : mesures CTC CityFollowUp pour le graphique d'évolution ---
|
||||
$ctc_completion_series = [];
|
||||
foreach ($stats->getCityFollowUps() as $fu) {
|
||||
|
@ -1908,4 +1908,164 @@ final class AdminController extends AbstractController
|
|||
'maptiler_token' => $_ENV['MAPTILER_TOKEN'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/demandes', name: 'app_admin_demandes')]
|
||||
public function listDemandes(Request $request): Response
|
||||
{
|
||||
$status = $request->query->get('status');
|
||||
|
||||
$repository = $this->entityManager->getRepository(\App\Entity\Demande::class);
|
||||
|
||||
if ($status) {
|
||||
$demandes = $repository->findByStatus($status);
|
||||
} else {
|
||||
$demandes = $repository->findAllOrderedByCreatedAt();
|
||||
}
|
||||
|
||||
// Get all possible statuses for the filter
|
||||
$allStatuses = ['new', 'email_provided', 'ready', 'email_sent', 'email_failed', 'email_opened', 'edit_form_opened', 'place_modified', 'linked_to_place'];
|
||||
|
||||
// Count demandes for each status
|
||||
$statusCounts = [];
|
||||
foreach ($allStatuses as $statusValue) {
|
||||
$statusCounts[$statusValue] = $repository->findByStatus($statusValue);
|
||||
}
|
||||
|
||||
// Get total count
|
||||
$totalCount = $repository->findAllOrderedByCreatedAt();
|
||||
|
||||
return $this->render('admin/demandes/list.html.twig', [
|
||||
'demandes' => $demandes,
|
||||
'current_status' => $status,
|
||||
'all_statuses' => $allStatuses,
|
||||
'status_counts' => $statusCounts,
|
||||
'total_count' => count($totalCount)
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/demandes/{id}/edit', name: 'app_admin_demande_edit')]
|
||||
public function editDemande(int $id, Request $request): Response
|
||||
{
|
||||
$demande = $this->entityManager->getRepository(\App\Entity\Demande::class)->find($id);
|
||||
|
||||
if (!$demande) {
|
||||
$this->addFlash('error', 'Demande non trouvée');
|
||||
return $this->redirectToRoute('app_admin_demandes');
|
||||
}
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$placeUuid = $request->request->get('placeUuid');
|
||||
|
||||
if ($placeUuid) {
|
||||
// Check if the Place exists
|
||||
$place = $this->entityManager->getRepository(Place::class)->findOneBy(['uuid_for_url' => $placeUuid]);
|
||||
|
||||
if ($place) {
|
||||
$demande->setPlaceUuid($placeUuid);
|
||||
$demande->setPlace($place);
|
||||
$demande->setStatus('linked_to_place');
|
||||
|
||||
// Set OSM object type and OSM ID from the Place
|
||||
$demande->setOsmObjectType($place->getOsmKind());
|
||||
$demande->setOsmId((int)$place->getOsmId());
|
||||
|
||||
$this->entityManager->persist($demande);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Demande mise à jour avec succès');
|
||||
} else {
|
||||
$this->addFlash('error', 'Place non trouvée avec cet UUID');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/demandes/edit.html.twig', [
|
||||
'demande' => $demande
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/contacted-places', name: 'app_admin_contacted_places')]
|
||||
public function listContactedPlaces(): Response
|
||||
{
|
||||
$demandes = $this->entityManager->getRepository(\App\Entity\Demande::class)->findPlacesWithContactAttempt();
|
||||
|
||||
return $this->render('admin/demandes/contacted_places.html.twig', [
|
||||
'demandes' => $demandes
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/admin/demandes/{id}/send-email', name: 'app_admin_demande_send_email')]
|
||||
public function sendEmailToDemande(int $id, \Symfony\Component\Mailer\MailerInterface $mailer): Response
|
||||
{
|
||||
$demande = $this->entityManager->getRepository(\App\Entity\Demande::class)->find($id);
|
||||
|
||||
if (!$demande) {
|
||||
$this->addFlash('error', 'Demande non trouvée');
|
||||
return $this->redirectToRoute('app_admin_demandes');
|
||||
}
|
||||
|
||||
$place = $demande->getPlace();
|
||||
|
||||
if (!$place) {
|
||||
$this->addFlash('error', 'Aucune place associée à cette demande');
|
||||
return $this->redirectToRoute('app_admin_demande_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
// Check if the place has an email
|
||||
if (!$place->getEmail() && !$demande->getEmail()) {
|
||||
$this->addFlash('error', 'Aucun email associé à cette place ou à cette demande');
|
||||
return $this->redirectToRoute('app_admin_demande_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
// Use the email from the place if available, otherwise use the email from the demande
|
||||
$email = $place->getEmail() ?: $demande->getEmail();
|
||||
|
||||
// Generate the email content
|
||||
$emailContent = $this->renderView('admin/email_content.html.twig', [
|
||||
'place' => $place
|
||||
]);
|
||||
|
||||
// Only send the email in production environment
|
||||
if ($this->getParameter('kernel.environment') === 'prod') {
|
||||
$message = (new \Symfony\Component\Mime\Email())
|
||||
->from('contact@osm-commerce.fr')
|
||||
->to($email)
|
||||
->subject('Votre lien de modification OpenStreetMap')
|
||||
->html($emailContent);
|
||||
|
||||
try {
|
||||
$mailer->send($message);
|
||||
} catch (\Throwable $e) {
|
||||
$this->actionLogger->log('ERROR_envoi_email', [
|
||||
'demande_id' => $demande->getId(),
|
||||
'place_id' => $place->getId(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
$this->addFlash('error', 'Erreur lors de l\'envoi de l\'email : ' . $e->getMessage());
|
||||
return $this->redirectToRoute('app_admin_demande_edit', ['id' => $id]);
|
||||
}
|
||||
} else {
|
||||
// In non-production environments, just log the attempt
|
||||
$this->actionLogger->log('email_would_be_sent', [
|
||||
'demande_id' => $demande->getId(),
|
||||
'place_id' => $place->getId(),
|
||||
'email' => $email,
|
||||
'content' => $emailContent
|
||||
]);
|
||||
$this->addFlash('info', 'En environnement de production, un email serait envoyé à ' . $email);
|
||||
}
|
||||
|
||||
// Update the last contact attempt date and set status to email_sent
|
||||
$now = new \DateTime();
|
||||
$demande->setLastContactAttempt($now);
|
||||
$demande->setStatus('email_sent');
|
||||
$place->setLastContactAttemptDate($now);
|
||||
|
||||
$this->entityManager->persist($demande);
|
||||
$this->entityManager->persist($place);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Email envoyé avec succès');
|
||||
return $this->redirectToRoute('app_admin_contacted_places');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue