src/Controller/BFChallengeEditionController.php line 266

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\BFChallenge;
  4. use App\Entity\BFChallengeEdition;
  5. use App\Entity\BFFestival;
  6. use App\Entity\BFEdition;
  7. use App\Entity\BFDescription;
  8. use App\Entity\BFMailTournoi;
  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 BFChallengeEditionController extends AbstractController
  17. {
  18.     /**
  19.     * @Route("challenge/edition-{id}/delete", name="bfchallengeedition_delete")
  20.     */
  21.     public function DeleteEdition(int $idRequest $request)
  22.     {
  23.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  24.         
  25.         $edition $this->getDoctrine()
  26.             ->getRepository(BFChallengeEdition::class)
  27.             ->find($id);
  28.         
  29.         $challenge=$edition->getChallenge();
  30.         $this->denyAccessUnlessGranted('delete'$challenge);
  31.         
  32.         $challengeid $edition->getChallenge()->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 du challenge est supprimée');
  41.             return $this->redirectToRoute('admin_challenge',[
  42.                 'idchallenge'=>$challengeid,
  43.             ]);
  44.         }
  45.         
  46.        return $this->redirectToRoute('admin');
  47.     }
  48.     
  49.     /**
  50.     * @Route("challenge/edition-{id}/unactive", name="bfchallengeedition_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("challenge/edition-{id}/active", name="bfchallengeedition_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.     public function ChangeActiveEdition(int $idbool $isactivebool $fromadminRequest $request)
  70.     {
  71.         $edition $this->getDoctrine()
  72.             ->getRepository(BFChallengeEdition::class)
  73.             ->find($id);
  74.         
  75.         $challenge=$edition->getChallenge();
  76.         $this->denyAccessUnlessGranted('edit'$challenge);
  77.         
  78.         //check option for activate more editions at the same time => there is no restriction on challenges
  79.         $activecount $challenge->getCountActive();
  80.         if($activecount>&& $isactive==true )
  81.         {
  82.             //because we try to add one
  83.             $activecount++;
  84.             if(!$this->isGranted('option_editionactive_challenge_'.$activecount,$challenge))
  85.             {
  86.                 $this->addFlash('danger''Vous ne pouvez pas activer plus d\'éditions, consultez les offres');
  87.                 
  88.                 if($fromadmin==true)
  89.                 {
  90.                     return $this->redirectToRoute('admin_challenge_edition',[
  91.                         'idedition'=>$edition->getId(),
  92.                     ]);
  93.                 }
  94.                 else
  95.                 {
  96.                      return $this->redirectToRoute('admin_challenge',[
  97.                     'idchallenge'=>$challenge->getId(),
  98.                     ]);
  99.                 }
  100.             }
  101.         }
  102.         
  103.         if($edition!=null)
  104.         {
  105.             $edition->setIsactive($isactive);
  106.             $entityManager $this->getDoctrine()->getManager();
  107.             $entityManager->persist($edition);
  108.             $entityManager->flush();
  109.             
  110.             if($isactive)
  111.             {
  112.                 $this->addFlash('success''L\'édition a été activée');
  113.             }
  114.             else
  115.             {
  116.                 $this->addFlash('warning''L\'édition a été archivée');
  117.             }
  118.         }
  119.         
  120.         return $this->redirectToRoute('admin_challenge',[
  121.         'idchallenge'=>$challenge->getId(),
  122.         ]);
  123.     }
  124.     
  125.     
  126.     public function ShowBFChallengeEditionsTable(int $challengeid)
  127.     {
  128.         $challenge $this->getDoctrine()
  129.             ->getRepository(BFChallenge::class)
  130.             ->find($challengeid);
  131.         
  132.         $this->denyAccessUnlessGranted('edit'$challenge);
  133.         
  134.         $editions $challenge->getEditions();
  135.         
  136.         $activeeditions = array();
  137.         
  138.         foreach ($editions as $edition )
  139.         {
  140.             if($edition->getIsactive()==true)
  141.             {
  142.                 array_push($activeeditions$edition);
  143.             }
  144.         }
  145.         
  146.         return $this->render('challenges/adminchallengeeditionstable.html.twig', [
  147.             'bfchallengeeditions' => $activeeditions,
  148.             'bfchallenge' => $challenge,
  149.         ]);
  150.     }
  151.     
  152.     public function ShowBFChallengeEditionsHome()
  153.     {
  154.         $challengeeditions = array();
  155.         //If user, we get the subscriptions
  156.         
  157.         if($this->isGranted('IS_AUTHENTICATED_FULLY'))
  158.         {
  159.             $user $this->getUser();
  160.             
  161.             $challengesubscriptions $this->getDoctrine()->getRepository(BFChallengeEdition::class)->findNearestSubscriptions($user$isactive=true6);
  162.             
  163.             if(count($challengesubscriptions)>0)
  164.                 $challengeeditions=array_merge($challengeeditions,$challengesubscriptions);
  165.             
  166.         }
  167.         
  168.         if(count($challengeeditions)<6)
  169.         {
  170.             $nearestchallengeedition $this->getDoctrine()->getRepository(BFChallengeEdition::class)->findNearestIsactive(true6-count($challengeeditions));
  171.             
  172.             $challengeeditions=array_merge($challengeeditions,$nearestchallengeedition);
  173.         }
  174.         
  175.         //Be sure that there is only 6
  176.         //$challengeeditionssix = array_slice($challengeeditions,0,6);
  177.         
  178.         return $this->render('challenges/homechallengestrending.html.twig', [
  179.             'bfchallengeeditions' => $challengeeditions,
  180.         ]);
  181.     }
  182.     
  183.     public function ShowBFChallengEdtionImageCard(int $idchallengeedition)
  184.     {
  185.         $bfchallengeedition $this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($idchallengeedition);
  186.         
  187.         if($bfchallengeedition==null)
  188.             throw $this->createNotFoundException();
  189.         
  190.         return $this->render('challenges/challengeeditionimagecard.html.twig', [
  191.             'bfchallengeedition' => $bfchallengeedition,
  192.         ]);
  193.     }
  194.     
  195.     public function ShowUnactiveBFEditionsTable(int $challengeid)
  196.     {
  197.         $challenge $this->getDoctrine()
  198.             ->getRepository(BFChallenge::class)
  199.             ->find($challengeid);
  200.         
  201.         $this->denyAccessUnlessGranted('edit'$challenge);
  202.         
  203.         $editions $challenge->getEditions();
  204.         
  205.         $activeeditions = array();
  206.         
  207.         foreach ($editions as $edition )
  208.         {
  209.             if($edition->getIsactive()==false)
  210.             {
  211.                 array_push($activeeditions$edition);
  212.             }
  213.         }
  214.         
  215.         return $this->render('challenges/adminchallengeeditionstableunactive.html.twig', [
  216.             'bfchallengeeditions' => $activeeditions,
  217.             'bfchallenge' => $challenge,
  218.         ]);
  219.     }
  220.     
  221.     public function ShowBreadcrumb(int $id$iscreate=false)
  222.     {
  223.         if($iscreate)
  224.         {
  225.             $bfchallenge=$this->getDoctrine()
  226.                 ->getRepository(BFChallenge::class)
  227.                 ->find($id);
  228.             $bfedition= new BFChallengeEdition();
  229.         }
  230.         else
  231.         {
  232.             $bfedition $this->getDoctrine()
  233.                 ->getRepository(BFChallengeEdition::class)
  234.                 ->find($id);
  235.             $bfchallenge$bfedition->getChallenge();
  236.         }
  237.         
  238.         return $this->render('breadcrumb/challengeeditionbreadcrumb.html.twig', [
  239.             'bfchallengeedition' => $bfedition,
  240.             'bfchallenge' => $bfchallenge,
  241.             'iscreate' => $iscreate,
  242.         ]);
  243.     }
  244.     
  245.     public function ShowActiveButton(int $id)
  246.     {
  247.         $bfchallengeedition $this->getDoctrine()
  248.             ->getRepository(BFChallengeEdition::class)
  249.             ->find($id);
  250.         
  251.         return $this->render('challenges/adminchallengeeditionactivationbutton.html.twig', [
  252.             'bfchallengeedition' => $bfchallengeedition,
  253.         ]);
  254.     }
  255.     
  256.     public function ShowSmallView(int $id)
  257.     {
  258.         $bfchallengeedition $this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($id);
  259.         
  260.         if($bfchallengeedition==null) return null;
  261.         
  262.         return $this->render('challenges/challengeeditionsmallview.html.twig', [
  263.             'bfchallengeedition' => $bfchallengeedition,
  264.         ]);
  265.         
  266.     }
  267. }
  268. ?>