src/Controller/front/Pages/PageController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller\front\Pages;
  3. use ReCaptcha\ReCaptcha;
  4. use App\Entity\Pages\Page;
  5. use App\Entity\Contact\Contact;
  6. use App\Form\Contact\ContactType;
  7. use App\Service\Mailer\MailerService;
  8. use App\Controller\Admin\CoreController;
  9. use App\Entity\Pages\PageCategory;
  10. use App\Repository\Pages\PageRepository;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use App\Service\Manager\Blocs\BlocManager;
  13. use App\Service\Manager\Media\MediaManager;
  14. use App\Repository\Pages\PageLangRepository;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use App\Service\Manager\Pages\PaletteColorsManager;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. #[Route('/page')]
  21. class PageController extends CoreController
  22. {
  23.     #[Route('/{slug}'name'front_page_show')]
  24.     public function show(
  25.                             PageLangRepository $pageLangRepository,
  26.                             PageRepository $pageRepository,
  27.                             MediaManager $mediaManager,
  28.                             BlocManager $blocManager,
  29.                             PaletteColorsManager $paletteColorsManager,       
  30.                             Request $request,MailerService $mailer,
  31.                             ManagerRegistry $doctrine,
  32.                             TranslatorInterface $translator,
  33.                             $slug
  34.                         ): Response
  35.     {
  36.         $language $this->getCurrentLanguage(); 
  37.         $pageLang $pageLangRepository->findOneBy([
  38.             'language'=> $language,
  39.             'slug' => $slug
  40.         ]);
  41.         $page $pageLang->getPage(); 
  42.         $contact = new Contact();
  43.         $form $this->createForm(ContactType::class, $contact, [
  44.             'action' => '#sectionContact',
  45.             //'origin' => str_replace("Proxies\\__CG__\\", '',get_class($page)),
  46.             'origin' => $doctrine->getManager()->getClassMetadata(PageCategory::class),
  47.             'originId' =>  ($page->getId() )
  48.         ]);
  49.         $form->handleRequest($request);
  50.         
  51.         if ($request->isMethod('POST')) {
  52.        
  53.          if($form->isValid()) {
  54.             
  55.             $em $doctrine->getManager();
  56.                     
  57.             $name  =  $email "";
  58.         
  59.             $name $form->get('name')->getData();
  60.             $entreprise $form->get('entreprise')->getData();
  61.             $phone $form->get('phone')->getData();
  62.             $email $form->get('email')->getData();
  63.             $from['from'][$name] = $email;
  64.             $isAccepted $form->get('isAccepted')->getData();
  65.             $to $this->getParameter('email.to');
  66.             $from $_ENV['EMAIL_FROM'];
  67.             $subject=  'Netisse'' - '.$pageLang->getName();
  68.             $mailer->sendEmail(
  69.                 $to,
  70.                 '<html><body><h1>' $subject '</h1>' .'<h4>NOM:</h4>'.$form->get('name')->getData().'<br>'.'<h4>EMAIL:</h4>'.$form->get('email')->getData() .
  71.                 '<br><h4>ENTREPRISE:</h4>'.$form->get('entreprise')->getData() . '<br><h4>TELEPHONE:</h4>'.$form->get('phone')->getData().'<br><h4>MESSAGE:</h4>'.$form->get('message')->getData() . '</body></html>',
  72.                 $subject,
  73.                 $from
  74.             );
  75.             
  76.             $em->persist($contact);
  77.             $em->flush(); 
  78.             $this->addFlash('success'$translator->trans('front.form.msg_send'));
  79.         // Create a redirect response to the current page with an anchor tag
  80.             $redirectUrl $this->generateUrl('front_page_show', ['slug' => $slug]) . '#sectionContact';
  81.             return $this->redirect($redirectUrl);
  82.             }
  83.             else {
  84.                 // Vérifier le champ Honeypot
  85.                 $emailHoneypot $form->get('email_honeypot')->getData();
  86.                 if (!empty($emailHoneypot)) {
  87.                     $this->addFlash('danger'$translator->trans('Vous êtes considéré comme Bot/Spammer !.'));    
  88.                 }
  89.             }
  90.         }
  91.         $medias $mediaManager->getMedias($pagenull$language);
  92.         $blocs $blocManager->getBlocs($page);
  93.        
  94.         $paletteColors $paletteColorsManager->getValues('App\\Entity\\Pages\\Page',$page->getId());
  95.          $colorPage=null;
  96.         if($paletteColors){
  97.             $colorPage=$paletteColors[0];
  98.         }
  99.         $template 'front/pages/index.html.twig';
  100.         $paramsPage $page->getPageSousCategory() ?  ['id' => $page->getId(), 'category' => $page->getPageSousCategory()] : ['id' => $page->getId(), 'media_page' => true ];
  101.         if($page->getPageSousCategory()) {
  102.             $paramsPage['media_page'] = 1;
  103.         }
  104.         return $this->render($template, [
  105.             'blocs'  => $blocs,
  106.             'page'   =>   $pageRepository->getAllQb($language,$paramsPage)->getOneOrNullResult(),
  107.             'medias' => $medias,
  108.             'paletteColors' =>$colorPage,
  109.             'form' => $form->createView(),
  110.            
  111.         ]);
  112.      
  113.     }
  114. }