src/Controller/HomeController.php line 159

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Diffusion\PubDiffusion;
  4. use App\Diffusion\PopupExtraDiffusion;
  5. use App\Entity\Adherent\Magasin;
  6. use App\Entity\Adherent\WebFactoryConsentement;
  7. use App\Entity\ConfigEadh\Popover;
  8. use App\Entity\EspaceFournisseur\Pub;
  9. use App\Entity\Message\Message;
  10. use App\Entity\PopupExtra;
  11. use App\Entity\VenteRechercheMagasins\VenteRechercheMagasins;
  12. use App\Enum\ArticleLocationsEnum;
  13. use App\Form\User\WebFactoryConsentementType;
  14. use App\Manager\Crm\CrmAccessManager;
  15. use App\Manager\OpcManager;
  16. use App\Manager\Progress\ModerationChpSupContact;
  17. use App\Manager\Webfactory\WebfactoryManager;
  18. use App\Repository\PopupExtraMasquerRepository;
  19. use DateTime;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\HttpFoundation\Response;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Component\Security\Core\Security;
  28. use Symfony\Component\Security\Core\User\UserInterface;
  29. use Symfony\Contracts\Translation\TranslatorInterface;
  30. class HomeController extends AbstractController
  31. {
  32.     private ?UserInterface $user;
  33.     public function __construct(
  34.         Security                                 $security,
  35.         private readonly EntityManagerInterface  $em,
  36.         private readonly TranslatorInterface     $translator,
  37.         private readonly CrmAccessManager        $crmAccessManager,
  38.         private readonly WebfactoryManager       $webfactoryManager,
  39.         private readonly OpcManager              $opcManager,
  40.         private readonly ModerationChpSupContact $moderationChpSupContact
  41.     )
  42.     {
  43.         $this->user = $security->getUser();
  44.     }
  45.     #[Route(path: '/', name: 'home')]
  46.     public function home(Request $request, PubDiffusion $pubDiffusion, PopupExtraMasquerRepository $popupMasquerRepository, PopupExtraDiffusion $popupDiffusion): Response
  47.     {
  48.         $dateDuJour = new DateTime('now');
  49.         $disabledAnnonces = $this->em->getRepository(VenteRechercheMagasins::class)->createQueryBuilder('vrm')
  50.             ->where('vrm.disable_at < :date')
  51.             ->andWhere('vrm.disabled = :disabled')
  52.             ->setParameters(['date' => $dateDuJour, 'disabled' => 0])
  53.             ->getQuery()
  54.             ->getResult();
  55.         if (!empty($disabledAnnonces)) {
  56.             foreach ($disabledAnnonces as $disabledAnnonce) {
  57.                 $notif = new Message();
  58.                 $notif->setAdherent($disabledAnnonce->getCodeAdh());
  59.                 $notif->setType('Vente_magasins');
  60.                 $notif->setObjet('Vente et recherche de magasin');
  61.                 $notif->setContenu('Votre annonce N°' . $disabledAnnonce->getRefAnnonce() . ' a été mis hors ligne !');
  62.                 $notif->setUrl($this->generateUrl('vente_et_recherche_magasin_dashboard'));
  63.                 $notif->setLangue($this->user->getLangue());
  64.                 $disabledAnnonce->setDisabled(1);
  65.                 $this->em->persist($notif);
  66.                 $this->em->persist($disabledAnnonce);
  67.             }
  68.             $this->em->flush();
  69.         }
  70.         // Je récupère la pop-up du moment (en fonction de la date)
  71.         $popupOptions = ['options' => ['active' => 1, 'langue' => $this->user->getLangue()]];
  72.         $popupContent = $popupDiffusion->getDatasByEntities(PopupExtra::class, $popupOptions);
  73.         $popupContent = (!empty($popupContent)) ? $popupContent[0] : null;
  74.         $isAccord = false;
  75.         if ($popupContent) {
  76.             $accord = $popupMasquerRepository->findOneBy(['K_ADHERENT' => $this->user->getKAdherent(), 'popup' => $popupContent->getId()]);
  77.             if (!empty($accord)) {
  78.                 $isAccord = true;
  79.             }
  80.         }
  81.         $pubRequestOptions = ['options' => ['location' => 'HOMEPAGE', 'langue' => true], 'orderBy' => ['sort' => 'ASC']];
  82.         $pubs = $pubDiffusion->getDatasByEntities(Pub::class, $pubRequestOptions);
  83.         $popovers = $this->em->getRepository(Popover::class)->getPopoverByCategory('Homepage', $request->getLocale());
  84.         return $this->render('home/home.html.twig', [
  85.             'article_locations' => ArticleLocationsEnum::toArray(),
  86.             'pubs' => $pubs,
  87.             'popupContent' => $popupContent,
  88.             'isAccord' => $isAccord,
  89.             'popovers' => $popovers
  90.         ]);
  91.     }
  92.     #[Route(path: '/multimag-{codeAdh}', name: 'multimag_switch')]
  93.     public function multimagSwitch($codeAdh): RedirectResponse
  94.     {
  95.         $multimagSwitch = $this->em->getRepository(Magasin::class)->findOneBy(['k_adherent' => $codeAdh]);
  96.         if ($multimagSwitch) {
  97.             $this->getUser()->setKadherent($codeAdh);
  98.             $this->getUser()->setMagasin($multimagSwitch->getLib());
  99.             $this->getUser()->setLib($multimagSwitch->getLib());
  100.             $this->getUser()->setCRM($this->crmAccessManager->checkAccessCrm($codeAdh));
  101.             $this->getUser()->setESV(($multimagSwitch->getKNIVEAUADH() === 'LOL4G' || $multimagSwitch->getKNIVEAUADH() === 'LOL2G'));
  102.             $contratSiteWeb = $this->webfactoryManager->getContratFactory($codeAdh);
  103.             $this->getUser()->setContratSiteWeb($contratSiteWeb);
  104.             $this->getUser()->setKPA($multimagSwitch->getKPA());
  105.             $this->opcManager->initJaugeOpc($multimagSwitch);
  106.         }
  107.         return $this->redirectToRoute('home');
  108.     }
  109.     #[Route(path: '/mentions-legales', name: 'mentions')]
  110.     public function mentionsLegalesAction(): Response
  111.     {
  112.         $locale = $this->translator->getLocale();
  113.         if ($locale == "nl") {
  114.             return $this->render('home/Politique/mentions_BE_NL.html.twig');
  115.         } else {
  116.             return $this->render('home/Politique/mentions.html.twig');
  117.         }
  118.     }
  119.     #[Route(path: '/politique-de-confidentialite', name: 'politique')]
  120.     public function politiqueConfAction(): Response
  121.     {
  122.         $locale = $this->translator->getLocale();
  123.         if ($locale == "nl") {
  124.             return $this->render('home/Politique/politique_BE_NL.html.twig');
  125.         } else {
  126.             return $this->render('home/Politique/politique.html.twig');
  127.         }
  128.     }
  129.     #[Route(path: '/lang/{lang}', name: 'change_lang')]
  130.     public function updateLangAction(Request $request, $lang): RedirectResponse
  131.     {
  132.         $referer = $request->headers->get('referer');
  133.         $session = $request->getSession();
  134.         if ($this->getUser()) {
  135.             $session->set('_locale', strtolower((string)$this->getUser()->getLangue()));
  136.         } else {
  137.             $session->set('_locale', strtolower((string)$lang));
  138.         }
  139.         return $this->redirect($referer);
  140.     }
  141.     #[Route(path: '/redirect/bibliotheque-facebook', name: 'redirection_bibliotheque_fb')]
  142.     #[IsGranted(['ROLE_BIBLIOTHEQUE_FB'])]
  143.     public function bibliothequeFb(): RedirectResponse
  144.     {
  145.         $param = 'fr_FR';
  146.         if (strtoupper((string)$this->user->getCentrale()) == "BE") {
  147.             $param = (strtoupper((string)$this->user->getLangue()) == 'NL') ? 'be_NL' : 'be_FR';
  148.         }
  149.         return $this->redirect('https://form.groupeall.com/bibliotheque-facebook/' . $param . '/api-login-checkout/' . $this->user->getTokenSSO());
  150.     }
  151.     #[Route(path: '/redirect/webshop', name: 'redirection_webshop')]
  152.     public function webshopMontures(): RedirectResponse
  153.     {
  154.         return $this->redirect('https://webshop.groupeall.com/login?token=' . $this->user->getTokenSSO());
  155.     }
  156.     #[Route(path: '/factory-presentation', name: 'consentement_factory')]
  157.     #[Route(path: '/factory-presentation-start', name: 'consentement_factory_start')]
  158.     public function presentationFactory(Request $request): RedirectResponse|Response
  159.     {
  160.         if ($request->getRequestUri() === "/factory-presentation-start") {
  161.             $packType = "gratuit";
  162.         } else {
  163.             $packType = "payant";
  164.         }
  165.         $consentementAdh = $this->em->getRepository(WebFactoryConsentement::class)->findOneBy(['adherent' => $this->getUser()->getKadherent()]);
  166.         if (!is_null($consentementAdh) || !$this->getUser()->getContratSiteWeb()['access']) {
  167.             return $this->redirectToRoute("home");
  168.         }
  169.         $newConsentementAdh = new WebFactoryConsentement();
  170.         $newConsentementAdh->setAdherent($this->getUser()->getKadherent());
  171.         $form = $this->createForm(WebFactoryConsentementType::class, $newConsentementAdh, ['type_pack' => $packType]);
  172.         $form->handleRequest($request);
  173.         if ($form->isSubmitted() && $form->isValid()) {
  174.             $newConsentementAdh->setTypePack($packType);
  175.             $this->em->persist($newConsentementAdh);
  176.             $this->em->flush();
  177.             $this->addFlash("success", "Vos informations ont bien été enregistrées");
  178.             return $this->redirectToRoute("home");
  179.         }
  180.         return $this->render("home/consentement_factory.html.twig", [
  181.             'form' => $form->createView(),
  182.             'fitting_pack' => $packType
  183.         ]);
  184.     }
  185. }