src/Controller/Client/AbstractClientController.php line 167

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Client;
  3. use App\Entity\Contact;
  4. use App\Entity\ContactCreationSociete;
  5. use App\Entity\ContactInvestissementImmo;
  6. use App\Entity\ContactInvestissementImmoProperty;
  7. use App\Entity\ContactInvestissementImmoPropertyCharge;
  8. use App\Entity\EmailBlacklist;
  9. use App\Form\ContactCreationSocieteType;
  10. use App\Form\ContactInvestissementImmoType;
  11. use App\Services\MoneticoService;
  12. use App\Services\QueriesV2Manager;
  13. use Psr\Log\LoggerInterface;
  14. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  15. use Twig\Environment;
  16. use App\Form\ContactType;
  17. use App\Services\WebSite;
  18. use App\Form\MiniBookType;
  19. use App\Entity\ApplyRequest;
  20. use App\Form\NewsletterType;
  21. use App\Entity\AccountingFirm;
  22. use App\Form\EbookDownloadType;
  23. use App\Form\CompanyCreationType;
  24. use App\Form\AnnouncementApplyType;
  25. use App\Repository\AliasRepository;
  26. use App\Services\SendContactEmail as CE;
  27. use App\Repository\AccountingFirmRepository;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\Mailer\MailerInterface;
  30. use Symfony\Component\HttpFoundation\Response;
  31. use App\Controller\Client\ClientWidgetController;
  32. use App\Entity\ContactProfession;
  33. use App\Form\ContactProfessionType;
  34. use App\Form\ContactCustomType;
  35. use App\Form\ContactEtreRappeleType;
  36. use App\Repository\DynDataRepository;
  37. use App\Repository\AnnouncementRepository;
  38. use Symfony\Component\HttpFoundation\RequestStack;
  39. use Symfony\Component\HttpFoundation\RedirectResponse;
  40. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  41. use App\Services\AccountingFirmResolver;
  42. use Symfony\Contracts\Cache\CacheInterface;
  43. use Symfony\Component\Form\FormError;
  44. use Symfony\Component\RateLimiter\RateLimiterFactory;
  45. abstract class AbstractClientController extends AbstractController
  46. {
  47.     protected $accountingFirm;
  48.     protected $templateBase;
  49.     protected $mailer;
  50.     protected $request;
  51.     protected $redirect;
  52.     protected $formview;
  53.     protected $formsend;
  54.     protected $formlivreview;
  55.     protected $form_send_livre;
  56.     protected $formcompanyview;
  57.     protected $form_send_company;
  58.     protected $formprofessionview;
  59.     protected $formetrerappeleview;
  60.     protected $form_send_profession;
  61.     protected $form_send_etreRappele;
  62.     protected $formnewsletterview;
  63.     protected $form_send_newsletter;
  64.     protected $formminibookview;
  65.     protected $form_send_minibook;
  66.     protected $formrecrutementview;
  67.     protected $form_send_recrutement;
  68.     protected $formprevicreationview;
  69.     protected $form_send_previ_creation;
  70.     protected $formpreviimmoview;
  71.     protected $form_send_previ_immo;
  72.     protected $formcustomview;
  73.     protected $form_send_custom;
  74.     protected $CE;
  75.     protected $twig;
  76.     protected $site;
  77.     protected $dynData;
  78.     protected $dynDataArray;
  79.     protected $dynDataText;
  80.     protected $announcementMain;
  81.     protected $announcementSpontanee;
  82.     protected $serviceQMV2;
  83.     protected  $moneticoService;
  84.     protected $theHost;
  85.     protected $logger;
  86.     protected $cache;
  87.     protected $contactFormByIpLimiter;
  88.     public function __construct(RequestStack $requestAccountingFirmRepository $accountingFirmRepositoryAliasRepository $aliasrepositoryMailerInterface $mailerCE $CEEnvironment $twigWebSite $siteAnnouncementRepository $announcementRepositoryDynDataRepository $dynDataRepositoryQueriesV2Manager $serviceQMV2MoneticoService $moneticoServiceLoggerInterface $loggerAccountingFirmResolver $accountingFirmResolverCacheInterface $cacheRateLimiterFactory $contactFormByIpLimiter)
  89.     {
  90.         $this->moneticoService $moneticoService;
  91.         $this->logger $logger;
  92.         $this->cache $cache;
  93.         $this->contactFormByIpLimiter $contactFormByIpLimiter;
  94.         $theHost $request->getCurrentRequest()->getHost();
  95.         $theHost str_replace('www.'''$theHost);
  96.         if (preg_match('/preview/'$request->getCurrentRequest()->get('_route'))) {
  97.             $theHost $request->getCurrentRequest()->attributes->get('host');
  98.         }
  99.         // $theHost = 'cabinet-za.de';
  100.         // ✅ UTILISATION DU RESOLVER CENTRALISÉ - évite la duplication avec le Voter
  101.         $this->accountingFirm $accountingFirmResolver->resolve();
  102.         // Gestion de la redirection si alias ou host non trouvé
  103.         if (is_null($this->accountingFirm)) {
  104.             $alias $aliasrepository->findOneBy([
  105.                 'name' => $theHost
  106.             ]);
  107.             if (!is_null($alias)) {
  108.                 $acID $alias->getParameter()->getAccountingFirm()->getId();
  109.                 $this->accountingFirm $accountingFirmRepository->findOneBy([
  110.                     'id' => $acID
  111.                 ]);
  112.                 $this->redirect $this->accountingFirm->getHost();
  113.             } else {
  114.                 $this->redirect 404;
  115.             }
  116.         }
  117.         $theHost $this->accountingFirm->getHost();
  118.         $this->theHost $theHost;
  119.         // ✅ OPTIMISATION : Cache des DynData avec relations hydratées
  120.         // On récupère directement depuis le repository (pas de cache d'entités Doctrine)
  121.         // car les relations lazy-loaded ne survivent pas à la sérialisation du cache
  122.         $this->dynData $dynDataRepository->findAll();
  123.         // Filtrer par type - on garde les entités complètes avec relations hydratées
  124.         $this->dynDataArray array_values(array_filter($this->dynData, fn($d) => $d->getType() === 'ARRAY'));
  125.         $this->dynDataText array_values(array_filter($this->dynData, fn($d) => $d->getType() === 'TEXT'));
  126.         if (!empty($this->accountingFirm)) {
  127.             $this->announcementMain $announcementRepository->findMyAnnouncementMain($this->accountingFirm);
  128.             $this->announcementSpontanee $announcementRepository->findMyAnnouncementsSpontanee($this->accountingFirm);
  129.         }
  130.         $this->templateBase '/' $theHost '/templates/';
  131.         $this->request $request;
  132.         $this->mailer $mailer;
  133.         $this->formsend false;
  134.         $this->form_send_livre false;
  135.         $this->form_send_company false;
  136.         $this->form_send_newsletter false;
  137.         $this->form_send_minibook false;
  138.         $this->form_send_recrutement false;
  139.         $this->form_send_custom false;
  140.         $this->form_send_previ_creation false;
  141.         $this->form_send_previ_immo false;
  142.         $this->CE $CE;
  143.         $this->twig $twig;
  144.         $this->site $site;
  145.         $this->serviceQMV2 $serviceQMV2;
  146.     }
  147.     protected function render(string $view, array $parameters = [], Response $response null, array $return = []): Response
  148.     {
  149.         // ✅ OPTIMISATION : Cache du fichier entrypoints.json (évite I/O disque + parsing JSON)
  150.         // Le cache sera automatiquement invalidé au prochain déploiement
  151.         $build $this->cache->get('build_entrypoints', function() {
  152.             $filePath $this->getParameter('kernel.project_dir') . '/public/build/entrypoints.json';
  153.             return json_decode(file_get_contents($filePath), true);
  154.         });
  155.         $this->twig->addGlobal('build'$build);
  156.         $this->twig->addGlobal('serverActuUrl'$this->site->getServerActuUrl());
  157.         // set redirection
  158.         if (!is_null($this->redirect)) {
  159.             if ($this->redirect == 404) {
  160.                 return new Response(""404);
  161.                 die();
  162.             } else {
  163.                 $this->redirect "https://" $this->redirect;
  164.             }
  165.         }
  166.         // Access from actualite-du-mois.php
  167.         if ($this->request && $this->request->getCurrentRequest() && $this->request->getCurrentRequest()->getBaseUrl() == "/actualite-du-mois.php") {
  168.             if ($this->redirectRouteV2($this->request->getCurrentRequest())) {
  169.                 $redirect $this->redirectRouteV2($this->request->getCurrentRequest());
  170.                 $redirect str_replace("actualite-du-mois.php"""$redirect);
  171.                 $redirect str_replace("//""/"$redirect);
  172.             } else {
  173.                 $redirect "/actualite-du-mois";
  174.             }
  175.             if (empty($this->redirect)) {
  176.                 $this->redirect "https://" $this->request->getCurrentRequest()->getHttpHost() . $redirect;
  177.             } else {
  178.                 $this->redirect $this->redirect $redirect;
  179.             }
  180.         }
  181.         // do redirection
  182.         if (!is_null($this->redirect)) {
  183.             return new RedirectResponse($this->redirect);
  184.             die();
  185.         }
  186.         // SETUP
  187.         $entityManager $this->getDoctrine()->getManager();
  188.         // Contact
  189.         $form $this->createForm(ContactType::class, null, ['cabinet' => $this->accountingFirm]);
  190.         $request $this->get('request_stack')->getCurrentRequest();
  191.         $form->get('form_timestamp')->setData(time());
  192.         $form->get('route')->setData($request->attributes->get('_route'));
  193.         if ($request->attributes->get('_route') == 'previewprescripteur_client' || $request->attributes->get('_route') == 'prescripteur_client') {
  194.             $form->get('id_prescriber')->setData($request->attributes->get('id'));
  195.         }
  196.         $form->handleRequest($request);
  197.         if ($form->isSubmitted() && $form->isValid()) {
  198.             // Rate limiting par IP : max 2 soumissions par période de 24h
  199.             $limiter $this->contactFormByIpLimiter->create($request->getClientIp());
  200.             if (!$limiter->consume(1)->isAccepted()) {
  201.                 $form->addError(new FormError('Trop de tentatives. Vous avez déjà soumis ce formulaire plusieurs fois aujourd\'hui. Merci de réessayer demain ou de nous contacter directement par téléphone.'));
  202.             } else {
  203.             $name $form->get('name')->getData();
  204.             $email $form->get('email')->getData();
  205.             $message $form->get('message')->getData();
  206.             $fiveMinutesAgo = new \DateTime('-5 minutes');
  207.             $existingContact $this->getDoctrine()->getRepository(Contact::class)->findRecentContactByName($name$fiveMinutesAgo);
  208.             $submittedAt = (int) $form->get('form_timestamp')->getData();
  209.             $now time();
  210.             $elapsedSeconds $now $submittedAt;
  211.             // Anti-spam : formulaire soumis trop vite
  212.             if ($elapsedSeconds 10) {
  213.                 // Ajout à la blacklist
  214.                 $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  215.                 $entityManager $this->getDoctrine()->getManager();
  216.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  217.                 if (!$blacklistedEmail) {
  218.                     $blacklistedEmail = new EmailBlacklist();
  219.                     $blacklistedEmail->setEmail($email);
  220.                     $blacklistedEmail->setName($name);
  221.                     $blacklistedEmail->setBlockCount(1);
  222.                 } else {
  223.                     $blacklistedEmail->incrementBlockCount();
  224.                 }
  225.                 $entityManager->persist($blacklistedEmail);
  226.                 $entityManager->flush();
  227.             }
  228.             // Détection message spam type "ClbNCSjWDTZMonBownuySkg"
  229.             if ($this->isGibberishMessage($message) || $this->isSpamContent($message)) {
  230.                 $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  231.                 $entityManager $this->getDoctrine()->getManager();
  232.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  233.                 if (!$blacklistedEmail) {
  234.                     $blacklistedEmail = new EmailBlacklist();
  235.                     $blacklistedEmail->setEmail($email);
  236.                     $blacklistedEmail->setName($name);
  237.                     $blacklistedEmail->setBlockCount(1);
  238.                 } else {
  239.                     $blacklistedEmail->incrementBlockCount();
  240.                 }
  241.                 $entityManager->persist($blacklistedEmail);
  242.                 $entityManager->flush();
  243.             }
  244.             // Vérifier si l'email est dans la blacklist
  245.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  246.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) && !$existingContact && !$this->isSpamContent($message)) {
  247.                 $this->CE->sendContactEmail($form);
  248.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  249.                 // Incrémenter le compteur de tentatives
  250.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  251.                 if ($blacklistedEmail) {
  252.                     $blacklistedEmail->incrementBlockCount();
  253.                     $entityManager $this->getDoctrine()->getManager();
  254.                     $entityManager->persist($blacklistedEmail);
  255.                     $entityManager->flush();
  256.                 }
  257.             }
  258.             $this->formsend true;
  259.             } // end else rate limiter
  260.         }
  261.         $this->formview $form->createView();
  262.         // Contact Custom
  263.         $form_custom $this->createForm(ContactCustomType::class, null, ['cabinet' => $this->accountingFirm]);
  264.         $form_custom->handleRequest($request);
  265.         $this->formcustomview $form_custom->createView();
  266.         if ($form_custom->isSubmitted() && $form_custom->isValid()) {
  267.             $name $form_custom->get('name')->getData();
  268.             $email $form_custom->get('email')->getData();
  269.             $message $form_custom->get('message')->getData();
  270.             // Vérifier si l'email est dans la blacklist
  271.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  272.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) && stripos($message"free") === false) {
  273.                 $this->CE->sendContactCustomEmail($form_custom);
  274.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  275.                 // Incrémenter le compteur de tentatives
  276.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  277.                 if ($blacklistedEmail) {
  278.                     $blacklistedEmail->incrementBlockCount();
  279.                     $entityManager $this->getDoctrine()->getManager();
  280.                     $entityManager->persist($blacklistedEmail);
  281.                     $entityManager->flush();
  282.                 }
  283.             }
  284.             $this->form_send_custom true;
  285.         }
  286.         // EbookDownload
  287.         $form_livre $this->createForm(EbookDownloadType::class);
  288.         $form_livre->handleRequest($request);
  289.         $this->formlivreview $form_livre->createView();
  290.         if ($form_livre->isSubmitted() && $form_livre->isValid()) {
  291.             $this->CE->sendEbookEmail($form_livre);
  292.             $this->form_send_livre true;
  293.         }
  294.         // company
  295.         $form_company $this->createForm(CompanyCreationType::class, null, ['cabinet' => $this->accountingFirm]);
  296.         $form_company->handleRequest($request);
  297.         $this->formcompanyview $form_company->createView();
  298.         if ($form_company->isSubmitted() && $form_company->isValid()) {
  299.             $name $form_company->get('name')->getData();
  300.             $email $form_company->get('email')->getData();
  301.             // Vérifier si l'email est dans la blacklist
  302.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  303.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name))) {
  304.                 $this->CE->sendCompanyEmail($form_company);
  305.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  306.                 // Incrémenter le compteur de tentatives
  307.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  308.                 if ($blacklistedEmail) {
  309.                     $blacklistedEmail->incrementBlockCount();
  310.                     $entityManager $this->getDoctrine()->getManager();
  311.                     $entityManager->persist($blacklistedEmail);
  312.                     $entityManager->flush();
  313.                 }
  314.             }
  315.             $this->form_send_company true;
  316.         }
  317.         // company
  318.         $form_profession $this->createForm(ContactProfessionType::class, null, ['cabinet' => $this->accountingFirm]);
  319.         $form_profession->handleRequest($request);
  320.         $this->formprofessionview $form_profession->createView();
  321.         if ($form_profession->isSubmitted() && $form_profession->isValid()) {
  322.             $name $form_profession->get('name')->getData();
  323.             $email $form_profession->get('email')->getData();
  324.             $message $form_profession->get('message')->getData();
  325.             // Vérifier si l'email est dans la blacklist
  326.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  327.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) && stripos($message"free") === false) {
  328.                 $this->CE->sendContactProfessionEmail($form_profession);
  329.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  330.                 // Incrémenter le compteur de tentatives
  331.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  332.                 if ($blacklistedEmail) {
  333.                     $blacklistedEmail->incrementBlockCount();
  334.                     $entityManager $this->getDoctrine()->getManager();
  335.                     $entityManager->persist($blacklistedEmail);
  336.                     $entityManager->flush();
  337.                 }
  338.             }
  339.             $this->form_send_profession true;
  340.         }
  341.         // etre rappele
  342.         $form_etre_rappele $this->createForm(ContactEtreRappeleType::class, null, ['cabinet' => $this->accountingFirm]);
  343.         $form_etre_rappele->handleRequest($request);
  344.         $this->formetrerappeleview $form_etre_rappele->createView();
  345.         if ($form_etre_rappele->isSubmitted() && $form_etre_rappele->isValid())
  346.         {
  347.             $name $form_etre_rappele->get('name')->getData();
  348.             $email $form_etre_rappele->get('email')->getData();
  349.             // Vérifier si l'email est dans la blacklist
  350.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  351.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name))) {
  352.                 $this->CE->sendContactEtreRappeleEmail($form_etre_rappele);
  353.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  354.                 // Incrémenter le compteur de tentatives
  355.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  356.                 if ($blacklistedEmail) {
  357.                     $blacklistedEmail->incrementBlockCount();
  358.                     $entityManager $this->getDoctrine()->getManager();
  359.                     $entityManager->persist($blacklistedEmail);
  360.                     $entityManager->flush();
  361.                 }
  362.             }
  363.             $this->form_send_etreRappele true;
  364.         }
  365. // previ creation
  366.         $logFile $this->getParameter('kernel.project_dir') . '/var/log/monprevi.log';
  367.         if (!is_dir(dirname($logFile))) {
  368.             @mkdir(dirname($logFile), 0775true);
  369.         }
  370.         $log = function (string $message) use ($logFile) {
  371.             @file_put_contents(
  372.                 $logFile,
  373.                 sprintf("[%s] %s\n", (new \DateTimeImmutable())->format('Y-m-d H:i:s'), $message),
  374.                 FILE_APPEND
  375.             );
  376.         };
  377.         if ($this->accountingFirm->getId() === 301 || $this->accountingFirm->getId() === 320) {
  378.             $log("Init Previ Creation: host={$this->theHost}, cabinet_id=" . ($this->accountingFirm $this->accountingFirm->getId() : 'null'));
  379.         }
  380.         try {
  381.             $contactCreationSociete = new ContactCreationSociete();
  382.             $contactCreationSociete->setCabinet($this->accountingFirm);
  383.             $contactCreationSociete->setCreatedAt(new \DateTimeImmutable('now'));
  384.             $form_previcreation $this->createForm(ContactCreationSocieteType::class, $contactCreationSociete, ['cabinet' => $this->accountingFirm]);
  385.             $this->formprevicreationview $form_previcreation->createView();
  386.             if ($this->accountingFirm->getId() === 301) {
  387.                 $log("Previ Creation : Formulaire affiché");
  388.             }
  389.             if ($request->isMethod('POST') && $request->request->has($form_previcreation->getName())) {
  390.                 $log("Previ Creation POST detecté pour form=" $form_previcreation->getName());
  391.                 $form_previcreation->handleRequest($request);
  392.                 if ($form_previcreation->isSubmitted() && $form_previcreation->isValid()) {
  393.                     $log("Previ Creation formulaire soumis et valide");
  394.                     $startActivityAt $form_previcreation->get('startActivityAt')->getData();
  395.                     $fiscalYearEndAt $form_previcreation->get('fiscalYearEndAt')->getData();
  396.                     $log(sprintf(
  397.                         "Previ Creation dates reçues: startActivityAt=%s, fiscalYearEndAt=%s",
  398.                         $startActivityAt $startActivityAt->format('d/m/Y') : 'null',
  399.                         $fiscalYearEndAt $fiscalYearEndAt->format('d/m/Y') : 'null'
  400.                     ));
  401.                     $contactCreationSociete->setStartActivityAt($startActivityAt);
  402.                     $contactCreationSociete->setFiscalYearEndAt($fiscalYearEndAt);
  403.                     $name $form_previcreation->get('name')->getData();
  404.                     $email $form_previcreation->get('email')->getData();
  405.                     $log("Previ Creation nom reçu: {$name} {$email}");
  406.                     // Vérifier si l'email est dans la blacklist
  407.                     $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  408.                     if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name))) {
  409.                         $log("Blacklist check passed for email: {$email}");
  410.                         try {
  411.                             $entityManager->persist($contactCreationSociete);
  412.                             $entityManager->flush();
  413.                         } catch (\Throwable $e) {
  414.                             $this->logger->error("❌ Erreur lors du persist/flush Previ Creation", [
  415.                                 'message' => $e->getMessage(),
  416.                                 'trace' => $e->getTraceAsString(),
  417.                                 'form_data_class' => get_class($form_previcreation->getData()),
  418.                                 'form_valid' => $form_previcreation->isValid(),
  419.                                 'form_errors' => (string) $form_previcreation->getErrors(truefalse),
  420.                             ]);
  421.                             throw $e;
  422.                         }
  423.                         $log("Previ Creation entité persistée id=" $contactCreationSociete->getId());
  424.                         $contactCreationSociete->setReference('PREVI_' $contactCreationSociete->getId());
  425.                         $entityManager->persist($contactCreationSociete);
  426.                         $entityManager->flush();
  427.                         $log("Previ Creation référence définie=" $contactCreationSociete->getReference());
  428.                         if ($contactCreationSociete->getPaymentMethod() === 'cb') {
  429.                             $parameters $this->accountingFirm->getParameters();
  430.                             $price = ($contactCreationSociete->getCategory() == "Prévisionnel complet") ? "359,00" "259,00";
  431.                             $urlRetour $this->generateUrl('monetico_return_client', ['id' => $contactCreationSociete->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  432.                             $urlNotif $this->generateUrl('monetico_notification', [], UrlGeneratorInterface::ABSOLUTE_URL);
  433.                             if (str_contains($this->request->getCurrentRequest()->get('_route'), 'preview')) {
  434.                                 $urlRetour $this->generateUrl('previewmonetico_return_client', ['host' => $this->theHost'id' => $contactCreationSociete->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  435.                                 $urlNotif $this->generateUrl('previewmonetico_notification', ['host' => $this->theHost], UrlGeneratorInterface::ABSOLUTE_URL);
  436.                             }
  437.                             $log("Previ Creation paiement CB: price={$price}, reference=" $contactCreationSociete->getReference() . ", url_retour={$urlRetour}, url_notif={$urlNotif}");
  438.                             $params = [
  439.                                 'tpe'         => $parameters->getMoneticoTpe(),
  440.                                 'societe'     => $parameters->getMoneticoSociete(),
  441.                                 'hmac_key'    => $parameters->getMoneticoCle(),
  442.                                 'url_retour'  => $urlRetour,
  443.                                 'url_notif'   => $urlNotif,
  444.                                 'montant'     => $price,
  445.                                 'reference'   => $contactCreationSociete->getReference(),
  446.                                 'email'       => $contactCreationSociete->getEmail(),
  447.                                 'name'        => $contactCreationSociete->getName(),
  448.                                 'firstname'   => $contactCreationSociete->getFirstname(),
  449.                                 'address'     => $contactCreationSociete->getSocietyAddress(),
  450.                                 'zipCode'     => $contactCreationSociete->getSocietyZipCode(),
  451.                                 'city'        => $contactCreationSociete->getSocietyCity(),
  452.                             ];
  453.                             $log("Previ Creation génération du formulaire de paiement Monetico");
  454.                             return new Response($this->moneticoService->generatePaymentForm($params));
  455.                         }
  456.                         $this->CE->sendPreviCreation($contactCreationSociete);
  457.                         $this->form_send_previ_creation true;
  458.                         $log("Previ Creation email envoyé, référence=" $contactCreationSociete->getReference());
  459.                         $urlRetour $this->generateUrl('monetico_return_client', ['id' => $contactCreationSociete->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  460.                         if (str_contains($this->request->getCurrentRequest()->get('_route'), 'preview')) {
  461.                             $urlRetour $this->generateUrl('previewmonetico_return_client', ['host' => $this->theHost'id' => $contactCreationSociete->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  462.                         }
  463.                         $urlRetour .= "?reference=" $contactCreationSociete->getReference();
  464.                         $urlRetour .= "&code-retour=paiement";
  465.                         $log("Previ Creation redirection vers {$urlRetour}");
  466.                         return new RedirectResponse($urlRetour);
  467.                     } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  468.                         $blacklistedEmail $blacklistRepo->findByEmail($email);
  469.                         if ($blacklistedEmail) {
  470.                             $blacklistedEmail->incrementBlockCount();
  471.                             $entityManager->persist($blacklistedEmail);
  472.                             $entityManager->flush();
  473.                         }
  474.                         $log("Previ Creation email blacklisté: {$email}");
  475.                     }
  476.                 } else {
  477.                     $log("Previ Creation formulaire non valide ou non soumis");
  478.                     $this->logger->error("Previ Creation formulaire non valide ou non soumis", [
  479.                         'form_data_class' => get_class($form_previcreation->getData()),
  480.                         'form_valid' => $form_previcreation->isValid(),
  481.                         'form_errors' => (string) $form_previcreation->getErrors(truefalse),
  482.                     ]);
  483.                 }
  484.             }
  485.         } catch (\Throwable $e) {
  486.             // ⚙️ On tente de récupérer le contenu du formulaire, même s'il est invalide
  487.             $formData = [];
  488.             try {
  489.                 if (isset($form_previcreation) && $form_previcreation->isSubmitted()) {
  490.                     // on extrait les données brutes + erreurs
  491.                     $formData = [
  492.                         'data' => $form_previcreation->getData(),
  493.                         'submitted_data' => $request->request->all($form_previcreation->getName()),
  494.                         'errors' => (string) $form_previcreation->getErrors(truefalse),
  495.                     ];
  496.                 }
  497.             } catch (\Throwable $innerE) {
  498.                 // on logue aussi si jamais même la récupération échoue (par sécurité)
  499.                 $this->logger->warning('Impossible d’extraire les données du formulaire dans le catch', [
  500.                     'inner_message' => $innerE->getMessage(),
  501.                 ]);
  502.             }
  503.             // 🧾 Log complet de l’exception
  504.             $this->logger->error('❌ Exception non interceptée dans Previ Creation', [
  505.                 'message' => $e->getMessage(),
  506.                 'trace' => $e->getTraceAsString(),
  507.                 'file' => $e->getFile(),
  508.                 'line' => $e->getLine(),
  509.                 'request_uri' => $request->getRequestUri(),
  510.                 'form_data' => $formData,
  511.             ]);
  512.             // 🔁 selon ton besoin :
  513.              throw $e// pour laisser Symfony gérer l'erreur (page 500)
  514.         }
  515.         // previ immo
  516.         if ($this->accountingFirm->getId() === 301) {
  517.             $log("Init Previ Immo: host={$this->theHost}, cabinet_id=" . ($this->accountingFirm $this->accountingFirm->getId() : 'null'));
  518.         }
  519.         try {
  520.             $contactInvestissementImmo = new ContactInvestissementImmo();
  521.             $contactInvestissementImmo->setAccountingFirm($this->accountingFirm);
  522.             $contactInvestissementImmo->setNumberProperties(1);
  523.             $contactInvestissementImmo->setCreatedAt(new \DateTimeImmutable('now'));
  524.             $form_previimmo $this->createForm(ContactInvestissementImmoType::class, $contactInvestissementImmo, ['cabinet' => $this->accountingFirm]);
  525.             $this->formpreviimmoview $form_previimmo->createView();
  526.             if ($this->accountingFirm->getId() === 301) {
  527.                 $log("Previ Immo : Formulaire affiché");
  528.             }
  529.             if ($request->isMethod('POST') && $request->request->has($form_previimmo->getName())) {
  530.                 $log("Previ Immo POST détecté pour form=" $form_previimmo->getName());
  531.                 $form_previimmo->handleRequest($request);
  532.                 if ($form_previimmo->isSubmitted() && $form_previimmo->isValid()) {
  533.                     $log("Previ Immo formulaire soumis et valide");
  534.                     $name $form_previimmo->get('name')->getData();
  535.                     $email $form_previimmo->get('email')->getData();
  536.                     $log("Previ Immo nom reçu: {$name} {$email}");
  537.                     $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  538.                     if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name))) {
  539.                         $propertiesImmoData $form_previimmo->get('propertiesImmo')->getData();
  540.                         $propertiesChargesData $form_previimmo->get('propertiesCharges')->getData();
  541.                         $propertiesRentData $form_previimmo->get('propertiesRent')->getData();
  542.                         $log("Previ Immo propriétés reçues: nb=" . (is_iterable($propertiesImmoData) ? count($propertiesImmoData) : 0));
  543.                         foreach ($propertiesImmoData as $index => $propertyData) {
  544.                             $log("Previ Immo propriété index={$index} création");
  545.                             $property = new ContactInvestissementImmoProperty();
  546.                             $property->setSurface($propertyData['surface'] ?? '');
  547.                             $property->setBiens($propertyData['biens'] ?? '');
  548.                             $property->setRents($propertiesRentData[$index]['rent'] ?? '');
  549.                             $property->setContactInvestissementImmo($contactInvestissementImmo);
  550.                             if (isset($propertiesChargesData[$index]['charges']) && is_iterable($propertiesChargesData[$index]['charges'])) {
  551.                                 $log("Previ Immo propriété index={$index} charges nb=" count($propertiesChargesData[$index]['charges']));
  552.                                 foreach ($propertiesChargesData[$index]['charges'] as $chargeData) {
  553.                                     $charge = new ContactInvestissementImmoPropertyCharge();
  554.                                     $charge->setName($chargeData['name'] ?? '');
  555.                                     $charge->setAmount($chargeData['amount'] ?? '');
  556.                                     $charge->setFrequency($chargeData['periodicite'] ?? '');
  557.                                     $charge->setContactInvestissementImmoProperty($property);
  558.                                     $entityManager->persist($charge);
  559.                                     $property->addCharge($charge);
  560.                                 }
  561.                             }
  562.                             $entityManager->persist($property);
  563.                             $contactInvestissementImmo->getProperties()->add($property);
  564.                         }
  565.                         try {
  566.                             $entityManager->persist($contactInvestissementImmo);
  567.                             $entityManager->flush();
  568.                         } catch (\Throwable $e) {
  569.                             $this->logger->error("❌ Erreur lors du persist/flush Previ Immo", [
  570.                                 'message' => $e->getMessage(),
  571.                                 'trace' => $e->getTraceAsString(),
  572.                                 'form_data_class' => get_class($form_previimmo->getData()),
  573.                                 'form_valid' => $form_previimmo->isValid(),
  574.                                 'form_errors' => (string) $form_previimmo->getErrors(truefalse),
  575.                             ]);
  576.                             throw $e;
  577.                         }
  578.                         $log("Previ Immo entité persistée id=" $contactInvestissementImmo->getId());
  579.                         $contactInvestissementImmo->setReference('PREVI_IMMO_' $contactInvestissementImmo->getId());
  580.                         $entityManager->persist($contactInvestissementImmo);
  581.                         $entityManager->flush();
  582.                         $log("Previ Immo référence définie=" $contactInvestissementImmo->getReference());
  583.                         if ($contactInvestissementImmo->getPaymentMethod() === 'cb') {
  584.                             $parameters $this->accountingFirm->getParameters();
  585.                             $price "259,00";
  586.                             $urlRetour $this->generateUrl('monetico_return_client', ['id' => $contactInvestissementImmo->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  587.                             $urlNotif $this->generateUrl('monetico_notification', [], UrlGeneratorInterface::ABSOLUTE_URL);
  588.                             if (str_contains($this->request->getCurrentRequest()->get('_route'), 'preview')) {
  589.                                 $urlRetour $this->generateUrl('previewmonetico_return_client', ['host' => $this->theHost'id' => $contactInvestissementImmo->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  590.                                 $urlNotif $this->generateUrl('previewmonetico_notification', ['host' => $this->theHost], UrlGeneratorInterface::ABSOLUTE_URL);
  591.                             }
  592.                             $log("Previ Immo paiement CB: price={$price}, reference=" $contactInvestissementImmo->getReference());
  593.                             $params = [
  594.                                 'tpe'         => $parameters->getMoneticoTpe(),
  595.                                 'societe'     => $parameters->getMoneticoSociete(),
  596.                                 'hmac_key'    => $parameters->getMoneticoCle(),
  597.                                 'url_retour'  => $urlRetour,
  598.                                 'url_notif'   => $urlNotif,
  599.                                 'montant'     => $price,
  600.                                 'reference'   => $contactInvestissementImmo->getReference(),
  601.                                 'email'       => $contactInvestissementImmo->getEmail(),
  602.                                 'name'        => $contactInvestissementImmo->getName(),
  603.                                 'firstname'   => $contactInvestissementImmo->getFirstname(),
  604.                                 'address'     => $contactInvestissementImmo->getAdress(),
  605.                                 'zipCode'     => $contactInvestissementImmo->getZipCode(),
  606.                                 'city'        => $contactInvestissementImmo->getCity(),
  607.                             ];
  608.                             $log("Previ Immo génération du formulaire de paiement Monetico");
  609.                             return new Response($this->moneticoService->generatePaymentForm($params));
  610.                         }
  611.                         $this->CE->sendPreviImmo($contactInvestissementImmo);
  612.                         $this->form_send_previ_immo true;
  613.                         $log("Previ Immo email envoyé, référence=" $contactInvestissementImmo->getReference());
  614.                         $urlRetour $this->generateUrl('monetico_return_client', ['id' => $contactInvestissementImmo->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  615.                         if (str_contains($this->request->getCurrentRequest()->get('_route'), 'preview')) {
  616.                             $urlRetour $this->generateUrl('previewmonetico_return_client', ['host' => $this->theHost'id' => $contactInvestissementImmo->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
  617.                         }
  618.                         $urlRetour .= "?reference=" $contactInvestissementImmo->getReference();
  619.                         $urlRetour .= "&code-retour=paiement";
  620.                         $log("Previ Immo redirection vers {$urlRetour}");
  621.                         return new RedirectResponse($urlRetour);
  622.                     } else {
  623.                         $blacklistedEmail $blacklistRepo->findByEmail($email);
  624.                         if ($blacklistedEmail) {
  625.                             $blacklistedEmail->incrementBlockCount();
  626.                             $entityManager->persist($blacklistedEmail);
  627.                             $entityManager->flush();
  628.                         }
  629.                         $log("Previ Immo email blacklisté: {$email}");
  630.                     }
  631.                 } else {
  632.                     $log("Previ Immo formulaire non valide ou non soumis");
  633.                 }
  634.             }
  635.         } catch (\Throwable $e) {
  636.             // 🧾 Récupération sécurisée du contenu du formulaire
  637.             $formData = [];
  638.             try {
  639.                 if (isset($form_previimmo) && $form_previimmo->isSubmitted()) {
  640.                     $formData = [
  641.                         'data' => $form_previimmo->getData(),
  642.                         'submitted_data' => $request->request->all($form_previimmo->getName()),
  643.                         'errors' => (string) $form_previimmo->getErrors(truefalse),
  644.                     ];
  645.                 }
  646.             } catch (\Throwable $innerE) {
  647.                 $this->logger->warning('Impossible d’extraire les données du formulaire Previ Immo', [
  648.                     'inner_message' => $innerE->getMessage(),
  649.                 ]);
  650.             }
  651.             // 🔥 Log complet de l’exception
  652.             $this->logger->error('❌ Exception non interceptée dans Previ Immo', [
  653.                 'message' => $e->getMessage(),
  654.                 'trace' => $e->getTraceAsString(),
  655.                 'file' => $e->getFile(),
  656.                 'line' => $e->getLine(),
  657.                 'request_uri' => $request->getRequestUri(),
  658.                 'form_data' => $formData,
  659.             ]);
  660.             return new Response("Une erreur interne est survenue"500);
  661.         }
  662.         // newsletter
  663.         $form_newsletter $this->createForm(NewsletterType::class, null, ['cabinet' => $this->accountingFirm]);
  664.         $form_newsletter->handleRequest($request);
  665.         $this->formnewsletterview $form_newsletter->createView();
  666.         if ($form_newsletter->isSubmitted() && $form_newsletter->isValid()) {
  667.             $name $form_newsletter->get('name')->getData();
  668.             $email $form_newsletter->get('email')->getData();
  669.             // Vérifier si l'email est dans la blacklist
  670.             $blacklistRepo $this->getDoctrine()->getRepository(EmailBlacklist::class);
  671.             if (!($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name))) {
  672.                 $this->CE->sendNewsletterEmail($form_newsletter);
  673.             } elseif ($blacklistRepo->isEmailBlacklisted($email) || $blacklistRepo->isEmailBlacklisted($name)) {
  674.                 // Incrémenter le compteur de tentatives
  675.                 $blacklistedEmail $blacklistRepo->findByEmail($email);
  676.                 if ($blacklistedEmail) {
  677.                     $blacklistedEmail->incrementBlockCount();
  678.                     $entityManager $this->getDoctrine()->getManager();
  679.                     $entityManager->persist($blacklistedEmail);
  680.                     $entityManager->flush();
  681.                 }
  682.             }
  683.             $this->form_send_newsletter true;
  684.         }
  685.         // minibook
  686.         $form_minibook $this->createForm(MiniBookType::class);
  687.         $form_minibook->handleRequest($request);
  688.         $this->formminibookview $form_minibook->createView();
  689.         if ($form_minibook->isSubmitted() && $form_minibook->isValid()) {
  690.             $this->CE->sendMiniEbookEmail($form_minibook);
  691.             $this->form_send_minibook true;
  692.         }
  693.         // recrutement
  694.         $form_recrutement $this->createForm(AnnouncementApplyType::class, null, ['cabinet' => $this->accountingFirm]);
  695.         $form_recrutement->handleRequest($request);
  696.         $this->formrecrutementview $form_recrutement->createView();
  697.         if ($form_recrutement->isSubmitted() && $form_recrutement->isValid()) {
  698.             $this->CE->sendRecrutementEmail($form_recrutement);
  699.             $this->form_send_recrutement true;
  700.         }
  701.         // Setup return data
  702.         $parameters['accountingFirm'] = $parameters['cabinet'] = $this->accountingFirm;
  703.         $parameters['parameters'] = $this->accountingFirm->getParameters();
  704.         $parameters['form'] = $this->formview;
  705.         $parameters['form_send'] = $this->formsend;
  706.         $parameters['form_livre'] = $this->formlivreview;
  707.         $parameters['form_send_livre'] = $this->form_send_livre;
  708.         $parameters['form_company'] = $this->formcompanyview;
  709.         $parameters['form_send_company'] = $this->form_send_company;
  710.         $parameters['form_newsletter'] = $this->formnewsletterview;
  711.         $parameters['form_send_newsletter'] = $this->form_send_newsletter;
  712.         $parameters['form_minibook'] = $this->formminibookview;
  713.         $parameters['form_send_minibook'] = $this->form_send_minibook;
  714.         $parameters['form_recrutement'] = $this->formrecrutementview;
  715.         $parameters['form_send_recrutement'] = $this->form_send_recrutement;
  716.         $parameters['form_profession'] = $this->formprofessionview;
  717.         $parameters['form_send_profession'] = $this->form_send_profession;
  718.         $parameters['form_etre_rappele'] = $this->formetrerappeleview;
  719.         $parameters['form_send_etre_rappele'] = $this->form_send_etreRappele;
  720.         $parameters['form_custom'] = $this->formcustomview;
  721.         $parameters['form_send_custom'] = $this->form_send_custom;
  722.         $parameters['form_previ_creation'] = $this->formprevicreationview;
  723.         $parameters['form_send_previ_creation'] = $this->form_send_previ_creation;
  724.         $parameters['form_previ_immo'] = $this->formpreviimmoview;
  725.         $parameters['form_send_previ_immo'] = $this->form_send_previ_immo;
  726.         if (isset($this->announcementMain[0])) {
  727.             $parameters['announcementMain'] = $this->announcementMain[0];
  728.         }
  729.         if (isset($this->announcementSpontanee[0])) {
  730.             $parameters['announcementSpontanee'] = $this->announcementSpontanee[0];
  731.         }
  732.         $parameters["DynData"] = [];
  733.         // ✅ OPTIMISATION : Éviter count() dans la boucle et appels répétés aux getters
  734.         // Utilisation de foreach au lieu de for avec count()
  735.         foreach ($this->dynDataText as $dynDataItem) {
  736.             $name $dynDataItem->getName();
  737.             $key str_replace(' ''-'strtolower($name));
  738.             $parameters["DynData"][$key] = [
  739.                 'name' => $name,
  740.                 'data' => $dynDataItem->getData(),
  741.                 'type' => $dynDataItem->getType(),
  742.             ];
  743.         }
  744.         foreach ($this->dynDataArray as $dynDataItem) {
  745.             $name $dynDataItem->getName();
  746.             $dataItems $dynDataItem->getDataItems();
  747.             $dataItemsArray = [];
  748.             foreach ($dataItems as $item) {
  749.                 $dataItemsArray[] = [
  750.                     'titre' => $item->getTitle(),
  751.                     'data' => $item->getData(),
  752.                 ];
  753.             }
  754.             $key str_replace(' ''-'strtolower($name));
  755.             $parameters["DynData"][$key] = [
  756.                 'name' => $name,
  757.                 'data' => $dataItemsArray,
  758.                 'type' => $dynDataItem->getType(),
  759.             ];
  760.         }
  761.         $host $this->request->getCurrentRequest()->getHost();
  762.         $isPreview str_contains($this->request->getCurrentRequest()->get('_route') ?? '''preview');
  763.         if (!$isPreview && in_array($host, ['prod.lagence.expert''frontdev.lagence.expert''127.0.0.1'])) {
  764.             return parent::render($this->templateBase $view$parameters$response);
  765.         } else if ($this->accountingFirm->getParameters()->isMaintenance()) {
  766.             return parent::render("/maintenance.html.twig"$parameters$response);
  767.         } else if ($this->accountingFirm->getParameters()->isConstruction()) {
  768.             return parent::render("/maintenance.html.twig"$parameters$response);
  769.         } else {
  770.             return parent::render($this->templateBase $view$parameters$response);
  771.         }
  772.     }
  773.     private function isGibberishMessage(string $message): bool
  774.     {
  775.         $message trim($message);
  776.         // Trop court = on laisse passer
  777.         if (mb_strlen($message) < 10) {
  778.             return false;
  779.         }
  780.         // Aucun espace → très suspect
  781.         if (strpos($message' ') === false) {
  782.             // Uniquement lettres/chiffres
  783.             if (preg_match('/^[a-zA-Z0-9]+$/'$message)) {
  784.                 return true;
  785.             }
  786.         }
  787.         // Ratio voyelles / longueur
  788.         preg_match_all('/[aeiouyAEIOUY]/'$message$matches);
  789.         $vowelCount count($matches[0]);
  790.         $length mb_strlen($message);
  791.         if ($vowelCount $length 0.2) {
  792.             return true;
  793.         }
  794.         return false;
  795.     }
  796.     private function isSpamContent(string $message): bool
  797.     {
  798.         if (mb_strlen(trim($message)) < 10) {
  799.             return false;
  800.         }
  801.         // Mots-clés spam (casino, crypto, etc.)
  802.         $spamKeywords = [
  803.             'free',
  804.             'casino''poker''slots''jackpot''gambling',
  805.             'crypto''bitcoin''btc''ethereum''nft''binance''cryptomonnaie',
  806.             'forex''trading''investment opportunity''make money',
  807.             'viagra''cialis''pharma',
  808.             'click here''cliquez ici''buy now''achetez maintenant',
  809.             'paid to write''writing job''work from home''earn money''job quiz',
  810.             'passive income''side hustle''full training''no experience',
  811.             'make money online''extra income''financial freedom''be your own boss',
  812.         ];
  813.         $messageLower mb_strtolower($message);
  814.         foreach ($spamKeywords as $keyword) {
  815.             if (str_contains($messageLower$keyword)) {
  816.                 return true;
  817.             }
  818.         }
  819.         // Liens dans le message (http:// ou https:// uniquement — www. et .com seuls génèrent trop de faux positifs)
  820.         if (preg_match('/https?:\/\//i'$message)) {
  821.             return true;
  822.         }
  823.         // Majorité de mots en majuscules (plus de 50% des mots de 3+ lettres)
  824.         preg_match_all('/\b[A-Z]{3,}\b/'$message$capsWords);
  825.         preg_match_all('/\b\w{3,}\b/'$message$allWords);
  826.         if (!empty($allWords[0]) && count($capsWords[0]) / count($allWords[0]) > 0.5) {
  827.             return true;
  828.         }
  829.         // Répétition excessive d'un même caractère (5+ fois de suite)
  830.         if (preg_match('/(.)\1{4,}/'$message)) {
  831.             return true;
  832.         }
  833.         // Longue séquence de chiffres (12+ consécutifs — évite les numéros de téléphone à 10 chiffres)
  834.         if (preg_match('/\d{12,}/'$message)) {
  835.             return true;
  836.         }
  837.         return false;
  838.     }
  839.     protected function redirectRouteV2(Request $requeststring $prefix null): ?string
  840.     {
  841.         $redirect null;
  842.         $p $request->getRequestUri();
  843.         $pos strpos($p'?');
  844.         if ($pos !== false) {
  845.             $p substr($p0$pos 1) . str_replace('?''&'substr($p$pos 1));
  846.         }
  847.         $route parse_url($p);
  848.         if (isset($route['query'])) {
  849.             parse_str($route['query'], $query);
  850.             $page = isset($query['p']) ? $query['p'] : null;
  851.             $id = isset($query['id']) ? $query['id'] : null;
  852.             $date = isset($query['date']) ? $query['date'] : null;
  853.             $search = isset($query['q']) ? $query['q'] : null;
  854.             if (!empty($page) && !is_null($page)) {
  855.                 switch ($page) {
  856.                     case 'transformation-digitale.php':
  857.                         if (!empty($id) && !is_null($id)) {
  858.                             $redirect $this->generateUrl('client_widget_transformation_digitale_show', ['id' => $id'slug' => 'actualite']);
  859.                         } else {
  860.                             $redirect $this->generateUrl('client_widget_transformation_digitale_noid');
  861.                         }
  862.                         break;
  863.                     case 'calendrier-fiscal.php':
  864.                         if (!empty($id) && !is_null($id)) {
  865.                             $redirect $this->generateUrl('client_widget_news_fisc_show', ['id' => $id]);
  866.                         }
  867.                         break;
  868.                     case 'actualites-calendrier-fiscal.php':
  869.                         if (!empty($date) && !is_null($date)) {
  870.                             $redirect $this->generateUrl('client_widget_news_fisc_list_show', ['date' => $date]);
  871.                         }
  872.                         break;
  873.                     case 'actualite.php':
  874.                         if (!empty($id) && !is_null($id)) {
  875.                             $redirect $this->generateUrl('client_widget_news_juri_show', ['id' => $id'slug' => 'actualite']);
  876.                         }
  877.                         break;
  878.                     case 'bien-etre.php':
  879.                         if (!empty($id) && !is_null($id)) {
  880.                             $redirect $this->generateUrl('client_widget_bien_etre_show', ['id' => $id'slug' => 'actualite']);
  881.                         } else {
  882.                             $redirect $this->generateUrl('client_widget_bien_etre_noid');
  883.                         }
  884.                         break;
  885.                     case 'actualite-cabinet.php':
  886.                         if (!empty($id) && !is_null($id)) {
  887.                             $redirect $this->generateUrl('client_widget_news_cabinet_show', ['id' => $id'slug' => 'actualite']);
  888.                         }
  889.                         break;
  890.                     case 'recherche.php':
  891.                         if (!empty($search) && !is_null($search)) {
  892.                             $redirect $this->generateUrl('client_widget_recherche', ['q' => $search]);
  893.                         }
  894.                         break;
  895.                     case 'podcast.php':
  896.                         if (!empty($id) && !is_null($id)) {
  897.                             $redirect $this->generateUrl('client_widget_podcast_detail', ['id' => $id]);
  898.                         } else {
  899.                             $redirect $this->generateUrl('client_widget_podcast_detail', ['id' => "list"]);
  900.                         }
  901.                         break;
  902.                     case 'podcast-latest.php':
  903.                             $podcats_latest $this->serviceQMV2->getPodcastLatest();
  904.                             $redirect $this->generateUrl('client_widget_podcast_detail', ['id' => $podcats_latest[0]->getId()]);
  905.                         break;
  906.                     case 'infographie-rse.php':
  907.                         if (!empty($id) && !is_null($id)) {
  908.                             $redirect $this->generateUrl('client_widget_infographie_rse_detail', ['id' => $id]);
  909.                         } else {
  910.                             $redirect $this->generateUrl('client_widget_infographie_rse_detail_noid');
  911.                         }
  912.                         break;
  913.                     case 'participation.php':
  914.                         $redirect $this->generateUrl('client_widget_participation_pal');
  915.                         break;
  916.                     case 'journal.php':
  917.                         if (!empty($id) && !is_null($id)) {
  918.                             $redirect $this->generateUrl('client_widget_journal_show', ['id' => $id]);
  919.                         } else {
  920.                             $redirect $this->generateUrl('client_widget_journal_noid');
  921.                         }
  922.                         break;
  923.                     case 'aide.php':
  924.                         if (!empty($id) && !is_null($id)) {
  925.                             $redirect $this->generateUrl('client_widget_aide_show', ['id' => $id]);
  926.                         } else {
  927.                             $redirect $this->generateUrl('client_widget_aide_noid');
  928.                         }
  929.                         break;
  930.                     case 'calendrier-juridique.php':
  931.                         if ($date) {
  932.                             $redirect $this->generateUrl('client_widget_news_fisc_list_show', ['date' => $date]);
  933.                         } else {
  934.                             $redirect $this->generateUrl('client_widget_calendrier_show');
  935.                         }
  936.                         break;
  937.                     default:
  938.                         // NOPE
  939.                         break;
  940.                 }
  941.             }
  942.         }
  943.         return $redirect $prefix $redirect $redirect;
  944.     }
  945. }