src/Controller/website/WebsiteController.php line 140

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Controller/website/WebsiteController.php
  4. //----------------------------------------------------------------------
  5. namespace App\Controller\website;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpKernel\Exception\HttpException;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\Security\Core\Security;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use App\Repository\ArticleRepository;
  15. use App\Repository\NotificationRepository;
  16. use App\Repository\PartnerRepository;
  17. use App\Repository\MembersAssoRepository;
  18. use App\Repository\EventRepository;
  19. use App\Repository\ProjectRepository;
  20. use App\Entity\Workshop;
  21. use App\Entity\WorkshopCategory;
  22. use App\Entity\MembershipAsso;
  23. use App\Entity\MembershipIndividual;
  24. use App\Entity\Contact;
  25. use App\Form\ContactType;
  26. use App\Form\website\MembershipAssoTypeOut;
  27. use App\Form\website\MembershipIndiTypeOut;
  28. use App\Service\LogTools;
  29. class WebsiteController extends AbstractController
  30. {
  31.     public function __construct(Security $securityManagerRegistry $doctrineLogTools $logToolsNotificationRepository $notifRepositoryArticleRepository $articleRepositoryPartnerRepository $partnerRepositoryMembersAssoRepository $membersAssoRepoEventRepository $eventRepositoryProjectRepository $projectRepository)
  32.     {
  33.         $this->logTools $logTools;
  34.         $this->security $security;
  35.         $this->em $doctrine->getManager();
  36.         $this->notifRepository $notifRepository;
  37.         $this->articleRepository $articleRepository;
  38.         $this->partnerRepository $partnerRepository;
  39.         $this->membersAssoRepo $membersAssoRepo;
  40.         $this->eventRepository $eventRepository;
  41.         $this->projectRepository $projectRepository;
  42.     }
  43.     public function home(): Response
  44.     {  
  45.         $notif $this->notifRepository->findLast();
  46.         
  47.         $result null;
  48.         if ($notif!=null) {
  49.             if ($notif->getDateOver() > new \DateTime('now')) {
  50.                 $result $notif;
  51.             }
  52.         }else {
  53.             $result null;
  54.         }
  55.         return $this->render("website/index.html.twig", [
  56.             'notification' => $result,
  57.             'partners' => $this->partnerRepository->findAll(),
  58.             'events' => $this->eventRepository->findNext(),
  59.         ]);
  60.     }
  61.     public function legal(): Response
  62.     {  
  63.         return $this->render("website/legal.html.twig", [
  64.             'partners' => $this->partnerRepository->findAll(),
  65.         ]);
  66.     }
  67.     public function missions(): Response
  68.     {  
  69.         return $this->render("website/missions.html.twig" , [
  70.             'partners' => $this->partnerRepository->findAll(),
  71.             'projects' => $this->projectRepository->findAllByOrder(),
  72.         ]);
  73.     }
  74.     public function equipe(): Response
  75.     {  
  76.         return $this->render("website/equipe.html.twig" , [
  77.             'partners' => $this->partnerRepository->findAll(),
  78.         ]);
  79.     }
  80.     public function adherents(): Response
  81.     {  
  82.         return $this->render("website/adherents.html.twig" , [
  83.             'members_asso' => $this->membersAssoRepo->findAll(),
  84.             'partners' => $this->partnerRepository->findAll(),
  85.         ]);
  86.     }
  87.     public function ateliers(): Response
  88.     {  
  89.         // Get the repository
  90.         $dir $this->getParameter('kernel.project_dir') . '/public/workshop_planning';
  91.         // var_dump($dir);
  92.         // Get all the files
  93.         $files glob($dir '/planning_ateliers_*.pdf');
  94.         // 
  95.         if ($files == null) {
  96.             $latestFilename null;
  97.         }
  98.         else {
  99.             
  100.             // Sort to get the more recent file
  101.             $latestFile array_reduce($files, function ($a$b) {
  102.                 return filemtime($a) > filemtime($b) ? $a $b;
  103.             });
  104.             // Get the filename + template
  105.             $latestFilename "href=workshop_planning/".basename($latestFile)." download";
  106.         }
  107.         $workshopCat $this->em->getRepository(WorkshopCategory::class)->findAll();
  108.         $workshop $this->em->getRepository(Workshop::class)->findAll();
  109.         return $this->render("website/workshop/ateliers.html.twig" , [
  110.             'partners' => $this->partnerRepository->findAll(),
  111.             'workshop' => $workshop,
  112.             'workshopCat' => $workshopCat,
  113.             'latestFilename' => $latestFilename,
  114.         ]);
  115.     }
  116.     public function actualites(): Response
  117.     {  
  118.         $article $this->articleRepository->findAllByLatest();
  119.         return $this->render("website/news/actualites.html.twig", [
  120.             'news' => $article,
  121.             'partners' => $this->partnerRepository->findAll(),
  122.         ]);
  123.     }
  124.     public function adhesions(): Response
  125.     {  
  126.         return $this->render("website/adhesions.html.twig" , [
  127.             'partners' => $this->partnerRepository->findAll(),
  128.         ]);
  129.     }
  130.     public function contact(Request $request): Response
  131.     {
  132.         $contact = new Contact();
  133.         $form $this->createForm(ContactType::class, $contact);
  134.         $form->handleRequest($request);
  135.         if ($form->isSubmitted() && $form->isValid())
  136.         {
  137.             
  138.             $this->em->persist($contact);
  139.             $okey true;
  140.             try {
  141.                 $this->em->flush();
  142.             }
  143.             catch (\Exception $e)
  144.             {
  145.                 $this->logTools->errorlog($e->getMessage());
  146.                 $okey false;
  147.             }
  148.             // Inform user of process and redirect
  149.             if ($okey)
  150.             {
  151.                 // All went well
  152.                 $request->getSession()->getFlashBag()->add('notice''event.success');
  153.             }
  154.             else
  155.             {
  156.                 // Something went wrong
  157.                 $request->getSession()->getFlashBag()->add('error''event.error');
  158.             }
  159.             return $this->redirectToRoute('contact');
  160.         }
  161.         return $this->renderForm('website/contact/contact.html.twig', [
  162.             'form'      =>  $form,
  163.             'action'    =>  'add',
  164.             'partners' => $this->partnerRepository->findAll(),
  165.             'recaptcha_site_key' => $_ENV['RECAPTCHA3_KEY']
  166.         ]);
  167.     }
  168.     public function formAdhesion(): Response
  169.     {  
  170.         return $this->render("website/formulaire.html.twig", [
  171.             'partners' => $this->partnerRepository->findAll(),
  172.         ]);
  173.     }
  174.     public function membershipAsso(Request $requestEntityManagerInterface $em): Response
  175.     {
  176.         $membershipAsso = new MembershipAsso();
  177.         $form $this->createForm(MembershipAssoTypeOut::class, $membershipAsso);
  178.         $form->handleRequest($request);
  179.         if ($form->isSubmitted() && $form->isValid())
  180.         {
  181.             $this->em->persist($membershipAsso);
  182.             $okey true;
  183.             try {
  184.                 $this->em->flush();
  185.             }
  186.             catch (\Exception $e)
  187.             {
  188.                 $this->logTools->errorlog($e->getMessage());
  189.                 $okey false;
  190.             }
  191.             // Inform user of process and redirect
  192.             if ($okey)
  193.             {
  194.                 // All went well
  195.                 $request->getSession()->getFlashBag()->add('notice''event.success');
  196.             }
  197.             else
  198.             {
  199.                 // Something went wrong
  200.                 $request->getSession()->getFlashBag()->add('error''event.error');
  201.             }
  202.             return $this->redirectToRoute('home');
  203.         }
  204.         return $formHtml $this->renderForm('/website/membership/membershipAsso.html.twig', [
  205.             'form' => $form,
  206.             'partners' => $this->partnerRepository->findAll(),
  207.         ]);        
  208.     
  209.     }
  210.     public function membershipIndi(Request $requestEntityManagerInterface $em): Response
  211.     {
  212.         $membershipIndi = new MembershipIndividual();
  213.         $form $this->createForm(MembershipIndiTypeOut::class, $membershipIndi);
  214.         $form->handleRequest($request);
  215.         if ($form->isSubmitted() && $form->isValid())
  216.         {
  217.             $this->em->persist($membershipIndi);
  218.             $okey true;
  219.             try {
  220.                 $this->em->flush();
  221.             }
  222.             catch (\Exception $e)
  223.             {
  224.                 $this->logTools->errorlog($e->getMessage());
  225.                 $okey false;
  226.             }
  227.             // Inform user of process and redirect
  228.             if ($okey)
  229.             {
  230.                 // All went well
  231.                 $request->getSession()->getFlashBag()->add('notice''event.success');
  232.             }
  233.             else
  234.             {
  235.                 // Something went wrong
  236.                 $request->getSession()->getFlashBag()->add('error''event.error');
  237.             }
  238.             return $this->redirectToRoute('home');
  239.         }
  240.         return $formHtml $this->renderForm('/website/membership/membershipIndi.html.twig', [
  241.             'form' => $form,
  242.             'partners' => $this->partnerRepository->findAll(),
  243.         ]);        
  244.     
  245.     }
  246. }
  247. // Front : Page formadhésion avec checkbox -> requete ajax à route membership avec param (asso or indi)
  248. // Back : membership -> si asso -> new MembershipAsso else new MembershipIndividual (foreach : do steps)