<?php
namespace App\Controller;
use App\Entity\BFFestival;
use App\Entity\BFEdition;
use App\Entity\BFDescription;
use App\Entity\BFMailTournoi;
use App\Entity\BFChallenge;
use App\Entity\BFChallengeEdition;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use App\Form\Type\BFEditionType;
use App\Form\Type\BFDescriptionEditionImagesType;
use App\Form\Type\BFMailTournoiType;
class BFEditionController extends AbstractController
{
/**
* @Route("edition-{id}/delete", name="bfedition_delete")
*/
public function DeleteEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$edition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($id);
$festival=$edition->getFestival();
$this->denyAccessUnlessGranted('delete', $festival);
$festivalid = $edition->getFestival()->getId();
if($edition!=null)
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($edition);
$entityManager->flush();
$this->addFlash('secondary', 'L\'édition est supprimée');
return $this->redirectToRoute('admin_festival',[
'id'=>$festivalid,
]);
}
return $this->redirectToRoute('admin');
}
/**
* @Route("edition-{id}/unactive", name="bfedition_unactive")
*/
public function UnactiveEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
return $this->ChangeActiveEdition($id, false, false, $request);
}
/**
* @Route("edition-{id}/active", name="bfedition_active")
*/
public function ActiveEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
return $this->ChangeActiveEdition($id, true, false, $request);
}
/**
* @Route("edition-{idedition}/challengedition-{idchallengeedition}", name="bfedition_unlinkchallengeedition")
*/
public function UnlinkChallengEdition(int $idedition, int $idchallengeedition)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$edition=$this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
if($edition==null)
throw $this->createNotFoundException();
$this->denyAccessUnlessGranted('delete', $edition->getFestival());
$challengeedition=$this->getDoctrine()->getRepository(BFChallengeEdition::class)->find($idchallengeedition);
if($challengeedition==null)
throw $this->createNotFoundException();
$edition->removeChallengeedition($challengeedition);
$em=$this->getDoctrine()->getManager();
$em->persist($edition);
$em->flush();
$this->addFlash('secondary', 'L\'édition a été dissociée de l\'édition du challenge');
return $this->redirectToRoute('admin_festival',[
'id'=>$edition->getFestival()->getId(),
]);
}
public function ChangeActiveEdition(int $id, bool $isactive, bool $fromadmin, Request $request)
{
$edition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($id);
$festival=$edition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
//check option for activate more editions at the same time
$activecount = $festival->getCountActive();
if($activecount>0 && $isactive==true )
{
//because we try to add one
$activecount++;
if(!$this->isGranted('option_editionactive_'.$activecount,$festival))
{
$this->addFlash('danger', 'Vous ne pouvez pas activer plus d\'éditions, consultez les offres');
if($fromadmin==true)
{
return $this->redirectToRoute('admin_edition',[
'id' => $edition->getFestival()->getId(),
'idedition'=>$edition->getId(),
]);
}
else
{
return $this->redirectToRoute('admin_festival',[
'id'=>$edition->getFestival()->getId(),
]);
}
}
}
if($edition!=null)
{
$edition->setIsactive($isactive);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
if($isactive)
{
$this->addFlash('success', 'L\'édition a été activée');
}
else
{
$this->addFlash('warning', 'L\'édition a été archivée');
}
}
if($fromadmin==true)
{
return $this->redirectToRoute('admin_edition',[
'id' => $edition->getFestival()->getId(),
'idedition'=>$edition->getId(),
]);
}
else
{
return $this->redirectToRoute('admin_festival',[
'id'=>$edition->getFestival()->getId(),
]);
}
}
public function ShowBFEditionsTable(int $activefestivalid)
{
$festival = $this->getDoctrine()
->getRepository(BFFestival::class)
->find($activefestivalid);
$this->denyAccessUnlessGranted('edit', $festival);
$editions = $festival->getEditions();
$activeeditions = array();
foreach ($editions as $edition )
{
if($edition->getIsactive()==true)
{
array_push($activeeditions, $edition);
}
}
return $this->render('editions/admineditionstable.html.twig', [
'bfeditions' => $activeeditions,
'bffestival' => $festival,
]);
}
public function ShowUnactiveBFEditionsTable(int $activefestivalid)
{
$festival = $this->getDoctrine()
->getRepository(BFFestival::class)
->find($activefestivalid);
$this->denyAccessUnlessGranted('edit', $festival);
$editions = $festival->getEditions();
$unactiveeditions = array();
foreach ($editions as $edition)
{
if($edition->getIsactive()==false)
{
array_push($unactiveeditions, $edition);
}
}
return $this->render('editions/adminedtitionstableunactive.html.twig', [
'bfeditions' => $unactiveeditions,
'bffestival' => $festival,
]);
}
public function ShowBreadcrumb(int $id, $iscreate=false)
{
if($iscreate)
{
$bffestival=$this->getDoctrine()
->getRepository(BFFestival::class)
->find($id);
$bfedition= new BFEdition();
}
else
{
$bfedition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($id);
$bffestival= $bfedition->getFestival();
}
return $this->render('breadcrumb/editionbreadcrumb.html.twig', [
'bfedition' => $bfedition,
'bffestival' => $bffestival,
'iscreate' => $iscreate,
]);
}
public function ShowActiveButton(int $id)
{
$bfedition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($id);
return $this->render('editions/admineditionactivationbutton.html.twig', [
'bfedition' => $bfedition,
]);
}
public function ShowSmallView(int $id)
{
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
if($bfedition==null) return null;
$festival=$bfedition->getFestival();
if($this->isGranted('option_uniqueurl_festival', $festival) && $festival->getRoute()!=null)
{
$route=$festival->getRoute()->getRoute();
}
else if ($this->isGranted('option_uniqueurl_edition', $bfedition) && $bfedition->getRoute()!=null)
{
$route=$bfedition->getRoute()->getRoute();
}
else
{
$route="edition/".$id;
}
return $this->render('editions/editionsmallview.html.twig', [
'bfedition' => $bfedition,
'bfeditionroute' => $route,
]);
}
public function ShowListView(int $id)
{
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
if($bfedition==null) return null;
$festival=$bfedition->getFestival();
if($this->isGranted('option_uniqueurl_festival', $festival) && $festival->getRoute()!=null)
{
$route=$festival->getRoute()->getRoute();
}
else if ($this->isGranted('option_uniqueurl_edition', $bfedition) && $bfedition->getRoute()!=null)
{
$route=$bfedition->getRoute()->getRoute();
}
else
{
$route="edition/".$id;
}
return $this->render('editions/editionlistview.html.twig', [
'bfedition' => $bfedition,
'bfeditionroute' => $route,
]);
}
public function ShowListViewInactive(int $id)
{
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
if($bfedition==null) return null;
$festival=$bfedition->getFestival();
return $this->render('editions/editionlistviewinactive.html.twig', [
'bfedition' => $bfedition,
]);
}
public function ShowAdminInscriptions(int $id)
{
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($id);
if($bfedition==null) return null;
return $this->render('editions/admineditioninscriptionsview.html.twig', [
'bfedition' => $bfedition,
]);
}
}
?>