src/Controller/PublicController.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AdminMaintenance;
  4. use App\Entity\Menu;
  5. use App\Entity\MenuFooter;
  6. use App\Entity\MenuHeader;
  7. use App\Entity\Pages;
  8. use App\Entity\PagesContent;
  9. use App\Entity\SectionsAccueil;
  10. use App\Entity\SectionsFooter;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\Asset\PathPackage;
  15. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Mailer\MailerInterface;
  18. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Security\Core\Security;
  23. use Symfony\Component\Asset\Packages;
  24. class PublicController extends AbstractController
  25. {
  26.     private UrlGeneratorInterface $urlGenerator;
  27.     public function __construct(UserPasswordHasherInterface $passwordHasherUrlGeneratorInterface $urlGeneratorManagerRegistry $doctrineSecurity $security,Packages $packages)
  28.     {
  29.         $this->passwordHasher $passwordHasher;
  30.         $this->urlGenerator $urlGenerator;
  31.         $this->doctrine $doctrine;
  32.         $this->security $security;
  33.         $this->packages $packages;
  34.     }
  35.     /**
  36.      * @Route("/{url}/{forEdit}", name="publicPages", defaults={"url":"Maintenance-en-systemes-de-securite-incendie-Formation","forEdit":false})
  37.      */
  38.     public function publicPages(Request $request,$url,$forEdit// ULR !!!!!
  39.     {
  40.         //Variables
  41.         $template 'public/pages/blog.html.twig';
  42.         //On recherche la page
  43.         $PagesEntity $this->doctrine->getManager()->getRepository(Pages::class)->findOneBy(array('url'=>$url'actif'=>1));
  44.         //Par defaut on redirige vers la page d'accueil => pas ouf comme technique
  45.         if(!$PagesEntity || $PagesEntity->getId() == 7) {
  46.             $PagesEntity $this->doctrine->getManager()->getRepository(Pages::class)->findOneBy(array('id'=>7));
  47.             //SEO
  48.             $seoFull = array(
  49.                 'seotitre' => $PagesEntity->getSeotitre(),
  50.                 'seometa' => $PagesEntity->getSeometa()
  51.             );
  52.             //Choix du content
  53.             $PagesContentEntity $this->doctrine->getManager()->getRepository(PagesContent::class)->findOneBy(array('pages'=>$PagesEntity'actif'=>1));
  54.             //Variables
  55.             $template 'public/pages/frontPage.html.twig';
  56.             $sectionsAccueilEntity $this->doctrine->getManager()->getRepository(SectionsAccueil::class)->findBy([],['ordre'=>'ASC']);
  57.             //roue des services
  58.             $arrayServices = [];
  59.             $roueServicesEntity $this->doctrine->getManager()->getRepository(SectionsAccueil::class)->findOneBy(['id'=>2]);
  60.             foreach($roueServicesEntity->getSectionsAccueilItem() as $services){
  61.                 $singleServices = [
  62.                     'titre' => $services->getNom(),
  63.                     'text' => $services->getText(),
  64.                     'lien' => $services->getLien(),
  65.                     'image' => $this->packages->getUrl($services->getImg1()),
  66.                     'imageSVG' => $this->packages->getUrl($services->getImg2()),
  67.                 ];
  68.                 $arrayServices[] = $singleServices;
  69.             }
  70.             foreach($roueServicesEntity->getSectionsAccueilItem() as $services){
  71.                 $singleServices = [
  72.                     'titre' => $services->getNom(),
  73.                     'text' => $services->getText(),
  74.                     'lien' => $services->getLien(),
  75.                     'image' => $this->packages->getUrl($services->getImg1()),
  76.                     'imageSVG' => $this->packages->getUrl($services->getImg2()),
  77.                 ];
  78.                 $arrayServices[] = $singleServices;
  79.             }
  80.             //Sinon c'est la vue classique
  81.             return $this->render($template, [
  82.                 'seo' => $seoFull,
  83.                 'pageInfo' => $PagesEntity,
  84.                 'PagesContentEntity' => $PagesContentEntity,
  85.                 'sectionsAccueilEntity' => $sectionsAccueilEntity,
  86.                 'itemsdivWheelnav' => $arrayServices,
  87.             ]);
  88.         }
  89.         if($PagesEntity) {
  90.             //SEO
  91.             $seoFull = array(
  92.                 'seotitre' => $PagesEntity->getSeotitre(),
  93.                 'seometa' => $PagesEntity->getSeometa()
  94.             );
  95.             //Choix du content
  96.             $PagesContentEntity $this->doctrine->getManager()->getRepository(PagesContent::class)->findOneBy(array('pages'=>$PagesEntity'actif'=>1));
  97.             //ATTENTION ICI !
  98.             $user $this->security->getUser();
  99.             //Si super Admin OU propriétaire de la page on redirige vers l'éditeur
  100.             if( $forEdit === 'true' && ($PagesEntity->getUser() === $user || $this->isGranted('ROLE_SUPER_ADMIN')) )
  101.             {
  102.                 $template 'public/pages/blogEditor.html.twig';
  103.             }
  104.             //Sinon c'est la vue classique
  105.             return $this->render($template, [
  106.                 'seo' => $seoFull,
  107.                 'pageInfo' => $PagesEntity,
  108.                 'PagesContentEntity' => $PagesContentEntity
  109.             ]);
  110.         }
  111.         $this->addFlash('warning'"Cette page n'existe pas...");
  112.         return $this->redirectToRoute('publicPages');
  113.     }
  114.   
  115.     //*************************************
  116.     //*************** RENDER **************
  117.     //*************************************
  118.     public function navHeaderRender() //Ok Gauthier
  119.     {
  120.         //On appel le menu
  121.         $menus $this->doctrine->getManager()->getRepository(MenuHeader::class)->findAll();
  122.         //On formate le menu pour qu'il soit exploitable
  123.         $returnMenuArray = [];
  124.         foreach ($menus as $menu) {
  125.             $arrayTemp = [
  126.                 'nom' => $menu->getNom(),
  127.                 'urlname' => $menu->getUrlname(),
  128.                 'id' => $menu->getPage()->getId(),
  129.                 'child' => []
  130.             ];
  131.             //Suivant le niveau on classe le tableau
  132.             switch($menu->getNiveau()) {
  133.                 case 0:
  134.                     $returnMenuArray[$menu->getId()] = $arrayTemp;
  135.                     break;
  136.                 case 1:
  137.                     $returnMenuArray[$menu->getParent()]['child'][$menu->getId()] = $arrayTemp;
  138.                     break;
  139.                 case 2:
  140.                     $returnMenuArray[$menu->getMenuparent()]['child'][$menu->getParent()]['child'][$menu->getId()] = $arrayTemp;
  141.                     break;
  142.             }
  143.         }
  144.         return $this->render('public/nav/nav.html.twig', [
  145.             'returnMenuArray' => $returnMenuArray
  146.         ]);
  147.     }
  148.     public function navFooterRender() //Ok Gauthier
  149.     {
  150.         //On appel le menu
  151.         $menus $this->doctrine->getManager()->getRepository(MenuFooter::class)->findAll();
  152.         //On formate le menu pour qu'il soit exploitable
  153.         $returnMenuArray = [];
  154.         foreach ($menus as $menu) {
  155.             $arrayTemp = [
  156.                 'nom' => $menu->getNom(),
  157.                 'urlname' => $menu->getUrlname(),
  158.                 'id' => $menu->getPage()->getId(),
  159.                 'child' => []
  160.             ];
  161.             //Suivant le niveau on classe le tableau
  162.             switch($menu->getNiveau()) {
  163.                 case 0:
  164.                     $returnMenuArray[$menu->getId()] = $arrayTemp;
  165.                     break;
  166.                 case 1:
  167.                     $returnMenuArray[$menu->getParent()]['child'][$menu->getId()] = $arrayTemp;
  168.                     break;
  169.                 case 2:
  170.                     $returnMenuArray[$menu->getMenuparent()]['child'][$menu->getParent()]['child'][$menu->getId()] = $arrayTemp;
  171.                     break;
  172.             }
  173.         }
  174.         return $this->render('public/nav/navFooter.html.twig', [
  175.             'returnMenuArray' => $returnMenuArray
  176.         ]);
  177.     }
  178.     public function navPreFooterRender() //Ok Gauthier
  179.     {
  180.         //On appel le footerSection
  181.         $SectionsFooter $this->doctrine->getManager()->getRepository(SectionsFooter::class)->findOneBy(['id'=>1]);
  182.         return $this->render('public/nav/preFooter.html.twig', [
  183.             'SectionsFooter' => $SectionsFooter
  184.         ]);
  185.     }
  186. }