src/Controller/FrontController.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\{ContactBlogArticleTranslationBlogCategorieTranslationHomeBloc};
  4. use App\Form\ContactType;
  5. use App\Security\EmailVerifier;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Mime\Address;
  12. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
  16. use Symfony\Component\Translation\LocaleSwitcher;
  17. class FrontController extends AbstractController
  18. {
  19.     #[Route('/'name'home')]
  20.     #[Route('/{_locale}'name'home.es'requirements: ['_locale' => 'es'] )]
  21.     #[Route('/{_locale}'name'home.de'requirements: ['_locale' => 'de'] )]
  22.     public function register(Request $requestEntityManagerInterface $entityManagerTranslatorInterface $translator): Response
  23.     {
  24.         $contact = new Contact();
  25.         $contactForm $this->createForm(ContactType::class, $contact);
  26.         $session $request->getSession();
  27.         /* affichage du popup toutes les 24h) */
  28.         if($session->has('popup')){
  29.             $infos $session->get('popup');
  30.             $time $infos['time'];
  31.             $new_time = clone($time);
  32.             $new_time $new_time->modify('+24 hours');
  33.             $now = new \Datetime();
  34.             if($now $time and $now $new_time){
  35.                 $showPopup 0;
  36.             }else{
  37.                 $showPopup 1;
  38.                 $session->set('popup', ['time' => new \DateTime()]);
  39.             }
  40.         }else{
  41.             $showPopup 1;
  42.             $session->set('popup', ['time' => new \DateTime()]);
  43.         }
  44.         $homePage =   $entityManager->getRepository(HomeBloc::class)->findOneById(1);
  45.         return $this->render('home.html.twig', [
  46.             'form' => $contactForm->createView(),
  47.             'showPopup' => $showPopup,
  48.             'homePage' => $homePage
  49.         ]);
  50.     }
  51.       #[Route('{_locale}/switcher/{route}'name'switcher')]
  52.       public function switcher($_locale$routeRequest $requestEntityManagerInterface $em): Response
  53.       {
  54.         $params $request->query->all();
  55.         $slug null;
  56.         if(!empty($params) and array_key_exists('params'$params)){
  57.           if(array_key_exists('slug'$params['params'])){
  58.             $slug $params['params']['slug'];
  59.           }
  60.         }
  61.         $route_locale = ($route.'.'.$_locale);
  62.         $last_three substr($route, -3);
  63.         if($last_three == '.de' OR $last_three == '.es'){
  64.           $route =  substr($route0strlen($route) - 3);
  65.           $route_locale = ($route.'.'.$_locale);
  66.         }
  67.         if($_locale == 'fr'){
  68.             if($route == 'blog.show'){
  69.               $article $em->getRepository(BlogArticleTranslation::class)->findOneBySlug($slug);
  70.               return $this->redirectToRoute($route, ['slug' => $article->getSlug() ]);
  71.             }else if($route == 'blog.category'){
  72.               $article $em->getRepository(BlogCategorieTranslation::class)->findOneBySlug($slug);
  73.               return $this->redirectToRoute($route, ['slug' => $article->getSlug() ]);
  74.             }
  75.             return $this->redirectToRoute($route$params);
  76.         }
  77.         if($route_locale == 'blog.show.es' OR $route_locale == 'blog.show.de' and !empty($slug)){
  78.           $article $em->getRepository(BlogArticleTranslation::class)->findOneBySlug($slug);
  79.           if(!empty($article)){
  80.             return $this->redirectToRoute($route_locale, ['slug' => $article->getSlug() ]);
  81.           }
  82.         }else if($route == 'blog.category'){
  83.           $article $em->getRepository(BlogCategorieTranslation::class)->findOneBySlug($slug);
  84.           return $this->redirectToRoute($route_locale, ['slug' => $article->getSlug() ]);
  85.         }
  86.         return $this->redirectToRoute($route_locale$params);
  87.       }
  88. }