src/Controller/FootController.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Entity\General;
  7. use App\Entity\Pistes;
  8. use App\Entity\Sponsors;
  9. use App\Util\Util;
  10. use App\Entity\Usuari;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. //use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  14. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  15. use Symfony\Component\Security\Core\SecurityContext;
  16. use Symfony\Component\Translation\LocaleSwitcher;
  17. class FootController extends AbstractController
  18. {
  19.     private $em;
  20.     /**
  21.      * @param LocaleSwitcher $localeSwitcher
  22.      * @param EntityManagerInterface $em
  23.      */
  24.     public function __construct(private LocaleSwitcher $localeSwitcherEntityManagerInterface $em)
  25.     {
  26.         $this->em $em;
  27.     }
  28.     /**
  29.      * @param Request $peticion
  30.      * @return Response
  31.      */
  32.     public function indexAction(Request $peticion): Response
  33.     {
  34.         $objUtil = new Util($this->em);
  35.         $objGeneral $this->em->getRepository(General::class)->findAll();
  36.         
  37.         $aGeneral['iMin'] = $aGeneral['iMax'] = $objGeneral[0]->getMasellaCm();
  38.         
  39.         if ($objGeneral[0]->getBoscCm() != '')
  40.         {
  41.             if ($objGeneral[0]->getBoscCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getBoscCm();
  42.             if ($objGeneral[0]->getBoscCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getBoscCm();
  43.         }
  44.         if ($objGeneral[0]->getTosaCm() != '')
  45.         {
  46.             if ($objGeneral[0]->getTosaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getTosaCm();
  47.             if ($objGeneral[0]->getTosaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getTosaCm();
  48.         }
  49.         
  50.         $query $this->em->createQuery(
  51.                                 'SELECT p
  52.                                 FROM App\Entity\Pistes p
  53.                                 WHERE (p.estatDia = :estat_dia
  54.                                 OR p.estatNit = :estat_nit) 
  55.                                 AND p.pista_relacionada is null 
  56.                                 '
  57.         )->setParameter('estat_dia''1')->setParameter('estat_nit''1');
  58.         $enPistes $query->getResult();
  59.         $query $this->em->createQuery(
  60.                                 'SELECT p
  61.                                 FROM App\Entity\Remuntadors p
  62.                                 WHERE p.estatDia = :estat_dia
  63.                                 OR p.estatNit = :estat_nit
  64.                                 '
  65.         )->setParameter('estat_dia''1')->setParameter('estat_nit''1');
  66.         $enRemuntadors $query->getResult();
  67.         
  68.         // Sponsors
  69.         $enSponsors $this->em->getRepository(Sponsors::class)->findBy(
  70.             array(
  71.                 'visible'   => 1
  72.             ),
  73.             array(
  74.                 'ordre'     => 'ASC'
  75.             )
  76.         );
  77.         $aValors $objUtil->aValors;
  78.         $sUrl $_SERVER['REQUEST_URI'];
  79.         $bEscola false;
  80.         if (strpos($sUrl'pagina') !== false)
  81.         {
  82.             foreach ($aValors as $sValor)
  83.             {
  84.                 if (strpos($sUrl$sValor) !== false)
  85.                 {
  86.                     $bEscola true;
  87.                     break;
  88.                 }
  89.             }
  90.         }
  91.         return $this->render(
  92.             'foot.html.twig',
  93.             array(
  94.                 'aGeneral'              => $aGeneral,
  95.                 'general'               => $objGeneral[0],
  96.                 'totalPistes'           => count($enPistes),
  97.                 'totalRemuntadors'      => count($enRemuntadors),
  98.                 'enSponsors'            => $enSponsors,
  99.                 'bEscola'               => $bEscola
  100.                 )
  101.         );
  102.     }
  103.     /**
  104.      * @param Request $peticion
  105.      * @return Response
  106.      */
  107.     public function meteoAction(Request $peticion)
  108.     {
  109.         $objGeneral $this->em->getRepository(General::class)->findAll();
  110.         
  111.         $aGeneral['iMin'] = $aGeneral['iMax'] = $objGeneral[0]->getMasellaCm();
  112.         
  113.         if ($objGeneral[0]->getBoscCm() != '')
  114.         {
  115.             if ($objGeneral[0]->getBoscCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getBoscCm();
  116.             if ($objGeneral[0]->getBoscCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getBoscCm();
  117.         }
  118.         if ($objGeneral[0]->getTosaCm() != '')
  119.         {
  120.             if ($objGeneral[0]->getTosaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getTosaCm();
  121.             if ($objGeneral[0]->getTosaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getTosaCm();
  122.         }
  123.         
  124.         $query $this->em->createQuery(
  125.                                 'SELECT p
  126.                                 FROM App\Entity\Pistes p
  127.                                 WHERE (p.estatDia = :estat_dia
  128.                                 OR p.estatNit = :estat_nit) 
  129.                                 AND p.pista_relacionada is null 
  130.                                 '
  131.         )->setParameter('estat_dia''1')->setParameter('estat_nit''1');
  132.         $enPistes $query->getResult();
  133.         $query $this->em->createQuery(
  134.                                 'SELECT p
  135.                                 FROM App\Entity\Remuntadors p
  136.                                 WHERE p.estatDia = :estat_dia
  137.                                 OR p.estatNit = :estat_nit
  138.                                 '
  139.         )->setParameter('estat_dia''1')->setParameter('estat_nit''1');
  140.         $enRemuntadors $query->getResult();
  141.         
  142.         // Sponsors
  143.         $enSponsors $this->em->getRepository(Sponsors::class)->findBy(
  144.             array(
  145.                 'visible'   => 1
  146.             ),
  147.             array(
  148.                 'ordre'     => 'ASC'
  149.             )
  150.         );
  151.         return $this->render(
  152.             'foot_meteo.html.twig',
  153.             array(
  154.                 'aGeneral'              => $aGeneral,
  155.                 'general'               => $objGeneral[0],
  156.                 'totalPistes'           => count($enPistes),
  157.                 'totalRemuntadors'      => count($enRemuntadors),
  158.                 'enSponsors'            => $enSponsors,
  159.                 )
  160.         );
  161.     }
  162. }