src/Controller/HomePagesController.php line 88

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\CBRCArticle;
  4. use App\Entity\CBRCArticleCategory;
  5. use App\Entity\CBRCPageContent;
  6. use App\Entity\CBRCPageContentUpdate;
  7. use App\Entity\CBRCUser;
  8. use App\Form\Type\CBRCUserDescriptionType;
  9. use App\Form\Type\CBRCUserType;
  10. use App\Form\Type\ContactType;
  11. use App\Form\Type\ModifyEmailType;
  12. use App\Form\Type\ModifyPasswordType;
  13. use App\Form\Type\PageContentType;
  14. use Knp\Component\Pager\PaginatorInterface;
  15. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  19. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  20. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  21. use Symfony\Component\HttpFoundation\Request;
  22. class HomePagesController extends AbstractController
  23. {
  24.     /**
  25.      * @Route ("/admin/pagecontent/{pagename}", name="admin_pagecontent")
  26.      */
  27.     public function ShowAdminPageContent(string $pagenameRequest $request)
  28.     {
  29.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  30.         $user=$this->getUser();
  31.         $pagecontent $this->GetOrCreatePageContent("$pagename");
  32.         $newpagecontentupdate = new CBRCPageContentUpdate();
  33.         $newpagecontentupdate->setUser($user);
  34.         $newpagecontentupdate->setPage($pagecontent);
  35.         $newpagecontentupdate->setContent($pagecontent->getContent());
  36.         $formcontent $this->createForm(PageContentType::class, $newpagecontentupdate);
  37.         $formcontent->handleRequest($request);
  38.         if($formcontent->isSubmitted() && $formcontent->isValid())
  39.         {
  40.             $pagecontent->setContent($newpagecontentupdate->getContent());
  41.             $em=$this->getDoctrine()->getManager();
  42.             $em->persist($pagecontent);
  43.             $em->persist($newpagecontentupdate);
  44.             $em->flush();
  45.             return $this->redirectToRoute('home_'.$pagename);
  46.         }
  47.         if ($formcontent->isSubmitted() && !$formcontent->isValid()) {
  48.             foreach ($formcontent->getErrors(true) as $error)
  49.                 $this->addFlash('danger'"(" $error->getOrigin()->getName() . ") " $error->getMessage());
  50.             $formcontent->clearErrors(true);
  51.         }
  52.         return $this->render('adminpagecontent.html.twig', [
  53.             'formpagecontent' =>$formcontent->createView(),
  54.             'pagename' => $pagename,
  55.         ]);
  56.     }
  57.     /**
  58.      * @Route ("/tournois", name="home_tournois")
  59.      */
  60.     public function ShowTournois(Request $request)
  61.     {
  62.         $pagecontent $this->GetOrCreatePageContent('tournois');
  63.         return $this->render('hometournois.html.twig',[
  64.             'pagecontent' => $pagecontent,
  65.         ]);
  66.     }
  67.     /**
  68.      * @Route ("/cours", name="home_cours")
  69.      */
  70.     public function ShowCours(Request $request)
  71.     {
  72.         $pagecontent $this->GetOrCreatePageContent('cours');
  73.         return $this->render('homecours.html.twig',[
  74.             'pagecontent' => $pagecontent,
  75.         ]);
  76.     }
  77.     /**
  78.      * @Route ("/competitions", name="home_competitions")
  79.      */
  80.     public function ShowCompetitions(Request $request)
  81.     {
  82.         $pagecontent $this->GetOrCreatePageContent('competitions');
  83.         return $this->render('homecomitecalendar.html.twig',[
  84.             'pagecontent' => $pagecontent,
  85.         ]);
  86.     }
  87.     /**
  88.      * @Route ("/utilitiares", name="home_utilitaires")
  89.      */
  90.     public function ShowUtilitiares(Request $request)
  91.     {
  92.         $pagecontent $this->GetOrCreatePageContent('utilitaires');
  93.         return $this->render('homeutilitaires.html.twig',[
  94.             'pagecontent' => $pagecontent,
  95.         ]);
  96.     }
  97.     /**
  98.      * @Route ("/partenaires", name="home_partenaires")
  99.      */
  100.     public function ShowPartenaires(Request $request)
  101.     {
  102.         $pagecontent $this->GetOrCreatePageContent('partenaires');
  103.         return $this->render('homepartenaires.html.twig',[
  104.             'pagecontent' => $pagecontent,
  105.         ]);
  106.     }
  107.     /**
  108.      * @Route ("/festival", name="home_festival")
  109.      */
  110.     public function ShowFestival(Request $request)
  111.     {
  112.         $pagecontent $this->GetOrCreatePageContent('festival');
  113.         return $this->render('homefestival.html.twig',[
  114.             'pagecontent' => $pagecontent,
  115.         ]);
  116.     }
  117.     private function GetOrCreatePageContent(string $name)
  118.     {
  119.         $pagecontent $this->getDoctrine()->getRepository(CBRCPageContent::class)->findOneBy(['name'=>$name]);
  120.         if(!$pagecontent)
  121.         {
  122.             //create the page
  123.             $pagecontent = new CBRCPageContent();
  124.             $pagecontent->setName($name);
  125.             //persist the page
  126.             $em $this->getDoctrine()->getManager();
  127.             $em->persist($pagecontent);
  128.             $em->flush();
  129.         }
  130.         return $pagecontent;
  131.     }
  132. }