<?php
namespace App\Controller\Backend;
use App\Entity\Congres;
use App\Entity\Participation;
use App\Form\Congres\ajoutCongresType;
use App\Form\Congres\modifCongresType;
use App\Repository\CongresRepository;
use App\Repository\EventRepository;
use App\Repository\InscriptionRepository;
use App\Repository\AbstractInscriptionRepository;
use App\Repository\MemberComiteCategorieRepository;
use App\Repository\ParticipationRepository;
use App\Repository\UserRepository;
use App\Repository\AuteurAbstractRepository;
use App\Repository\AbstracttRepository;
use Doctrine\ORM\EntityManagerInterface;
use Dompdf\Dompdf;
use Dompdf\Options;
use Knp\Component\Pager\PaginatorInterface;
use phpDocumentor\Reflection\Types\Null_;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\PresenceCongres;
use Symfony\Component\Security\Core\Security;
class CongresController extends AbstractController
{
/**
* @var CongresRepository
*/
private $repository;
public function __construct(CongresRepository $repository)
{
$this->repository = $repository;
}
/**
* @Route("/admin/particpantParCongreIndex/{congres}", name="participant_par_congres_index")
*/
public function participantParCongresIndex(Request $request, ParticipationRepository $participationRepository, $congres)
{
$participations = $participationRepository->findBy(['congres' => $congres]);
return $this->render('backend/congres/participantParCongres.html.twig', array('participations' => $participations, 'congres' => $congres));
}
/**
* @Route("/admin/particpantIndex", name="participant_index")
*/
public function participantIndex(Request $request, ParticipationRepository $participationRepository)
{
$participations = $participationRepository->findAll();
return $this->render('backend/congres/participation.html.twig', array('participations' => $participations));
}
/**
* @Route("/admin/listecongres", name="tous_congres")
*/
public function findAll(Request $request, ParticipationRepository $participationRepository)
{
$participations = $participationRepository->findByParticipationGroupeBy();
$touscongres = $this->repository->findAll();
return $this->render('backend/congres/congres.html.twig', array('touscongres' => $touscongres, 'participations' => $participations));
}
/**
* @Route("/admin/ParticipantAccepterDelegue", name="accepter_Delegue")
*/
public function ParticipantAccepterDelegue(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('participant');
$participation->setStatut('accepter');
$em->flush();
return new JsonResponse('participantAcceperDelegue');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/admin/ParticipantAccepterParticipant", name="accepter_Modérateur")
*/
public function ParticipantAccepterParticipant(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('chair');
$participation->setStatut('accepter');
$em->flush();
return new JsonResponse('participantAcceperModérateur');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/admin/ParticipantAccepterSpeaker", name="accepter_Speaker")
*/
public function ParticipantAccepterSpeaker(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('speaker');
$participation->setStatut('accepter');
$em->flush();
return new JsonResponse('participantAcceperSpeaker');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/admin/ParticipantAccepterExposant", name="accepter_Exposant")
*/
public function ParticipantAccepterExposant(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('exhibitor');
$participation->setStatut('accepter');
$em->flush();
return new JsonResponse('participantAcceperExposant');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/admin/ParticipantAccepterOrganizer", name="accepter_Organizer")
*/
public function ParticipantAccepterOrganizer(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('organisator');
$participation->setStatut('accepter');
$em->flush();
return new JsonResponse('participantAcceperOrganizer');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/admin/ParticipantRefuser", name="refuser_Participant")
*/
public function ParticipantRefuser(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em)
{
$participation = $participationRepository->findOneBy(['id' => $request->request->get('id')]);
if ($request->isMethod('post')) {
$participation->setTitre('refuser');
$participation->setStatut('refuser');
$em->flush();
return new JsonResponse('participantRefuser');
}
return $this->render('backend/congres/participantParCongres.html.twig', array('congres' => $participation->getCongres()->getId()));
}
/**
* @Route("/user/badgeIndex", name="badge_index")
*/
public function BadgeIndex(Request $request, ParticipationRepository $participationRepository, EntityManagerInterface $em, CongresRepository $congresRepository)
{
$participants = $participationRepository->findAll();
$congres = $congresRepository->findBy(['type_congres' => 'national']);
return $this->render('backend/badge/badgeIndex.html.twig', array('congres' => $congres, 'participants' => $participants));
}
/**
* @Route("/event/badge/{id}", name="badge")
*/
public function Badge(Request $request, InscriptionRepository $inscriptionRepository, EntityManagerInterface $em, $id)
{
$inscription = $inscriptionRepository->findOneBy(['id' => $id]);
$nom = $inscription->getNom();
$role = $inscription->getRole();
$prenom = $inscription->getPrenom();
$messageOld = 'Bienvenu(e) ' . $nom . ' ' . $prenom . ' parmi notre association tunisienne d\'urologie';
$message = 'http://urotunisia.com/presenceCongres/' . $inscription->getId();
$event = Null;
$congre = Null;
if (!empty($inscription->getCongres())) {
$congre = $inscription->getCongres();
} elseif (!empty($inscription->getEvent())) {
$event = $inscription->getEvent();
}
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
$pdfOptions->set('isRemoteEnabled', true); // temp folder with write permission
$pdfOptions->setIsRemoteEnabled(true);
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('backend/badge/badge.html.twig', ['nom' => $nom, 'prenom' => $prenom, 'event' => $event, 'congres' => $congre, 'message' => $message, 'role' => $role, 'id' => $inscription->getId()]);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// $paper_size = array(0,0,360,360);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (force download)
$dompdf->stream("Badge-" . $nom . "-" . $prenom . ".pdf", [
"Attachment" => false
]);
return $this->redirectToRoute('congres_nationaux');
}
/**
* @Route("/congresNationaux", name="congres_nationaux")
*/
public function CongresNat(Request $request, PaginatorInterface $paginator, MemberComiteCategorieRepository $memberComiteCategorieRepository, EventRepository $eventRepository)
{
$dateNow = new \DateTime('now');
$touscongres = $this->repository->findBy([], ['id' => 'DESC']);
$events = $eventRepository->findBy(['categorie' => 'national'], ['startDate' => 'ASC']);
$memberComiteCategorie = $memberComiteCategorieRepository->findAll();
$touscongres = $paginator->paginate(
// Doctrine Query, not results
$touscongres,
// Define the page parameter
$request->query->getInt('page', 1),
// Items per page
6
);
$congressByYear = $this->repository->findCongresByYear();
return $this->render('frontend/frontindex/congresNationaux.html.twig', array('touscongres' => $touscongres, 'memberComiteCategories' => $memberComiteCategorie, 'congressByYear' => $congressByYear, 'dateNow' => $dateNow, 'eventsATU' => $events));
}
/**
* @Route("/presenceCongres/{inscription}", name="presenceCongres")
*/
public function presenceCongres($inscription, EntityManagerInterface $em, InscriptionRepository $inscriptionRepository, Security $security): Response
{
$inscriptions = $inscriptionRepository->findOneBy(['id' => $inscription]);
// if ($security->isGranted('IS_AUTHENTICATED_FULLY')) {
// // Vérifier si l'utilisateur a le rôle d'administrateur
// if ($security->isGranted('ROLE_ADMIN_EVENTS')) {
$date = new \DateTime('now');
$dateFormatted = $date->format('Y-m-d');
$titreEvent = Null;
$dateFin = Null;
$dateDeb = Null;
if (!empty($inscriptions->getCongres())) {
$titreEvent = $inscriptions->getCongres()->getLabel();
$dateFin = $inscriptions->getCongres()->getDateFin()->format('Y-m-d');
$dateDeb = $inscriptions->getCongres()->getDateDebut()->format('Y-m-d');
} elseif (!empty($inscriptions->getEvent())) {
$titreEvent = $inscriptions->getEvent()->getTitre();
$dateFin = $inscriptions->getEvent()->getEndDate()->format('Y-m-d');
$dateDeb = $inscriptions->getEvent()->getStartDate()->format('Y-m-d');
}
if (($dateFin < $dateFormatted)) {
$this->addFlash('danger', 'Le congrès ' . $titreEvent . ' est déja passé');
} elseif (($dateDeb > $dateFormatted)) {
$this->addFlash('danger', 'Le congrès ' . $titreEvent . ' est à venir');
} elseif (($dateFormatted >= $dateDeb) && ($dateFormatted <= $dateFin)) {
$presenceCongres = new PresenceCongres();
$presenceCongres->setInscription($inscriptions);
$presenceCongres->setDate(new \DateTime('now'));
$em->persist($presenceCongres);
$em->flush();
$this->addFlash('success', 'Bienvenu(e) ' . $inscriptions->getNom() . ' ' . $inscriptions->getPrenom() . ' dans le : ' . $titreEvent . ', votre présence est enregistrée avec succès');
}
return $this->redirectToRoute('congres_nationaux', []);
// }
// else
// {
// $this->addFlash('success', 'Bonjour, le QR code doit être scanné par une des hôtesses à l\'accueil du congrès. ');
// return $this->redirectToRoute('congres_nationaux',[]);
// }
// }
// else{
// $this->addFlash('danger', 'Bonjour, merci de se connecter en tant qu\'admin et ensuite scanner le QR code. ');
// return $this->redirectToRoute('app_login',[]);
// }
}
/**
* @Route("/BeParticipant/{user}/{congre}", name="BeParticipant")
*/
public function BeParticipant(Request $request, $user, $congre, CongresRepository $congresRepository, UserRepository $userRepository, EntityManagerInterface $em, ParticipationRepository $participationRepository)
{
$congres = $congresRepository->findOneBy(array('id' => $congre));
$userr = $userRepository->findOneBy(['id' => $user]);
$partexist = $participationRepository->findBy(['user' => $user, 'congres' => $congre]);
$participation = new Participation();
if ($request->isMethod('post')) {
if (empty($partexist)) {
$participation->setCongres($congres);
$participation->setUser($userr);
$participation->setStatut('en_attente');
$participation->setTitre($request->request->get('statuts'));
$em->persist($participation);
$em->flush();
if ($request->getLocale() == 'fr') {
$this->addFlash('success', 'Félicitations! nous vous avons confirmé votre participation au congrès');
} elseif ($request->getLocale() == 'en') {
$this->addFlash('success', 'Congratulation! we have confirmed your participation in the congress');
}
} elseif (!empty($partexist)) {
if ($request->getLocale() == 'fr') {
$this->addFlash('danger', 'Vous avez deja participé dans ce congrès');
} elseif ($request->getLocale() == 'en') {
$this->addFlash('danger', 'You have already participated in this congress');
}
}
}
return $this->redirectToRoute('congres_nationaux');
}
/**
* @Route("/congres-details/{id}", name="details_congres")
* @param Congres $congres
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function detailsCongres(Congres $congres, Request $request, $id, EntityManagerInterface $em, CongresRepository $repository, AbstractInscriptionRepository $abstractInscriptionRepository)
{
$congres = $repository->find($id);
$abstractsInscriptions = $abstractInscriptionRepository->findAll();
return $this->render('frontend/frontindex/detailsCongres.html.twig', array('congres' => $congres, 'abstractInscriptions' => $abstractsInscriptions));
}
/**
* @Route("/admin/modifierCongres/{id}", name="modifier_congres")
* @param Congres $congres
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function editer(Congres $congres, Request $request, $id, EntityManagerInterface $em, CongresRepository $repository)
{
$congres = $repository->find($id);
$oldImage = $congres->getImage();
$oldPdf = $congres->getLienPdf();
if ($congres->getImage() != null) {
$congres->setImage(
new File($this->getParameter('imagesCongres_directory') . '/' . $congres->getImage())
);
}
if ($congres->getLienPdf() != null) {
$congres->setLienPdf(
new File($this->getParameter('uploadCongres_directory') . '/' . $congres->getLienPdf())
);
}
$form = $this->createForm(modifCongresType::class, $congres);
$form->handleRequest($request);
$touscongres = $this->repository->findAll();
if ($form->isSubmitted() && $form->isValid()) {
$brochureFile = $form->get('image')->getData();
$brochureFilePdf = $form->get('lien_pdf')->getData();
if ($brochureFile) {
$fileNameimage = md5(uniqid()) . '.' . $brochureFile->guessExtension();
$congres->setImage($fileNameimage);
$brochureFile->move(
$this->getParameter('imagesCongres_directory'),
$fileNameimage
);
} else {
$congres->setImage($oldImage);
}
if ($brochureFilePdf) {
$fileNamePdf = md5(uniqid()) . '.' . $brochureFilePdf->guessExtension();
$congres->setLienPdf($fileNamePdf);
$brochureFilePdf->move(
$this->getParameter('uploadCongres_directory'),
$fileNamePdf
);
} else {
$congres->setLienPdf($oldPdf);
}
foreach ($congres->getPackCongre() as $pack) {
$pack->setCongres($congres);
}
// var_dump($congres->getPackCongre());
// die();
$em->flush();
return $this->redirectToRoute('tous_congres');
}
return $this->render('backend/congres/edit.html.twig', array('form' => $form->createView(), 'touscongres' => $touscongres, 'congres' => $congres));
}
/**
* @Route("/admin/ajoutCongres", name="ajouter_congres")
*/
public function ajoutCongres(Request $request, EntityManagerInterface $em)
{
$congres = new Congres();
$form = $this->createForm(ajoutCongresType::class, $congres);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$brochureFile = $form->get('image')->getData();
$brochureFilePdf = $form->get('lien_pdf')->getData();
if ($congres->getImage() != null) {
$fileNameimage = md5(uniqid()) . '.' . $brochureFile->guessExtension();
$congres->setImage($fileNameimage);
try {
$brochureFile->move(
$this->getParameter('imagesCongres_directory'),
$fileNameimage
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
if ($congres->getLienPdf() != null) {
$fileNamepdf = md5(uniqid()) . '.' . $brochureFilePdf->guessExtension();
$congres->setLienPdf($fileNamepdf);
try {
$brochureFilePdf->move(
$this->getParameter('uploadCongres_directory'),
$fileNamepdf
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
}
foreach ($congres->getPackCongre() as $pack) {
$pack->setCongres($congres);
}
// var_dump($congres->getPackCongre());
// die();
$em->persist($congres);
$em->flush();
return $this->redirectToRoute('tous_congres');
}
return $this->render('backend/congres/add.html.twig', array('form' => $form->createView()));
}
/**
* @Route("/admin/supprimerCongres/{id}", name="supprimer_congres")
*/
public function supprimer($id, CongresRepository $repository, EntityManagerInterface $em)
{
$congres = $repository->find($id);
$em->remove($congres);
$em->flush();
return $this->redirectToRoute('tous_congres');
}
/**
* @Route("/admin/searchcongres/", name="congres_search")
*/
public function searchCongres(CongresRepository $repository, Request $request, PaginatorInterface $paginator)
{
$congres = $repository->findByNamePopular(
$request->query->get('query')
);
$congres = $paginator->paginate(
// Doctrine Query, not results
$congres,
// Define the page parameter
$request->query->getInt('page', 1),
// Items per page
2
);
$entityManager = $this->getDoctrine()->getManager();
$categoryRepository = $entityManager->getRepository(Congres::class);
return $this->render('backend/congres/congres.html.twig', [
'touscongres' => $congres
]);
}
/**
* @Route("/certificat", name="obtenir_certificat")
*/
public function certificat(CongresRepository $repository, EntityManagerInterface $em)
{
return $this->render('frontend/frontindex/certificat.html.twig');
}
/**
* @Route("/pdf", name="pdf_certificat")
*/
public function pdf(CongresRepository $repository, EntityManagerInterface $em)
{
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
$pdfOptions->set('isRemoteEnabled', true); // temp folder with write permission
$pdfOptions->setIsRemoteEnabled(true);
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('frontend/frontindex/pdf.html.twig');
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// $paper_size = array(0,0,360,360);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (force download)
$dompdf->stream("certificat.pdf", [
"Attachment" => true
]);
return $this->render('frontend/frontindex/certificat.html.twig');
}
/**
* @Route("/abstract-book/{id}", name="abstract-book")
*/
public function abstractBook(AbstracttRepository $abstracttRepository, $id, CongresRepository $congresRepository, AuteurAbstractRepository $auteurAbstractRepository)
{
$congres = $congresRepository->findOneBy(['id' => $id]);
$abstracts = $abstracttRepository->findBy(['congres' => $congres->getId(), 'statut' => 'accepter'], ['typeFinal' => 'ASC']);
$auteurs = $auteurAbstractRepository->findAll([]);
$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
$pdfOptions->set('isRemoteEnabled', true); // temp folder with write permission
$pdfOptions->setIsRemoteEnabled(true);
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('backend/congres/abstractBook.html.twig', ['abstracts' => $abstracts, 'auteurs' => $auteurs]);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// $paper_size = array(0,0,360,360);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (force download)
$dompdf->stream("Abstarct-book-" . $congres->getId() . ".pdf", [
"Attachment" => false
]);
return $this->render('frontend/frontindex/detailsCongres.html.twig', array('congres' => $congres));
}
}