src/Controller/BFEditionController.php line 321

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\BFFestival;
  4. use App\Entity\BFEdition;
  5. use App\Entity\BFDescription;
  6. use App\Entity\BFMailTournoi;
  7. use App\Entity\BFChallenge;
  8. use App\Entity\BFChallengeEdition;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use App\Form\Type\BFEditionType;
  14. use App\Form\Type\BFDescriptionEditionImagesType;
  15. use App\Form\Type\BFMailTournoiType;
  16. class BFEditionController extends AbstractController
  17. {
  18.     /**
  19.     * @Route("edition-{id}/delete", name="bfedition_delete")
  20.     */
  21.     public function DeleteEdition(int $idRequest $request)
  22.     {
  23.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  24.         
  25.         $edition $this->getDoctrine()
  26.             ->getRepository(BFEdition::class)
  27.             ->find($id);
  28.         
  29.         $festival=$edition->getFestival();
  30.         $this->denyAccessUnlessGranted('delete'$festival);
  31.         
  32.         $festivalid $edition->getFestival()->getId();
  33.         
  34.         if($edition!=null)
  35.         {
  36.             $entityManager $this->getDoctrine()->getManager();
  37.             $entityManager->remove($edition);
  38.             $entityManager->flush();
  39.             
  40.             $this->addFlash('secondary''L\'édition est supprimée');
  41.             return $this->redirectToRoute('admin_festival',[
  42.                 'id'=>$festivalid,
  43.             ]);
  44.         }
  45.         
  46.        return $this->redirectToRoute('admin');
  47.     }
  48.     
  49.     /**
  50.     * @Route("edition-{id}/unactive", name="bfedition_unactive")
  51.     */
  52.     public function UnactiveEdition(int $idRequest $request)
  53.     {
  54.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  55.         
  56.         return $this->ChangeActiveEdition($idfalsefalse$request);
  57.     }
  58.     
  59.     /**
  60.     * @Route("edition-{id}/active", name="bfedition_active")
  61.     */
  62.     public function ActiveEdition(int $idRequest $request)
  63.     {
  64.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  65.         
  66.         return $this->ChangeActiveEdition($idtruefalse$request);
  67.     }
  68.     
  69.     /**
  70.     * @Route("edition-{idedition}/challengedition-{idchallengeedition}", name="bfedition_unlinkchallengeedition")
  71.     */
  72.     public function UnlinkChallengEdition(int $ideditionint $idchallengeedition)
  73.     {
  74.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  75.         
  76.         $edition=$this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
  77.         
  78.         if($edition==null)
  79.             throw $this->createNotFoundException();
  80.         
  81.         $this->denyAccessUnlessGranted('delete'$edition->getFestival());
  82.         
  83.         $challengeedition=$this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($idchallengeedition);
  84.         
  85.         if($challengeedition==null)
  86.             throw $this->createNotFoundException();
  87.         
  88.         $edition->removeChallengeedition($challengeedition);
  89.         $em=$this->getDoctrine()->getManager();
  90.         $em->persist($edition);
  91.         $em->flush();
  92.         
  93.         $this->addFlash('secondary''L\'édition a été dissociée de l\'édition du challenge');
  94.         
  95.         return $this->redirectToRoute('admin_festival',[
  96.             'id'=>$edition->getFestival()->getId(),
  97.             ]);
  98.         
  99.         
  100.     }
  101.     
  102.     public function ChangeActiveEdition(int $idbool $isactivebool $fromadminRequest $request)
  103.     {
  104.         $edition $this->getDoctrine()
  105.             ->getRepository(BFEdition::class)
  106.             ->find($id);
  107.         
  108.         $festival=$edition->getFestival();
  109.         $this->denyAccessUnlessGranted('edit'$festival);
  110.         
  111.         //check option for activate more editions at the same time
  112.         $activecount $festival->getCountActive();
  113.         if($activecount>&& $isactive==true )
  114.         {
  115.             //because we try to add one
  116.             $activecount++;
  117.             if(!$this->isGranted('option_editionactive_'.$activecount,$festival))
  118.             {
  119.                 $this->addFlash('danger''Vous ne pouvez pas activer plus d\'éditions, consultez les offres');
  120.                 
  121.                 if($fromadmin==true)
  122.                 {
  123.                     return $this->redirectToRoute('admin_edition',[
  124.                         'id' => $edition->getFestival()->getId(),
  125.                         'idedition'=>$edition->getId(),
  126.                     ]);
  127.                 }
  128.                 else
  129.                 {
  130.                      return $this->redirectToRoute('admin_festival',[
  131.                     'id'=>$edition->getFestival()->getId(),
  132.                     ]);
  133.                 }
  134.             }
  135.         }
  136.         
  137.         if($edition!=null)
  138.         {
  139.             $edition->setIsactive($isactive);
  140.             $entityManager $this->getDoctrine()->getManager();
  141.             $entityManager->persist($edition);
  142.             $entityManager->flush();
  143.             
  144.             if($isactive)
  145.             {
  146.                 $this->addFlash('success''L\'édition a été activée');
  147.             }
  148.             else
  149.             {
  150.                 $this->addFlash('warning''L\'édition a été archivée');
  151.             }
  152.         }
  153.         
  154.        if($fromadmin==true)
  155.         {
  156.             return $this->redirectToRoute('admin_edition',[
  157.                 'id' => $edition->getFestival()->getId(),
  158.                 'idedition'=>$edition->getId(),
  159.             ]);
  160.         }
  161.         else
  162.         {
  163.              return $this->redirectToRoute('admin_festival',[
  164.             'id'=>$edition->getFestival()->getId(),
  165.             ]);
  166.         }
  167.     }
  168.     
  169.     public function ShowBFEditionsTable(int $activefestivalid)
  170.     {
  171.         $festival $this->getDoctrine()
  172.             ->getRepository(BFFestival::class)
  173.             ->find($activefestivalid);
  174.         
  175.         $this->denyAccessUnlessGranted('edit'$festival);
  176.         
  177.         $editions $festival->getEditions();
  178.         
  179.         $activeeditions = array();
  180.         
  181.         foreach ($editions as $edition )
  182.         {
  183.             if($edition->getIsactive()==true)
  184.             {
  185.                 array_push($activeeditions$edition);
  186.             }
  187.         }
  188.         
  189.         return $this->render('editions/admineditionstable.html.twig', [
  190.             'bfeditions' => $activeeditions,
  191.             'bffestival' => $festival,
  192.         ]);
  193.     }
  194.     
  195.     public function ShowUnactiveBFEditionsTable(int $activefestivalid)
  196.     {
  197.         $festival $this->getDoctrine()
  198.             ->getRepository(BFFestival::class)
  199.             ->find($activefestivalid);
  200.         
  201.         $this->denyAccessUnlessGranted('edit'$festival);
  202.         
  203.         $editions $festival->getEditions();
  204.         
  205.         $unactiveeditions = array();
  206.         
  207.         foreach ($editions as  $edition)
  208.         {
  209.             if($edition->getIsactive()==false)
  210.             {
  211.                 array_push($unactiveeditions$edition);
  212.             }
  213.         }
  214.         
  215.         return $this->render('editions/adminedtitionstableunactive.html.twig', [
  216.             'bfeditions' => $unactiveeditions,
  217.             'bffestival' => $festival,
  218.         ]);
  219.     }
  220.     
  221.     public function ShowBreadcrumb(int $id$iscreate=false)
  222.     {
  223.         if($iscreate)
  224.         {
  225.             $bffestival=$this->getDoctrine()
  226.                 ->getRepository(BFFestival::class)
  227.                 ->find($id);
  228.             $bfedition= new BFEdition();
  229.         }
  230.         else
  231.         {
  232.             $bfedition $this->getDoctrine()
  233.                 ->getRepository(BFEdition::class)
  234.                 ->find($id);
  235.             $bffestival$bfedition->getFestival();
  236.         }
  237.         
  238.         return $this->render('breadcrumb/editionbreadcrumb.html.twig', [
  239.             'bfedition' => $bfedition,
  240.             'bffestival' => $bffestival,
  241.             'iscreate' => $iscreate,
  242.         ]);
  243.     }
  244.     
  245.     public function ShowActiveButton(int $id)
  246.     {
  247.         $bfedition $this->getDoctrine()
  248.             ->getRepository(BFEdition::class)
  249.             ->find($id);
  250.         
  251.         return $this->render('editions/admineditionactivationbutton.html.twig', [
  252.             'bfedition' => $bfedition,
  253.         ]);
  254.     }
  255.     
  256.     public function ShowSmallView(int $id)
  257.     {
  258.         $bfedition $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
  259.         
  260.         if($bfedition==null) return null;
  261.         
  262.         $festival=$bfedition->getFestival();
  263.         
  264.         if($this->isGranted('option_uniqueurl_festival'$festival) && $festival->getRoute()!=null)
  265.         {
  266.             $route=$festival->getRoute()->getRoute();
  267.         }
  268.         else if ($this->isGranted('option_uniqueurl_edition'$bfedition) && $bfedition->getRoute()!=null)
  269.         {
  270.             $route=$bfedition->getRoute()->getRoute();
  271.         }
  272.         else
  273.         {
  274.             $route="edition/".$id;
  275.         }
  276.         
  277.         return $this->render('editions/editionsmallview.html.twig', [
  278.             'bfedition' => $bfedition,
  279.             'bfeditionroute' => $route,
  280.         ]);
  281.         
  282.     }
  283.     
  284.     public function ShowListView(int $id)
  285.     {
  286.         $bfedition $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
  287.         
  288.         if($bfedition==null) return null;
  289.         
  290.         $festival=$bfedition->getFestival();
  291.         
  292.         if($this->isGranted('option_uniqueurl_festival'$festival) && $festival->getRoute()!=null)
  293.         {
  294.             $route=$festival->getRoute()->getRoute();
  295.         }
  296.         else if ($this->isGranted('option_uniqueurl_edition'$bfedition) && $bfedition->getRoute()!=null)
  297.         {
  298.             $route=$bfedition->getRoute()->getRoute();
  299.         }
  300.         else
  301.         {
  302.             $route="edition/".$id;
  303.         }
  304.         
  305.         
  306.         return $this->render('editions/editionlistview.html.twig', [
  307.             'bfedition' => $bfedition,
  308.             'bfeditionroute' => $route,
  309.         ]);
  310.         
  311.     }
  312.     
  313.     public function ShowListViewInactive(int $id)
  314.     {
  315.         $bfedition $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
  316.         
  317.         if($bfedition==null) return null;
  318.         
  319.         $festival=$bfedition->getFestival();
  320.         
  321.         return $this->render('editions/editionlistviewinactive.html.twig', [
  322.             'bfedition' => $bfedition,
  323.         ]);
  324.         
  325.     }
  326.     
  327.     public function ShowAdminInscriptions(int $id)
  328.     {
  329.         $bfedition $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
  330.         
  331.         if($bfedition==null) return null;
  332.         
  333.         return $this->render('editions/admineditioninscriptionsview.html.twig', [
  334.             'bfedition' => $bfedition,
  335.         ]);
  336.     }
  337. }
  338. ?>