src/Controller/DefaultController.php line 100

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller;
  11. use App\Entity\AudioFile;
  12. use App\Entity\Candidate;
  13. use App\Entity\Commune;
  14. use App\Entity\Falc;
  15. use App\Entity\Motivation;
  16. use App\Entity\Region;
  17. use App\Entity\Theme;
  18. use App\Entity\User;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. /**
  25.  * Controller used to manage all the menu in the site.
  26.  */
  27. class DefaultController extends AbstractController
  28. {
  29.     #[Route('/'methods: ['GET'], name'intro')]
  30.     public function indexIntro(): Response
  31.     {
  32.         return $this->render('front/default/intro.html.twig');
  33.     }
  34.     #[Route('/search/{election_type}'methods: ['GET'], name'homepage')]
  35.     public function search(Request $requestEntityManagerInterface $entityManager): Response
  36.     {
  37.         $election_type $request->get('election_type');
  38.         $regions $entityManager->getRepository(Region::class)->findAll();
  39.         return $this->render('front/default/homepage.html.twig',[
  40.             'regions' => $regions,
  41.             'election_type' => $election_type
  42.         ]);
  43.     }
  44.     #[Route('/cam'methods: ['GET'], name'cam_home')]
  45.     public function showCamera(Request $request): Response
  46.     {
  47.         return $this->render('front/default/cam_page.html.twig');
  48.     }
  49.     #[Route('/front/regions/{election_type}/candidates/{region}'methods: ['GET'], name'app_region_candidates')]
  50.     public function candidatesOfRegion(
  51.         Request $request,
  52.         EntityManagerInterface $entityManager
  53.     ): Response
  54.     {
  55.         $candidates null;
  56.         $communes null;
  57.         $region_id $request->get('region');
  58.         $election_type $request->get('election_type');
  59.         $regions $entityManager->getRepository(Region::class)->findAll();
  60.         if ($election_type == 'MUNICIPALE'){
  61.             $current_region $entityManager->getRepository(Region::class)->find($region_id);
  62.             return $this->redirectToRoute('app_commune_candidates',
  63.                 array(
  64.                 'commune' => 2,
  65.                 'region' => $current_region->getId()
  66.             ));
  67.         }elseif ($election_type == 'REGIONALE'){
  68.             $current_region $entityManager->getRepository(Region::class)->find($region_id);
  69.         }else{
  70.             throw $this->createNotFoundException('Aucune circonscription de ce id existe');
  71.         }
  72.         if($current_region instanceof Region) {
  73.             $candidates $entityManager->getRepository(Candidate::class)->findBy(array('region'=>$current_region));
  74.         }
  75.         if($current_region instanceof Commune) {
  76.             $candidates $entityManager->getRepository(Candidate::class)->findBy(array('commune'=>$current_region));
  77.         }
  78.         return $this->render('front/candidate/list.html.twig',[
  79.             'candidates' => $candidates,
  80.             'election_type' => $election_type,
  81.             'communes' => $communes,
  82.             'current_region' => $current_region,
  83.             'regions' => $regions
  84.         ]);
  85.     }
  86.     #[Route('/front/commune/{region}/candidates/{commune}'methods: ['GET'], name'app_commune_candidates')]
  87.     public function candidatesOfCommune(
  88.         Request $request,
  89.         EntityManagerInterface $entityManager
  90.     ): Response
  91.     {
  92.         if ($request->get('region')){
  93.             $current_region $entityManager->getRepository(Region::class)->find($request->get('region'));
  94.         }
  95.         $communes $entityManager->getRepository(Commune::class)->findBy(array('region'=>$request->get('region')));
  96.         if ($request->get('commune')){
  97.             $current_commune $entityManager->getRepository(Commune::class)->find($request->get('commune'));
  98.         }
  99.         if ($current_commune!=null and $current_commune instanceof Commune){
  100.             $candidates $entityManager->getRepository(Candidate::class)->findBy(array('commune'=>$current_commune));
  101.         }
  102.         return $this->render('front/candidate/list.html.twig',[
  103.             'candidates' => $candidates,
  104.             'communes' => $communes,
  105.             'current_commune' => $current_commune,
  106.             'current_region' => $current_region
  107.         ]);
  108.     }
  109.     #[Route('front/motivation/{id}'name'app_front_motivation_show'methods: ['GET'])]
  110.     public function showMotivation(EntityManagerInterface $entityManagerMotivation $motivation): Response
  111.     {
  112.         if (empty($motivation)){
  113.             throw $this->createNotFoundException('La profession de foi est inexistante');
  114.         }
  115.         $user $this->getCurrentUser($entityManager$motivation);
  116.         if ($user instanceof User){
  117.             $candidate $user->getCandidate();
  118.         }
  119.         $audioFiles $entityManager->getRepository(AudioFile::class)->findBy(array('motivation'=>$candidate->getMotivation()));
  120.         $profilePicFileName $candidate->getMotivation()->getProfilePicFileName();
  121.         return $this->render('front/motivation/show.html.twig', [
  122.             'user' => $user,
  123.             'candidate' => $candidate,
  124.             'audioFiles' => $audioFiles,
  125.             'profilePicFileName' => $profilePicFileName
  126.         ]);
  127.     }
  128.     #[Route('front/theme/{id}'name'app_front_theme_show'methods: ['GET'])]
  129.     public function showTheme(Theme $theme,
  130.                               EntityManagerInterface $entityManager): Response
  131.     {
  132.         $falc $theme->getFalc();
  133.         if ($falc){
  134.             $candidate $entityManager->getRepository(Candidate::class)->findOneBy(array('falc'=>$falc));
  135.         }
  136.         $user $this->getCurrentUser($entityManager$theme);
  137.         if ($user instanceof User){
  138.             $candidate $user->getCandidate();
  139.         }
  140.         $audioFiles $entityManager->getRepository(AudioFile::class)->findBy(array('theme'=>$theme));
  141.         $themePicFileName $theme->getThemePicFileName();
  142.         return $this->render('front/theme/show.html.twig', [
  143.             'user' => $user,
  144.             'candidate' => $candidate,
  145.             'theme' => $theme,
  146.             'audioFiles' => $audioFiles,
  147.             'themePicFileName' => $themePicFileName
  148.         ]);
  149.     }
  150.     #[Route('/front/{id}/falc'methods: ['GET'], name'app_fiche_falc_show')]
  151.     public function getFfalc(Falc $falc,
  152.                              EntityManagerInterface $entityManager): Response
  153.     {
  154.         $candidate $entityManager->getRepository(Candidate::class)->findOneBy(array('falc' => $falc));
  155.         $themes $entityManager->getRepository(Theme::class)->findBy(array('falc' => $falc));
  156.         $arrData = array();
  157.         if (!empty($themes)){
  158.             foreach ($themes as $theme) {
  159.                 $audioFiles $entityManager->getRepository(AudioFile::class)->findBy(array('theme'=>$theme));
  160.                 //$themePicFileName = $theme->getThemePicFileName();
  161.                 $arrData[] = array('theme'=>$theme'audioFiles'=>$audioFiles'videoFiles'=>null);
  162.             }
  163.         }
  164.         return $this->render('front/falc/show.html.twig',[
  165.             'falc' => $falc,
  166.             'arrData' => $arrData,
  167.             'candidate' =>$candidate
  168.         ]);
  169.     }
  170.     public function getCurrentUser(EntityManagerInterface $entityManager$object_type)
  171.     {
  172.         if ($object_type instanceof Motivation){
  173.             $candidate $entityManager->getRepository(Candidate::class)->findOneBy(array('motivation'=>$object_type));
  174.         }
  175.         if ($object_type instanceof Theme){
  176.             $falc $object_type->getFalc();
  177.             $candidate $entityManager->getRepository(Candidate::class)->findOneBy(array('falc'=>$falc));
  178.         }
  179.         if (!empty($candidate)){
  180.             $user $entityManager->getRepository(User::class)->findOneBy(array('candidate'=>$candidate));
  181.         }
  182.         return $user;
  183.     }
  184. }