src/Controller/Frontend/LandingController.php line 87

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Frontend;
  3. use App\Controller\Controller;
  4. use App\Entity\FranceWiki;
  5. use App\Entity\PortugalWiki;
  6. use App\Entity\ProUser;
  7. use App\Entity\RecruitmentWiki;
  8. use App\Entity\Wiki;
  9. use App\Form\Type\Frontend\ContactProType;
  10. use App\Form\Type\Frontend\ContactType;
  11. use App\Form\Type\Frontend\RecruitmentApplyType;
  12. use App\Form\Type\Frontend\SaleAutoProType;
  13. use App\Form\Upload\Uploader;
  14. use App\Mailer\Mailer;
  15. use App\Parameter\Provider;
  16. use App\Repository\FranceWikiRepository;
  17. use App\Repository\PortugalWikiRepository;
  18. use App\Repository\RecruitmentWikiRepository;
  19. use App\Repository\WikiRepository;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Symfony\Component\Filesystem\Filesystem;
  22. use Symfony\Component\Form\FormFactoryInterface;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  25. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  26. use Symfony\Component\Mime\Email;
  27. use Symfony\Contracts\Translation\TranslatorInterface;
  28. use Twig\Environment;
  29. /**
  30.  * Controller for the landing pages needing only one action.
  31.  */
  32. class LandingController extends Controller
  33. {
  34.     public function __construct(
  35.         private readonly TranslatorInterface $translator,
  36.         private readonly SessionInterface $session,
  37.         private readonly FormFactoryInterface $formFactory,
  38.         private readonly Mailer $mailer,
  39.         private readonly string $defaultFrom,
  40.         private readonly string $contactTo,
  41.         private readonly string $contactOptimvoTo,
  42.         private readonly Provider $provider)
  43.     {
  44.     }
  45.     public function contactAction(Request $request)
  46.     {
  47.         $form $this->createForm(ContactType::class);
  48.         $form->handleRequest($request);
  49.         if ($form->isSubmitted() && $form->isValid()) {
  50.             $data $form->getData();
  51.             $this->mailer->send(
  52.                 $this->renderView('/Mail/contact.html.twig', ['data' => $data]),
  53.                 sprintf('Nouveau message de %s %s'$data['firstname'], $data['lastname']),
  54.                 $this->contactTo,
  55.                 $this->defaultFrom
  56.             );
  57.             $this->session->getFlashbag()->add('success'$this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
  58.             return $this->redirect($this->generateUrl('frontend_contact'));
  59.         }
  60.         return $this->render('/Frontend/landing/contact.html.twig', ['form' => $form->createView()]);
  61.     }
  62.     public function wikiListPortugalAction(PortugalWikiRepository $portugalWikiRepository)
  63.     {
  64.         $wikis $portugalWikiRepository->findBy(['published' => true], ['createdAt' => 'DESC']);
  65.         return $this->render('/Frontend/wiki/list_pt.html.twig', ['wikis' => $wikis]);
  66.     }
  67.     public function wikiListFranceAction(FranceWikiRepository $franceWikiRepository$limit null)
  68.     {
  69.         $wikis $franceWikiRepository->findListByType(Wiki::TYPE_B2C$limit);
  70.         return $this->render('/Frontend/wiki/list_fr.html.twig', ['wikis' => $wikis]);
  71.     }
  72.     public function wikiListFranceProAction(FranceWikiRepository $franceWikiRepository$limit null)
  73.     {
  74.         $wikis $franceWikiRepository->findListByType(Wiki::TYPE_B2B$limit);
  75.         return $this->render('/Frontend/wiki/list_fr.html.twig', ['wikis' => $wikis]);
  76.     }
  77.     public function wikiAction(EntityManagerInterface $entityManagerWikiRepository $wikiRepositoryFranceWikiRepository $franceWikiRepository$maker$model)
  78.     {
  79.         $wikis null;
  80.         $user $this->getUser();
  81.         if (null === $user && 'private' === $this->session->get('dimension''private')) {
  82.             $userType Wiki::TYPE_B2C;
  83.         } else {
  84.             $userType Wiki::TYPE_B2B;
  85.         }
  86.         if (null === $model) {
  87.             $wiki $wikiRepository->findOneBySlug($maker);
  88.             $imageAlt $maker;
  89.         } else {
  90.             $wiki $wikiRepository->findOneBySlugAndParentSlug($model$maker);
  91.             $imageAlt $maker.' '.$model;
  92.         }
  93.         if (null === $wiki || !$wiki->isPublished()) {
  94.             throw new NotFoundHttpException();
  95.         }
  96.         $template '/Frontend/wiki/view.html.twig';
  97.         if ($wiki instanceof FranceWiki) {
  98.             $template '/Frontend/wiki/franceView.html.twig';
  99.             $wikis $franceWikiRepository->findLastWikis($model$userType3);
  100.             if (Wiki::TYPE_B2C == $userType) {
  101.                 $wiki->addOneToNbViews();
  102.             } elseif (Wiki::TYPE_B2B == $userType) {
  103.                 $wiki->addOneToNbViewsPro();
  104.             }
  105.             $entityManager->flush();
  106.         }
  107.         if ($wiki instanceof PortugalWiki) {
  108.             $template '/Frontend/wiki/portugalView.html.twig';
  109.         }
  110.         return $this->render($template, ['wiki' => $wiki'imageAlt' => $imageAlt'wikis' => $wikis]);
  111.     }
  112.     public function recruitmentWikiAction(RecruitmentWikiRepository $recruitmentWikiRepository)
  113.     {
  114.         $wikis $recruitmentWikiRepository->findBy(['published' => true], ['createdAt' => 'DESC']);
  115.         return $this->render('/Frontend/wiki/recruitment.html.twig', ['wikis' => $wikis]);
  116.     }
  117.     public function recruitmentApplyAction(Request $requestTranslatorInterface $translatorUploader $uploader, ?Wiki $wiki null)
  118.     {
  119.         $form $this->formFactory->create(RecruitmentApplyType::class);
  120.         $form->handleRequest($request);
  121.         if ($form->isSubmitted() && $form->isValid()) {
  122.             $data $form->getData();
  123.             $recipients $this->provider->getParameterValue('recruitment.emails');
  124.             $files $uploader->handleUpload($form);
  125.             $filePathCV $files['cv']->getPathName();
  126.             $fileNameCV $data['firstName'].'-'.$data['lastName'].'-CV.'.$files['cv']->guessExtension();
  127.             if (null !== $data['coverLetter']) {
  128.                 $filePathLM $files['coverLetter']->getPathName();
  129.                 $fileNameLM $data['firstName'].'-'.$data['lastName'].'-LM.'.$files['coverLetter']->guessExtension();
  130.             }
  131.             $message = new Email();
  132.             $message->to(...$this->provider->getParameterValue('recruitment.emails'));
  133.             $message->from($data['email']);
  134.             $message->subject('[VPauto] Candidature - '.$data['firstName'].' '.$data['lastName'].' - '.$data['job']);
  135.             $body $data['message'];
  136.             $message->html($body);
  137.             try {
  138.                 $message->attachFromPath($filePathCV$fileNameCV);
  139.                 if (null !== $data['coverLetter']) {
  140.                     $message->attachFromPath($filePathLM$fileNameLM);
  141.                 }
  142.             } catch (\Exception $e) {
  143.                 var_dump($e->getMessage());
  144.                 exit;
  145.             }
  146.             $this->mailer->sendMessage($message);
  147.             $this->session->getFlashbag()->add('success'$translator->trans('frontend.wiki.recruitment.success'));
  148.             return $this->redirect($this->generateUrl('frontend_wiki_recruitment'));
  149.         }
  150.         return $this->render('/Frontend/wiki/recruitment_apply.html.twig', [
  151.             'wiki' => $wiki,
  152.             'form' => $form->createView(),
  153.         ]);
  154.     }
  155.     public function contactProAction(Request $request)
  156.     {
  157.         $form $this->createForm(ContactProType::class);
  158.         $form->handleRequest($request);
  159.         if ($form->isSubmitted() && $form->isValid()) {
  160.             $data $form->getData();
  161.             $this->mailer->send(
  162.                 $this->renderView('/Mail/contact_pro.html.twig', ['data' => $data]),
  163.                 sprintf('Nouveau message de %s %s'$data['firstname'], $data['lastname']),
  164.                 $this->contactTo,
  165.                 $this->defaultFrom
  166.             );
  167.             $this->session->getFlashbag()->add('success'$this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
  168.             return $this->redirect($this->generateUrl('frontend_contact_pro'));
  169.         }
  170.         return $this->render('/Frontend/landing/contact-pro.html.twig', ['form' => $form->createView()]);
  171.     }
  172.     public function saleAutoProAction(Request $request)
  173.     {
  174.         $form $this->createForm(SaleAutoProType::class);
  175.         $form->handleRequest($request);
  176.         if ($form->isSubmitted() && $form->isValid()) {
  177.             $data $form->getData();
  178.             $this->mailer->send(
  179.                 $this->renderView('/Mail/contact_optimvo.html.twig', ['data' => $data]),
  180.                 sprintf('Nouveau message de %s'$data['lastname']),
  181.                 $this->contactOptimvoTo,
  182.                 $this->defaultFrom
  183.             );
  184.             $this->session->getFlashbag()->add('success'$this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
  185.             return $this->redirect($this->generateUrl('frontend_sale_auto_pro'));
  186.         }
  187.         return $this->render('/Frontend/landing/sale-auto-pro.html.twig', ['form' => $form->createView()]);
  188.     }
  189.     public function salesRoomsProAction()
  190.     {
  191.         return $this->render('/Frontend/landing/accessMap/access-map.html.twig', [
  192.             'type' => 'pro',
  193.         ]);
  194.     }
  195.     public function roomLorientAction()
  196.     {
  197.         return $this->render('/Frontend/landing/accessMap/room-lorient.html.twig', [
  198.             'type' => 'pro',
  199.         ]);
  200.     }
  201.     public function roomNantesAction()
  202.     {
  203.         return $this->render('/Frontend/landing/accessMap/room-nantes.html.twig', [
  204.             'type' => 'pro',
  205.         ]);
  206.     }
  207.     public function roomRouenAction()
  208.     {
  209.         return $this->render('/Frontend/landing/accessMap/room-rouen.html.twig', [
  210.             'type' => 'pro',
  211.         ]);
  212.     }
  213.     public function roomLyonAction()
  214.     {
  215.         return $this->render('/Frontend/landing/accessMap/room-lyon.html.twig', [
  216.             'type' => 'pro',
  217.         ]);
  218.     }
  219.     public function roomParisAction()
  220.     {
  221.         return $this->render('/Frontend/landing/accessMap/room-paris.html.twig', [
  222.             'type' => 'pro',
  223.         ]);
  224.     }
  225.     public function roomBordeauxAction()
  226.     {
  227.         return $this->render('/Frontend/landing/accessMap/room-bordeaux.html.twig', [
  228.             'type' => 'pro',
  229.         ]);
  230.     }
  231.     public function roomMarseilleAction()
  232.     {
  233.         return $this->render('/Frontend/landing/accessMap/room-marseille.html.twig', [
  234.             'type' => 'pro',
  235.         ]);
  236.     }
  237.     public function roomLilleAction()
  238.     {
  239.         return $this->render('/Frontend/landing/accessMap/room-lille.html.twig', [
  240.             'type' => 'pro',
  241.         ]);
  242.     }
  243.     public function roomSeneffeAction()
  244.     {
  245.         return $this->render('/Frontend/landing/accessMap/room-seneffe.html.twig', [
  246.             'type' => 'pro',
  247.         ]);
  248.     }
  249.     public function roomSetubalAction()
  250.     {
  251.         return $this->render('/Frontend/landing/accessMap/room-setubal.html.twig', [
  252.             'type' => 'pro',
  253.         ]);
  254.     }
  255.     public function roomMadridAction()
  256.     {
  257.         return $this->render('/Frontend/landing/accessMap/room-madrid.html.twig', [
  258.             'type' => 'pro',
  259.         ]);
  260.     }
  261.     public function privacyPolicyAction(Request $request)
  262.     {
  263.         if (null === $type $this->getUser() instanceof ProUser 'pro' null) {
  264.             $type $request->query->get('type') ?? null;
  265.         }
  266.         return $this->render('/Frontend/landing/privacy-policy.html.twig', [
  267.             'type' => $type,
  268.         ]);
  269.     }
  270.     /**
  271.      * Available templates :
  272.      *     - /Frontend/landing/cgv/fr/content.html.twig
  273.      *     - /Frontend/landing/cgv/be/content.fr.html.twig
  274.      *     - /Frontend/landing/cgv/be/content.nl.html.twig
  275.      *     - /Frontend/landing/cgv/be/content.en.html.twig
  276.      *     - /Frontend/landing/cgv/es/content.es.html.twig
  277.      *     - /Frontend/landing/cgv/es/content.en.html.twig
  278.      *     - /Frontend/landing/cgv/pt/content.pt.html.twig
  279.      *     - /Frontend/landing/cgv/pt/content.en.html.twig.
  280.      */
  281.     public function countryCGVAction(Request $requeststring $countryEnvironment $twig)
  282.     {
  283.         $locale $request->getLocale();
  284.         $template 'content.html.twig';
  285.         if ($twig->getLoader()->exists("/Frontend/landing/cgv/{$country}/content.{$locale}.html.twig")) {
  286.             $template "content.{$locale}.html.twig";
  287.         } elseif ($twig->getLoader()->exists("/Frontend/landing/cgv/{$country}/content.en.html.twig")) {
  288.             $template 'content.en.html.twig';
  289.         }
  290.         return $this->render("/Frontend/landing/cgv/{$country}/{$template}");
  291.     }
  292.     public function cookiesAction()
  293.     {
  294.         return $this->render('/Frontend/landing/cookies.html.twig');
  295.     }
  296. }