<?php
namespace App\Controller;
use App\Form\Type\BFFestivalandEditionType;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\BFChallenge;
use App\Entity\BFChallengeEdition;
use App\Entity\BFFestival;
use App\Entity\BFEdition;
use App\Entity\BFTournoi;
use App\Entity\BFSeance;
use App\Entity\BFUser;
use App\Entity\BFResetPassword;
use App\Entity\BFAdminLicences;
use App\Entity\BFRouting;
use App\Entity\BFSubscription;
use App\Entity\BFMailChallenge;
use App\Entity\BFMailFestival;
use App\Entity\BFMailTournoi;
use App\Entity\BFProductEdition;
use App\Form\Type\BFChallengeType;
use App\Form\Type\BFChallengeEditionType;
use App\Form\Type\BFFestivalType;
use App\Form\Type\BFFestivalOwnerType;
use App\Form\Type\BFFestivalAdministratorAddType;
use App\Form\Type\BFFestivalAdministratorRemoveType;
use App\Form\Type\BFEditionType;
use App\Form\Type\BFTournoiType;
use App\Form\Type\BFTournoiWithTypeType;
use App\Form\Type\BFSeanceType;
use App\Form\Type\BFUserDescriptionType;
use App\Form\Type\BFDescriptionEditionImagesType;
use App\Form\Type\BFDescriptionFestivalType;
use App\Form\Type\BFDescriptionChallengeType;
use App\Form\Type\ModifyPasswordType;
use App\Form\Type\ModifyEmailType;
use App\Form\Type\AskPasswordType;
use App\Form\Type\RoutingType;
use App\Form\Type\BFMailFestivalType;
use App\Form\Type\BFMailTournoiType;
use App\Form\Type\BFChallengeAddFestivalType;
use App\Form\Type\BFProductEditionType;
use App\Form\Type\FestivalFeeType;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use App\Utilities\Mail;
use Stripe\Stripe;
use Stripe\StripeClient;
use Stripe\StripeAccount;
class AdminController extends AbstractController
{
/**
* @Route("/admin/festival-{id}", name="admin_festival")
*/
public function ShowAdminFestival(int $id,ValidatorInterface $validator, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$festival = $this->getDoctrine()
->getRepository(BFFestival::class)
->find($id);
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
//formdescrition
$formeditfestival = $this->createForm(BFFestivalType::class, $festival,[
'submit_label' => 'Editer',
]);
$formeditfestival->handleRequest($request);
if ($formeditfestival->isSubmitted() && $formeditfestival->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$festival = $formeditfestival->getData();
$errors = $validator->validate($festival);
if(count($errors)>0)
{
foreach($errors as $error)
{
$this->addFlash('danger', $error->toString());
}
}
else
{
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
}
return $this->redirect($request->getUri());
}
if($formeditfestival->isSubmitted() && !$formeditfestival->isValid())
{
foreach($formeditfestival->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formowner
$emailvalue = $festival->getOwner()!=null ? $festival->getOwner()->getEmail() : "";
$formfestivalowner = $this->createForm(BFFestivalOwnerType::class, null, [
'email_value' => $emailvalue ,
]);
$formfestivalowner->handleRequest($request);
if ($formfestivalowner->isSubmitted() && $formfestivalowner->isValid()) {
$this->denyAccessUnlessGranted('delete', $festival);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$email = $formfestivalowner->getData()['email'];
if($email==null)
{
$festival->setOwner(null);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('primary', 'Le propriétaire du festival a été modifié');
}
else
{
//getuser from email
$owneruser =$this->getDoctrine()
->getRepository(BFUser::class)
->findOneBy(['email'=>$email]);
if($owneruser!=null)
{
$festival->setOwner($owneruser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('primary', 'Le propriétaire du festival a été modifié');
}
else
{
$this->addFlash('danger', 'L\'adresse email est inconnue');
}
}
return $this->redirect($request->getUri());
}
if($formfestivalowner->isSubmitted() && !$formfestivalowner->isValid())
{
foreach($formfestivalowner->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formaddadministrator
$formfestivaladministratoradd = $this->createForm(BFFestivalAdministratorAddType::class, null, [
]);
$formfestivaladministratoradd->handleRequest($request);
if ($formfestivaladministratoradd->isSubmitted() && $formfestivaladministratoradd->isValid()) {
$this->denyAccessUnlessGranted('delete', $festival);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$email = $formfestivaladministratoradd->getData()['email'];
//getuser from email
$adminuser =$this->getDoctrine()
->getRepository(BFUser::class)
->findOneBy(['email'=>$email]);
if($adminuser!=null)
{
$festival->addAdministrator($adminuser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('primary', 'L\'administrateur a été ajouté');
return $this->redirect($request->getUri());
}
else
{
$this->addFlash('danger', 'L\'adresse email est inconnue');
}
}
if($formfestivaladministratoradd->isSubmitted() && !$formfestivaladministratoradd->isValid())
{
foreach($formfestivaladministratoradd->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formremoveadministrator
$formfestivaladministratorremove = $this->createForm(BFFestivalAdministratorRemoveType::class, null, ['festival'=>$festival]);
$formfestivaladministratorremove->handleRequest($request);
if ($formfestivaladministratorremove->isSubmitted() && $formfestivaladministratorremove->isValid()) {
$this->denyAccessUnlessGranted('delete', $festival);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$administratorid = $formfestivaladministratorremove->getData()['administratorstodelete'];
$adminuser=null;
if($administratorid!=null)
{
$adminuser =$this->getDoctrine()->getRepository(BFUser::class)->find($administratorid);
}
if($adminuser!=null)
{
$festival->removeAdministrator($adminuser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('primary', 'L\'administrateur a été envelé');
return $this->redirect($request->getUri());
}
}
if($formfestivaladministratorremove->isSubmitted() && !$formfestivaladministratorremove->isValid())
{
foreach($formfestivaladministratorremove->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formrouting
$bfrouting = $festival->getRoute();
if($bfrouting==null)
$bfrouting= new BFRouting();
$formrouting = $this->createForm(RoutingType::class, $bfrouting);
$formrouting->handleRequest($request);
if ($formrouting->isSubmitted() && $formrouting->isValid()) {
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
$this->denyAccessUnlessGranted('option_uniqueurl_festival', $festival);
$bfrouting = $formrouting->getData();
$entityManager = $this->getDoctrine()->getManager();
if($festival->getRoute()==null)
{
$festival->setRoute($bfrouting);
$entityManager->persist($bfrouting);
$entityManager->persist($festival);
}
else
{
$entityManager->persist($bfrouting);
}
$entityManager->flush();
$this->addFlash('primary', 'La route a été enregistrée');
return $this->redirect($request->getUri());
}
if($formrouting->isSubmitted() && !$formrouting->isValid())
{
foreach($formrouting->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//form orderfeebf
$formfeefestival = $this->createForm(FestivalFeeType::class, $festival,[
]);
$formfeefestival->handleRequest($request);
if ($formfeefestival->isSubmitted() && $formfeefestival->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$festival = $formfeefestival->getData();
$errors = $validator->validate($festival);
if(count($errors)>0)
{
foreach($errors as $error)
{
$this->addFlash('danger', $error->toString());
}
}
else
{
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($festival);
$entityManager->flush();
$this->addFlash('success', 'La commission a été changée');
}
return $this->redirect($request->getUri());
}
if($formeditfestival->isSubmitted() && !$formeditfestival->isValid())
{
foreach($formeditfestival->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//offers and option list
$bfadminlicences = $this->getDoctrine()->getRepository(BFAdminLicences::class)->findAllByFestival($festival);
return $this->render('adminfestival.html.twig', [
'userdescription' => $user->getDescription(),
'formbffestivaledit' => $formeditfestival->createView(),
'formbffestivalowner' => $formfestivalowner->createView(),
'formbffestivaladminadd' => $formfestivaladministratoradd->createView(),
'formbffestivaladminremove' => $formfestivaladministratorremove->createView(),
'formbffestivalorderfee' => $formfeefestival->createView(),
'formrouting' =>$formrouting->createView(),
'bffestival' => $festival,
'bfadminlicences' => $bfadminlicences,
'activefestivalid' => $id,
'stripeaccountvalid' => $this->isGranted('canpay', $festival),
]);
}
/**
* @Route("/admin/festival-{id}/subscriptions", name="admin_festival_subscriptions")
*/
public function ShowAdminFestivalSubscriptions(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$festival = $this->getDoctrine()
->getRepository(BFFestival::class)
->find($id);
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
//countsubscribers
$subscriptions = $this->getDoctrine()->getRepository(BFSubscription::class)->FindBy(['festival'=>$festival]);
//formsendmail
$bfmailfestival = new BFMailFestival();
$formsendmail = $this->createForm(BFMailFestivalType::class, $bfmailfestival);
$formsendmail->handleRequest($request);
if ($formsendmail->isSubmitted() && $formsendmail->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$bfmailfestival = $formsendmail->getData();
$bfmailfestival->setFestival($festival);
$bfmailfestival->setSubscribercount(count($subscriptions));
$bfmailfestival->setSenddate(new \DateTime('now'));
$em =$this->getDoctrine()->getManager();
$em->persist($bfmailfestival);
$em->flush();
$txtmessage = $bfmailfestival->getText();
$subject = $bfmailfestival->getSubject();
$sendedmail=0;
if($bfmailfestival->getIsadmin())
{
$admins = $festival->getAdministrators()->getValues();
$owner = $festival->getOwner();
if($owner!=null)
{
array_push($admins, $owner);
}
if(count($admins)==0)
{
$userrepository =$this->getDoctrine()->getRepository(BFUser::class);
array_push($admins, $userrepository->findByRole('ROLE_SUPER_ADMIN'));
}
$htmlmessage = $this->renderView('mail/festivalmail.html.twig', [
'subject' => $subject,
'message' => $txtmessage,
'festival' => $festival,
'mailfestival' => $bfmailfestival,
'subscriptionid' => 0,
'attachmentname' => $bfmailfestival->getAttachmentfiletitle()? $bfmailfestival->getAttachmentfiletitle() : $bfmailfestival->getAttachmentfile(),
]);
if(Mail::SendMailToBFUsers($admins, $owner->getEmail(), $subject, $htmlmessage, $txtmessage))
$this->addFlash('primary', 'Le mail de test a été envoyé à '.count($admins).' administrateurs');
else
$this->addFlash('danger', 'Impossible d\'envoyer le mail aux administrateurs ');
}
else
{
foreach($subscriptions as $subscription)
{
$htmlmessage = $this->renderView('mail/festivalmail.html.twig', [
'subject' => $subject,
'message' => $txtmessage,
'festival' => $festival,
'mailfestival' => $bfmailfestival,
'subscriptionid' => $subscription->getId(),
'attachmentname' => $bfmailfestival->getAttachmentfiletitle()? $bfmailfestival->getAttachmentfiletitle() : $bfmailfestival->getAttachmentfile(),
]);
if(Mail::SendMailToBFUser($subscription->getUser(), $festival->getOwner()->getEmail(), $subject, $htmlmessage, $txtmessage))
$sendedmail++;
}
$this->addFlash('primary', 'Le mail a été envoyé à '.$sendedmail.' destinataires');
}
return $this->redirect($request->getUri());
}
//get sendmail list
$sendmails = $this->getDoctrine()->getRepository(BFMailFestival::class)->findBy(['festival'=>$festival], ['senddate'=>'DESC']);
return $this->render('adminfestivalsubscriptions.html.twig', [
'userdescription' => $user->getDescription(),
'bffestival' => $festival,
'activefestivalid' => $id,
'countsubscription' => count($subscriptions),
'formsendmail' => $formsendmail->createView(),
'sendmails' => $sendmails,
]);
}
/**
* @Route("/admin/festival/create", name="admin_festival_create")
*/
public function CreateAdminFestival(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser() ;
$create = new BFFestival();
$createedition = new BFEdition();
$createedition->setFestival($create);
$formbffestivalcreate = $this->createForm(BFFestivalandEditionType::class, $createedition, [
]);
$formbffestivalcreate->handleRequest($request);
if ($formbffestivalcreate->isSubmitted() && $formbffestivalcreate->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$edition = $formbffestivalcreate->getData();
$festival=$edition->getFestival();
if(!in_array("ROLE_SUPER_ADMIN",$user->getRoles()))
$festival->setOwner($user);
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
$this->addFlash('primary', 'Le festival et l\'édition ont été créés');
if($edition->getIsactive())
{
$this->addFlash('success', 'L\'édition est publiée');
}
return $this->redirectToRoute('admin_festival',[
'id'=>$festival->getId(),
]);
}
if($formbffestivalcreate->isSubmitted() && !$formbffestivalcreate->isValid())
{
foreach($formbffestivalcreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbffestivalcreate->clearErrors(true);
}
return $this->render('adminfestivalcreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbffestivalcreate' => $formbffestivalcreate->createView(),
'uuid' => uniqid(),
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}", name="admin_edition")
*/
public function ShowAdminEdition(int $id, int $idedition, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$edition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($idedition);
$festival = $edition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user= $this->getUser();
//edit about form
$formbfeditionedit = $this->createForm(BFEditionType::class, $edition,[
'submit_label' => 'Editer',
]);
$formbfeditionedit->handleRequest($request);
if ($formbfeditionedit->isSubmitted() && $formbfeditionedit->isValid()) {
$this->denyAccessUnlessGranted('edit', $festival);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$edition = $formbfeditionedit->getData();
$edition->CleanLocation();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirect($request->getUri());
}
if($formbfeditionedit->isSubmitted() && !$formbfeditionedit->isValid())
{
foreach($formbfeditionedit->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//edit images form
$formbfeditionimagesedit = $this->createForm(BFDescriptionEditionImagesType::class, $edition->getDescription(),[
]);
$formbfeditionimagesedit->handleRequest($request);
if ($formbfeditionimagesedit->isSubmitted() && $formbfeditionimagesedit->isValid()) {
$this->denyAccessUnlessGranted('edit', $festival);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$description = $formbfeditionimagesedit->getData();
$edition= $description->getBfedition();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirect($request->getUri());
}
if($formbfeditionimagesedit->isSubmitted() && !$formbfeditionimagesedit->isValid())
{
foreach($formbfeditionimagesedit->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formrouting
$bfrouting = $edition->getRoute();
if($bfrouting==null)
$bfrouting= new BFRouting();
$formrouting = $this->createForm(RoutingType::class, $bfrouting);
$formrouting->handleRequest($request);
if ($formrouting->isSubmitted() && $formrouting->isValid()) {
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
$this->denyAccessUnlessGranted('option_uniqueurl_edition', $edition);
$bfrouting = $formrouting->getData();
$entityManager = $this->getDoctrine()->getManager();
if($edition->getRoute()==null)
{
$edition->setRoute($bfrouting);
$entityManager->persist($bfrouting);
$entityManager->persist($edition);
}
else
{
$entityManager->persist($bfrouting);
}
$entityManager->flush();
$this->addFlash('primary', 'La route a été enregistrée');
return $this->redirect($request->getUri());
}
if($formrouting->isSubmitted() && !$formrouting->isValid())
{
foreach($formrouting->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('adminedition.html.twig', [
'userdescription' => $user->getDescription(),
'formbfeditionedit' => $formbfeditionedit->createView(),
'formbfeditionimagesedit' => $formbfeditionimagesedit->createView(),
'formrouting' => $formrouting->createView(),
'activefestivalid' => $id,
'editionid' => $idedition,
'bfedition' => $edition,
'uuid' => uniqid(),
]);
}
/**
* @Route("/admin/festival-{id}/edition/create", name="admin_edition_create")
*/
public function CreateAdminEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
//get festival
$festival = $this->getDoctrine()->getRepository(BFFestival::class)->find($id);
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
$create = new BFEdition();
$create->setFestival($festival);
$formbfeditioncreate = $this->createForm(BFEditionType::class, $create,[
]);
$formbfeditioncreate->handleRequest($request);
if ($formbfeditioncreate->isSubmitted() && $formbfeditioncreate->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$edition = $formbfeditioncreate->getData();
$edition->setIsactive(false);
$edition->CleanLocation();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
$this->addFlash('primary', 'L\'édition est créée');
return $this->redirectToRoute('admin_edition',[
'id' => $edition->getFestival()->getId(),
'idedition'=>$edition->getId(),
]);
}
if($formbfeditioncreate->isSubmitted() && !$formbfeditioncreate->isValid())
{
foreach($formbfeditioncreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbfeditioncreate->clearErrors(true);
}
return $this->render('admineditioncreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbfeditioncreate' => $formbfeditioncreate->createView(),
'activefestivalid' => $id,
'bffestival' => $festival,
'uuid' => uniqid(),
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/tournois", name="admin_edition_tournois")
*/
public function ShowAdminEditionTournois(int $id, int $idedition)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user=$this->getUser();
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
return $this->render('admineditiontournois.html.twig', [
'userdescription' => $user->getDescription(),
'activefestivalid' => $id,
'editionid' => $idedition,
'tournoiid' => 0,
'bfedition' => $edition,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/tournoi-{idtournoi}", name="admin_edition_tournoiid")
*/
public function ShowAdminEditionTournoisById(int $id, int $idedition, int $idtournoi)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user=$this->getUser();
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
return $this->render('admineditiontournois.html.twig', [
'userdescription' => $user->getDescription(),
'activefestivalid' => $id,
'editionid' => $idedition,
'tournoiid' => $idtournoi,
'bfedition' => $edition,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/inscriptions", name="admin_edition_inscriptions")
*/
public function ShowAdminEditionInscriptions(int $id, int $idedition)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user=$this->getUser();
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
return $this->render('admineditioninscriptions.html.twig', [
'userdescription' => $user->getDescription(),
'activefestivalid' => $id,
'editionid' => $idedition,
'editionidins' => 0,
'bfedition' => $edition,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/inscriptions/contact", name="admin_edition_inscriptions_contact")
*/
public function ShowAdminEditionInscriptionsContact(int $id, int $idedition, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
$festival = $bfedition->getFestival();
$user=$this->getUser();
if($bfedition==null) return null;
$bfmailtournoi = new BFMailTournoi();
//form contact
$formsendmail = $this->createForm(BFMailTournoiType::class, $bfmailtournoi,[
'edition' => $bfedition,
]);
$formsendmail->handleRequest($request);
if ($formsendmail->isSubmitted() && $formsendmail->isValid()) {
$bfmailtournoi = $formsendmail->getData();
$bfinscriptions = $bfmailtournoi->getTournoi()->getInscriptions();
$emails = array();
if($bfmailtournoi->getIsadmin())
{
$admins = $festival->getAdministrators()->getValues();
$owner = $festival->getOwner();
if($owner!=null)
{
array_push($admins, $owner);
}
foreach($admins as $admin)
{
array_push($emails, $admin->getEmail());
}
}
else
{
foreach($bfinscriptions as $bfinscription)
{
$inscriptionusers = $bfinscription->getAllInscriptionUser();
foreach($inscriptionusers as $inscriptionuser)
{
if($inscriptionuser->getEmail()!=null)
array_push($emails, $inscriptionuser->getEmail());
}
}
}
$bfmailtournoi->setSenddate(new \DateTime('now'));
$bfmailtournoi->setReceivercount(count($emails));
$em =$this->getDoctrine()->getManager();
$em->persist($bfmailtournoi);
$em->flush();
$txtmessage = $bfmailtournoi->getText();
$subject = $bfmailtournoi->getSubject();
$sendedmail=0;
foreach($emails as $email)
{
$isuser = $this->getDoctrine()->getRepository(BFUser::class)->findOneBy(['email'=>$email])!=null;
$htmlmessage = $this->renderView('mail/tournoimail.html.twig', [
'subject' => $subject,
'message' => $txtmessage,
'festival' => $festival,
'mailfestival' => $bfmailtournoi,
'isuser' => $isuser,
'email' => $email,
'attachmentname' => $bfmailtournoi->getAttachmentfiletitle()? $bfmailtournoi->getAttachmentfiletitle() : $bfmailtournoi->getAttachmentfile(),
]);
if($festival->getOwner()!=null)
{
if(Mail::SendMailToMailWithFrom($email, $festival->getOwner()->getEmail(), $subject, $htmlmessage, $txtmessage))
$sendedmail++;
}
else
{
if(Mail::SendMailToMail($email, $subject, $htmlmessage, $txtmessage))
$sendedmail++;
}
}
$this->addFlash('primary', 'Le mail a été envoyé à '.$sendedmail.' destinataires');
if($sendedmail!=count($emails))
{
$bfmailtournoi->setReceivercount($sendedmail);
$em->persist($bfmailtournoi);
$em->flush();
}
return $this->redirect($request->getUri());
}
$sendmails=$this->getDoctrine()->getRepository(BFMailTournoi::class)->findByEdition($bfedition);
return $this->render('admineditioninscriptionscontact.html.twig', [
'userdescription' => $user->getDescription(),
'activefestivalid' => $id,
'editionid' => $idedition,
'editionidins' => 1,
'bfedition' => $bfedition,
'formsendmail' => $formsendmail->createView(),
'sendmails' => $sendmails,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/tournois/create", name="admin_tournoi_create")
*/
public function CreateAdminTournoi(int $id, int $idedition, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$create = new BFTournoi();
$edition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
$festival = $edition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
$create->setEdition($edition);
if($this->isGranted('option_inscription', $edition))
{
$formbftournoicreate = $this->createForm(BFTournoiWithTypeType::class, $create, [
]);
}
else
{
$formbftournoicreate = $this->createForm(BFTournoiType::class, $create, [
]);
}
$formbftournoicreate->handleRequest($request);
if ($formbftournoicreate->isSubmitted() && $formbftournoicreate->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$tournoi = $formbftournoicreate->getData();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($tournoi);
$entityManager->flush();
$edition = $tournoi->getEdition();
$festival = $edition->getFestival();
$this->addFlash('primary', 'Le tournoi est créé');
return $this->redirectToRoute('admin_edition_tournoiid',[
'id'=>$festival->getId(),
'idedition'=>$edition->getId(),
'idtournoi'=>$tournoi->getId(),
]);
}
if($formbftournoicreate->isSubmitted() && !$formbftournoicreate->isValid())
{
foreach($formbftournoicreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbftournoicreate->clearErrors(true);
}
return $this->render('admineditiontournoiscreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbftournoicreate' => $formbftournoicreate->createView(),
'activefestivalid' => $id,
'editionid' => $idedition,
'bfedition' => $edition,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/tournoi-{idtournoi}/seance/create", name="admin_seance_create")
*/
public function CreateAdminSeance(int $id, int $idedition, int $idtournoi, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$create = new BFSeance();
$tournoi= $this->getDoctrine()->getRepository(BFTournoi::class)->find($idtournoi);
$festival = $tournoi->getEdition()->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
$create->setTournoi($tournoi);
$formbfseancecreate = $this->createForm(BFSeanceType::class, $create, [
]);
$formbfseancecreate->handleRequest($request);
if ($formbfseancecreate->isSubmitted() && $formbfseancecreate->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$seance = $formbfseancecreate->getData();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($seance);
$entityManager->flush();
$tournoi=$seance->getTournoi();
$edition=$tournoi->getEdition();
$festival=$edition->getFestival();
$this->addFlash('primary', 'La séance est créée');
return $this->redirectToRoute('admin_edition_tournoiid',[
'id'=>$festival->getId(),
'idedition'=>$edition->getId(),
'idtournoi'=>$tournoi->getId(),
]);
}
if($formbfseancecreate->isSubmitted() && !$formbfseancecreate->isValid())
{
foreach($formbfseancecreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbfseancecreate->clearErrors(true);
}
return $this->render('admineditionseancecreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbfseancecreate' => $formbfseancecreate->createView(),
'activefestivalid' => $id,
'editionid' => $idedition,
'tournoiid' => $idtournoi,
'bftournoi' => $tournoi,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/tournoi-{idtournoi}/seance-{idseance}", name="admin_seance_edit")
*/
public function ShowAdminSeance(int $id, int $idedition, int $idtournoi, int $idseance, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$seance = $this->getDoctrine()
->getRepository(BFSeance::class)
->find($idseance);
$festival=$seance->getTournoi()->getEdition()->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user=$this->getUser();
$formbfseanceedit = $this->createForm(BFSeanceType::class, $seance, [
'submit_label' => 'Editer',
]);
$formbfseanceedit->handleRequest($request);
if ($formbfseanceedit->isSubmitted() && $formbfseanceedit->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$seance = $formbfseanceedit->getData();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($seance);
$entityManager->flush();
$tournoi= $seance->getTournoi();
$edition = $tournoi->getEdition();
$festival = $edition->getFestival();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirectToRoute('admin_edition_tournoiid',[
'id'=>$id,
'idedition'=>$idedition,
'idtournoi'=>$idtournoi,
]);
}
if($formbfseanceedit->isSubmitted() && !$formbfseanceedit->isValid())
{
foreach($formbfseanceedit->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('admineditionseance.html.twig', [
'userdescription' => $user->getDescription(),
'formbfseanceedit' => $formbfseanceedit->createView(),
'activefestivalid' => $id,
'editionid' => $idedition,
'tournoiid' => $idtournoi,
'bfseance' => $seance,
]);
}
/**
* @Route ("admin/challenge/create", name="admin_challenge_create")
*/
public function CreateAdminChallenge(Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$user = $this->getUser() ;
$create = new BFChallenge();
$formbfchallengecreate = $this->createForm(BFChallengeType::class, $create, [
]);
$formbfchallengecreate->handleRequest($request);
if ($formbfchallengecreate->isSubmitted() && $formbfchallengecreate->isValid()) {
$create->setOwner($user);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($create);
$entityManager->flush();
$this->addFlash('primary', 'Le challenge est créé');
return $this->redirectToRoute('admin_challenge',[
'idchallenge'=>$create->getId(),
]);
}
if($formbfchallengecreate->isSubmitted() && !$formbfchallengecreate->isValid())
{
foreach($formbfchallengecreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbfchallengecreate->clearErrors(true);
}
return $this->render('adminchallengecreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbfchallengecreate' => $formbfchallengecreate->createView(),
]);
}
/**
* @Route("/admin/challenge-{idchallenge}", name="admin_challenge")
*/
public function ShowAdminChallenge(int $idchallenge,ValidatorInterface $validator, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$challenge = $this->getDoctrine()->getRepository(BFChallenge::class)->find($idchallenge);
//$this->denyAccessUnlessGranted('edit', $challenge);
$user=$this->getUser();
$entityManager=$this->getDoctrine()->getManager();
//formdescription
$formeditchallenge = $this->createForm(BFChallengeType::class, $challenge, [
'submit_label' =>'Editer',
]);
$formeditchallenge->handleRequest($request);
if(($formeditchallenge->isSubmitted() && $formeditchallenge->isValid()))
{
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirect($request->getUri());
}
if($formeditchallenge->isSubmitted() && !$formeditchallenge->isValid())
{
foreach($formeditchallenge->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formfestivals
$festivals = $this->getDoctrine()->getRepository(BFFestival::class)->findAll();
foreach($challenge->getFestivals() as $festival)
{
$key = array_search($festival, $festivals);
if($key>=0)
{
unset($festivals[$key]);
}
}
$formfestivals = $this->createForm(BFChallengeAddFestivalType::class, null,[
'festivals' => $festivals,
] );
$formfestivals->handleRequest($request);
if($formfestivals->isSubmitted() && $formfestivals->isValid())
{
$selectedfestivalid = $formfestivals->getData()['addfestival'];
$selectedfestival=null;
if($selectedfestivalid!=null)
{
$selectedfestival = $this->getDoctrine()->getRepository(BFFestival::class)->find($selectedfestivalid);
}
if($selectedfestival!=null)
{
$challenge->addFestival($selectedfestival);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('primary', 'Le festival a été ajouté au challenge');
}
else
{
$this->addFlash('danger', 'Impossible d\'ajouter le festival au challenge');
}
return $this->redirect($request->getUri());
}
//formowner
$emailvalue = $challenge->getOwner()!=null ? $challenge->getOwner()->getEmail() : "";
$formchallengeowner = $this->createForm(BFFestivalOwnerType::class, null, [
'email_value' => $emailvalue,
]);
$formchallengeowner->handleRequest($request);
if ($formchallengeowner->isSubmitted() && $formchallengeowner->isValid())
{
//$this->denyAccessUnlessGranted('delete', $challenge);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$email = $formchallengeowner->getData()['email'];
if($email==null)
{
$challenge->setOwner(null);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('primary', 'Le propriétaire du challenge a été modifié');
}
else
{
//getuser from email
$owneruser =$this->getDoctrine()
->getRepository(BFUser::class)
->findOneBy(['email'=>$email]);
if($owneruser!=null)
{
$challenge->setOwner($owneruser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('primary', 'Le propriétaire du challenge a été modifié');
}
else
{
$this->addFlash('danger', 'L\'adresse email est inconnue');
}
}
return $this->redirect($request->getUri());
}
if($formchallengeowner->isSubmitted() && !$formchallengeowner->isValid())
{
foreach($formchallengeowner->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formaddadministrator
$formchallengeadministratoradd = $this->createForm(BFFestivalAdministratorAddType::class, null, [
]);
$formchallengeadministratoradd->handleRequest($request);
if ($formchallengeadministratoradd->isSubmitted() && $formchallengeadministratoradd->isValid()) {
//$this->denyAccessUnlessGranted('delete', $challenge);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$email = $formchallengeadministratoradd->getData()['email'];
//getuser from email
$adminuser =$this->getDoctrine()
->getRepository(BFUser::class)
->findOneBy(['email'=>$email]);
if($adminuser!=null)
{
$challenge->addAdministrator($adminuser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('primary', 'L\'administrateur a été ajouté');
return $this->redirect($request->getUri());
}
else
{
$this->addFlash('danger', 'L\'adresse email est inconnue');
}
}
if($formchallengeadministratoradd->isSubmitted() && !$formchallengeadministratoradd->isValid())
{
foreach($formchallengeadministratoradd->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
//formremoveadministrator
$formchallengeadministratorremove = $this->createForm(BFFestivalAdministratorRemoveType::class, null, ['festival'=>$challenge]);
$formchallengeadministratorremove->handleRequest($request);
if ($formchallengeadministratorremove->isSubmitted() && $formchallengeadministratorremove->isValid()) {
//$this->denyAccessUnlessGranted('delete', $challenge);
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$administratorid = $formchallengeadministratorremove->getData()['administratorstodelete'];
$adminuser=null;
if($administratorid!=null)
{
$adminuser =$this->getDoctrine()->getRepository(BFUser::class)->find($administratorid);
}
if($adminuser!=null)
{
$challenge->removeAdministrator($adminuser);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($challenge);
$entityManager->flush();
$this->addFlash('primary', 'L\'administrateur a été envelé');
return $this->redirect($request->getUri());
}
}
if($formchallengeadministratorremove->isSubmitted() && !$formchallengeadministratorremove->isValid())
{
foreach($formchallengeadministratorremove->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('adminchallenge.html.twig', [
'userdescription' => $user->getDescription(),
'bfchallenge' => $challenge,
'formbfchallengeedit' => $formeditchallenge->createView(),
'formbfchallengeowner' => $formchallengeowner->createView(),
'formbfchallengeadminadd' => $formchallengeadministratoradd->createView(),
'formbfchallengeadminremove' => $formchallengeadministratorremove->createView(),
'formaddbffestival' => $formfestivals->createView(),
'activechallengeid' => $idchallenge,
]);
}
/**
* @Route("/admin/challenge-{idchallenge}/subscriptions", name="admin_challenge_subscriptions")
*/
public function ShowAdminChallengeSubscriptions(int $idchallenge, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$challenge = $this->getDoctrine()
->getRepository(BFChallenge::class)
->find($idchallenge);
$this->denyAccessUnlessGranted('edit', $challenge);
$user=$this->getUser();
//countsubscribers
$subscriptions = $this->getDoctrine()->getRepository(BFSubscription::class)->FindBy(['challenge'=>$challenge]);
//formsendmail
$bfmailchallenge = new BFMailChallenge();
$formsendmail = $this->createForm(BFMailFestivalType::class, $bfmailchallenge);
$formsendmail->handleRequest($request);
if ($formsendmail->isSubmitted() && $formsendmail->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$bfmailfestival = $formsendmail->getData();
$bfmailchallenge->setChallenge($challenge);
$bfmailchallenge->setSubscribercount(count($subscriptions));
$bfmailchallenge->setSenddate(new \DateTime('now'));
$em =$this->getDoctrine()->getManager();
$em->persist($bfmailchallenge);
$em->flush();
$txtmessage = $bfmailchallenge->getText();
$subject = $bfmailchallenge->getSubject();
$sendedmail=0;
if($bfmailchallenge->getIsadmin())
{
$admins = $challenge->getAdministrators()->getValues();
$owner = $challenge->getOwner();
if($owner!=null)
{
array_push($admins, $owner);
}
if(count($admins)==0)
{
$userrepository =$this->getDoctrine()->getRepository(BFUser::class);
array_push($admins, $userrepository->findByRole('ROLE_SUPER_ADMIN'));
}
$htmlmessage = $this->renderView('mail/challengemail.html.twig', [
'subject' => $subject,
'message' => $txtmessage,
'challenge' => $challenge,
'mailchallenge' => $bfmailchallenge,
'subscriptionid' => 0,
'attachmentname' => $bfmailchallenge->getAttachmentfiletitle()? $bfmailchallenge->getAttachmentfiletitle() : $bfmailchallenge->getAttachmentfile(),
]);
if(Mail::SendMailToBFUsers($admins, $owner->getEmail(), $subject, $htmlmessage, $txtmessage))
$this->addFlash('primary', 'Le mail de test a été envoyé à '.count($admins).' administrateurs');
else
$this->addFlash('danger', 'Impossible d\'envoyer le mail aux administrateurs ');
}
else
{
foreach($subscriptions as $subscription)
{
$htmlmessage = $this->renderView('mail/challengemail.html.twig', [
'subject' => $subject,
'message' => $txtmessage,
'challenge' => $challenge,
'mailchallenge' => $bfmailchallenge,
'subscriptionid' => $subscription->getId(),
'attachmentname' => $bfmailchallenge->getAttachmentfiletitle()? $bfmailchallenge->getAttachmentfiletitle() : $bfmailchallenge->getAttachmentfile(),
]);
if(Mail::SendMailToBFUser($subscription->getUser(), $challenge->getOwner()->getEmail(), $subject, $htmlmessage, $txtmessage))
$sendedmail++;
}
$this->addFlash('primary', 'Le mail a été envoyé à '.$sendedmail.' destinataires');
}
return $this->redirect($request->getUri());
}
//get sendmail list
$sendmails = $this->getDoctrine()->getRepository(BFMailChallenge::class)->findBy(['challenge'=>$challenge], ['senddate'=>'DESC']);
return $this->render('adminchallengesubscriptions.html.twig', [
'userdescription' => $user->getDescription(),
'bfchallenge' => $challenge,
'countsubscription' => count($subscriptions),
'formsendmail' => $formsendmail->createView(),
'sendmails' => $sendmails,
'activechallengeid' => $idchallenge,
]);
}
/**
* @Route("/admin/challenge-{id}/edition/create", name="admin_challenge_edition_create")
*/
public function CreateAdminChallengeEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
//get challenge
$challenge = $this->getDoctrine()->getRepository(BFChallenge::class)->find($id);
if($challenge==null)
throw $this->createNotFoundException('The challenge doesn\'t exist');
$this->denyAccessUnlessGranted('edit', $challenge);
$user=$this->getUser();
//compute possible editions
$festivalsfromchallenge = $challenge->getFestivals();
$editionsarray= array();
foreach($festivalsfromchallenge as $festival)
{
$editions = $festival->getEditions();
foreach($editions as $edition)
{
$challengeeditions=$edition->getChallengeeditions();
//check if the edition is already in a challenge edition
if(count($challengeeditions)>0)
{
$isalreadyhere=false;
//check the possibility if the challenge is the current one
foreach($challengeeditions as $challengeedition)
{
//if yes we don't propose this bfedition because already in an edition of the current challenge
if($challengeedition->getChallenge()==$challenge)
{
$isalreadyhere=true;
break;
}
}
if(!$isalreadyhere)
array_push($editionsarray, $edition);
}
else
array_push($editionsarray, $edition);
}
}
$create = new BFChallengeEdition();
$create->setChallenge($challenge);
$formbfeditioncreate = $this->createForm(BFChallengeEditionType::class, $create,[
'editions'=>$editionsarray ]);
$formbfeditioncreate->handleRequest($request);
if ($formbfeditioncreate->isSubmitted() && $formbfeditioncreate->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
$edition = $formbfeditioncreate->getData();
$edition->setIsactive(false);
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($edition);
$entityManager->flush();
$this->addFlash('primary', 'L\'édition est créée');
return $this->redirectToRoute('admin_challenge_edition',[
'id' => $edition->getChallenge()->getId(),
'idedition'=>$edition->getId(),
]);
}
if($formbfeditioncreate->isSubmitted() && !$formbfeditioncreate->isValid())
{
foreach($formbfeditioncreate->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
$formbfeditioncreate->clearErrors(true);
}
return $this->render('challenges/adminchallengeeditioncreate.html.twig', [
'userdescription' => $user->getDescription(),
'formbfchallengeeditioncreate' => $formbfeditioncreate->createView(),
'challengeid' => $challenge->getId(),
'activechallengeid' => $challenge->getId(),
'bfchallenge' => $challenge,
]);
}
/**
* @Route("/admin/challenge/edition-{idedition}", name="admin_challenge_edition")
*/
public function ShowAdminChallengeEdition(int $idedition, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$cedition = $this->getDoctrine()
->getRepository(BFChallengeEdition::class)
->find($idedition);
$challenge = $cedition->getChallenge();
$this->denyAccessUnlessGranted('edit', $challenge);
$user= $this->getUser();
//compute possible editions
$festivalsfromchallenge = $challenge->getFestivals();
$editionsarray= array();
foreach($festivalsfromchallenge as $festival)
{
$editions = $festival->getEditions();
array_push($editionsarray, $editions->toArray());
}
//edit about form
$formbfchallengeeditionedit = $this->createForm(BFChallengeEditionType::class, $cedition,[
'editions'=>$editionsarray, 'submit_label'=>'Editer' ]);
$formbfchallengeeditionedit->handleRequest($request);
if ($formbfchallengeeditionedit->isSubmitted() && $formbfchallengeeditionedit->isValid()) {
// $form->getData() holds the submitted values
// but, the original `$task` variable has also been updated
//$cedition = $formbfchallengeeditionedit->getData();
// ... perform some action, such as saving the task to the database
// for example, if Task is a Doctrine entity, save it!
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($cedition);
$entityManager->flush();
$this->addFlash('success', 'Les modifications sont enregistrées');
return $this->redirect($request->getUri());
}
if($formbfchallengeeditionedit->isSubmitted() && !$formbfchallengeeditionedit->isValid())
{
foreach($formbfchallengeeditionedit->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('challenges/adminchallengeedition.html.twig', [
'userdescription' => $user->getDescription(),
'formbfchallengeedition' => $formbfchallengeeditionedit->createView(),
'activechallengeid' => $challenge->getId(),
'editionid' => $idedition,
'bfchallengeedition' => $cedition,
]);
}
/**
* @Route("/admin/edition-{id}/unactive", name="admin_bfedition_unactive")
*/
public function UnactiveEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$response = $this->forward('App\Controller\BFEditionController::ChangeActiveEdition', [
'id' => $id,
'isactive' => false,
'fromadmin'=> true,
'request' =>$request,
]);
return $response;
}
/**
* @Route("/admin/edition-{id}/active", name="admin_bfedition_active")
*/
public function ActiveEdition(int $id, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$response = $this->forward('App\Controller\BFEditionController::ChangeActiveEdition', [
'id' => $id,
'isactive' => true,
'fromadmin'=> true,
'request' =>$request,
]);
return $response;
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/cardspreview", name="admin_edition_cardspreview")
*/
public function ShowCardsPreview(int $id, int $idedition, Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$bfedition = $this->getDoctrine()->getRepository(BFEdition::class)->find($idedition);
$festival=$bfedition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
if($this->isGranted('option_uniqueurl_festival', $festival) && $festival->getRoute()!=null)
{
$route = $this->generateUrl('home_route',[
'route' => $festival->getRoute()->getRoute(),
]);
}
else if ($this->isGranted('option_uniqueurl_edition', $bfedition) && $bfedition->getRoute()!=null)
{
$route = $this->generateUrl('home_route',[
'route' => $bfedition->getRoute()->getRoute(),
]);
}
else
{
$route = $this->generateUrl('edition_view',[
'id' => $id,
]);
}
return $this->render('homepreview.html.twig', [
'bfedition' => $bfedition,
'bfeditionroute' => $route,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/payements", name="admin_edition_payements")
*/
public function ShowAdminEditionPayement($id, $idedition,Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$bfedition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($idedition);
$festival = $bfedition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user= $this->getUser();
$producteditions = $bfedition->getBfproducteditions();
$producteditionsbuy=array();
$produceditionsquantity=array();
$producteditionssum=array();
foreach($producteditions as $productedition)
{
$isbuy=false;
$quantity=0;
$sum=0;
$ordereditions = $productedition->getBFOrderEditions();
foreach($ordereditions as $orderedition)
{
$paymentintent = $orderedition->getBFPaymentIntentEdition();
if($paymentintent->getSuccessdate()!=null && $paymentintent->getRefunddate()==null)
{
$isbuy=true;
$quantity+=$orderedition->getQuantity();
$sum+=$orderedition->getDisplayTotal();
}
}
if($isbuy)
{
array_push($producteditionsbuy, $productedition);
array_push($produceditionsquantity, $quantity);
array_push($producteditionssum, $sum);
}
}
return $this->render('admineditionpayments.html.twig', [
'userdescription' => $user->getDescription(),
'bfedition' => $bfedition,
'activefestivalid' => $festival->getId(),
'editionid' => $bfedition->getId(),
'arrayproducteditions' => $producteditionsbuy,
'arrayquantity' => $produceditionsquantity,
'arraysum' => $producteditionssum,
]);
}
/**
* @Route("/admin/festival-{id}/edition-{idedition}/payements/create", name="admin_edition_payements_create")
*/
public function CreateAdminProductEdition($id, $idedition,Request $request)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$bfedition = $this->getDoctrine()
->getRepository(BFEdition::class)
->find($idedition);
$festival = $bfedition->getFestival();
$this->denyAccessUnlessGranted('edit', $festival);
$user= $this->getUser();
$newproduct = new BFProductEdition();
//edit about form
$formbfproductedition = $this->createForm(BFProductEditionType::class, $newproduct ,[
'edition'=> $bfedition, 'submit_label'=>'Créer' ]);
$formbfproductedition->handleRequest($request);
if ($formbfproductedition->isSubmitted() && $formbfproductedition->isValid()) {
$newproduct->setEdition($bfedition);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($newproduct);
$entityManager->flush();
$this->addFlash('success', 'Le nouveau forfait est créé');
return $this->redirectToRoute('admin_edition_payements', ['id' => $id, 'idedition' => $idedition]);
}
if($formbfproductedition->isSubmitted() && !$formbfproductedition->isValid())
{
foreach($formbfproductedition->getErrors(true) as $error)
$this->addFlash('danger', "(".$error->getOrigin()->getName().") ".$error->getMessage());
return $this->redirect($request->getUri());
}
return $this->render('payments/adminproducteditioncreate.html.twig', [
'userdescription' => $user->getDescription(),
'activefestivalid' => $festival->getId(),
'editionid' => $bfedition->getId(),
'bfedition' => $bfedition,
'formbfproductedition' => $formbfproductedition->createView(),
]);
}
private function ClearUserResetPassword(BFUser $bfuser)
{
//get bfreset from user id
$bfresetpassword = $this->getDoctrine()->getRepository(BFResetPassword::class)->findOneBy(['user'=>$bfuser]);
if($bfresetpassword!=null)
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($bfresetpassword);
$entityManager->flush();
}
}
}
?>