src/Controller/DefaultController.php line 290

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\Pagina;
  7. use App\Entity\General;
  8. use App\Entity\General2;
  9. use App\Entity\DarreraHora;
  10. use App\Entity\Galeries;
  11. use App\Entity\Fotos;
  12. use App\Entity\VideosYoutube;
  13. use App\Entity\Pestanyes;
  14. use App\Entity\FotosHome;
  15. use Dp\CalendarBundle\Entity\Item;
  16. use Symfony\Component\Translation\LocaleSwitcher;
  17. use Symfony\Component\Security\Core;
  18. use Symfony\Component\Security\Core\Security;
  19. use Twig\Sandbox\SecurityError;
  20. use App\Entity\Usuari;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Cookie;
  24. use Symfony\Component\Security\Core\SecurityContext;
  25. use Symfony\Component\HttpFoundation\Session\Session;
  26. class DefaultController extends AbstractController
  27. {
  28.     private $em;
  29.     public function __construct(private LocaleSwitcher $localeSwitcherEntityManagerInterface $em)
  30.     {
  31.         $this->em $em;
  32.     }
  33.     #/[Route('/', name: 'app_default_index')]
  34.     public function indexAction(Request $peticion)
  35.     {
  36.         $session $peticion->getSession();
  37.         $session->start();
  38.         
  39.         $repository $this->em->getRepository(Pagina::class);
  40.         /////////////////////////////////: Response
  41.         // la plana amb l'id 1 és la home
  42.         /////////////////////////////////
  43.         $pagina $repository->getPagina(1);
  44.         /////////////////////////
  45.         // Recull valors generals
  46.         /////////////////////////
  47.         $objGeneral $this->em->getRepository(General::class)->findAll();
  48.         $objGeneral2 $this->em->getRepository(General2::class)->findAll();
  49.         $aGeneral['iMin'] = $aGeneral['iMax'] = $objGeneral[0]->getMasellaCm();
  50.         
  51.         if ($objGeneral[0]->getBoscCm() != '')
  52.         {
  53.             if ($objGeneral[0]->getBoscCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getBoscCm();
  54.             if ($objGeneral[0]->getBoscCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getBoscCm();
  55.         }
  56.         if ($objGeneral[0]->getTosaCm() != '')
  57.         {
  58.             if ($objGeneral[0]->getTosaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $objGeneral[0]->getTosaCm();
  59.             if ($objGeneral[0]->getTosaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $objGeneral[0]->getTosaCm();
  60.         }
  61.         ////////////////////////////////
  62.         // Opcions del calaix de la home
  63.         ////////////////////////////////
  64.         $iClassBox 0;
  65.         if ($objGeneral[0]->getWebcamVisible()) $iClassBox++;
  66.         if ($objGeneral[0]->getMeteoVisible()) $iClassBox++;
  67.         if ($objGeneral[0]->getPistesVisible()) $iClassBox++;
  68.         if ($objGeneral[0]->getRemuntadorsVisible()) $iClassBox++;
  69.         if ($objGeneral[0]->getDesnivellVisible()) $iClassBox++;
  70.         if ($objGeneral[0]->getGruixVisible()) $iClassBox++;
  71.         if ($objGeneral[0]->getQualitatVisible()) $iClassBox++;
  72.         
  73.         if ($iClassBox == 7$iClassBox 13;
  74.         else
  75.         {
  76.             if ($iClassBox != 0)
  77.                 $iClassBox 12 $iClassBox;
  78.         }
  79.         
  80.         $blDarrera_hora false;
  81.         foreach ($pagina->getBlocs() as $key => $val)
  82.         {
  83.             if ($val->getTipus()->getSlug() == 'darrera_hora')
  84.             {
  85.                 $blDarrera_hora true;
  86.             }
  87.         }
  88.         
  89.         $objDarreraHora = array();
  90.         if ($blDarrera_hora)
  91.         {
  92.             $aSort = array("data" => "DESC");
  93.             $aParam = array();
  94.             
  95.             $objDarreraHora $this->em->getRepository(DarreraHora::class)->findBy($aParam,$aSort,5);
  96.         }
  97.         ///////////////
  98.         // Foto del dia
  99.         ///////////////
  100.         $sFotoDelDia = array();
  101.         $aParam = array('individual' => '1');
  102.         
  103.         $enFoto = array();
  104.         $enGaleries $this->em->getRepository(Galeries::class)->findOneBy($aParam);
  105.         if ($enGaleries)
  106.         {
  107.             $aParam = array('galeries' => $enGaleries);
  108.             $enFoto $this->em->getRepository(Fotos::class)->findBy($aParam, array('fecha'=>'DESC'));
  109.             
  110.             if ($enFoto)
  111.             {
  112.                 $sFotoDelDia['url'] = $enFoto[0]->getRutaImagen();
  113.                 $sFunctionName 'getDescripcio' ucfirst($peticion->getLocale());
  114.                 $sFotoDelDia['nom'] = $enFoto[0]->$sFunctionName();
  115.                 $sFotoDelDia['fecha'] = $enFoto[0]->getFecha();
  116.             }
  117.         }
  118.         $aParam = array('galeries' => $pagina->getGaleries());
  119.         $fotos $this->em->getRepository(Fotos::class)->findBy($aParam, array('orden'  => 'ASC'),null);
  120.         
  121.         ///////////////////////////////////
  122.         // Això es Masella TV al backoffice
  123.         ///////////////////////////////////
  124.         $aParam = array(    'destacat'  => 1
  125.                             'actiu'     => 1);
  126.         
  127.         $aVideoYoutubeDestacat $this->em->getRepository(VideosYoutube::class)->findBy($aParam);
  128.         
  129.         $aParam = array(    'destacat_central'  => 1
  130.                             'actiu'             => 1);
  131.         
  132.         $aVideoYoutubeDestacatCentral $this->em->getRepository(VideosYoutube::class)->findBy($aParam);
  133.         ////////////
  134.         // Pestanyes
  135.         ////////////
  136.         $enPestanyes $this->em->getRepository(Pestanyes::class)->findBy(
  137.             array(  'visible'   => 1),
  138.             array(  'ordre'     => 'ASC'));
  139.         $enFotosHome $this->em->getRepository(FotosHome::class)->findBy(
  140.             array(),
  141.             array(  'orden'     => 'ASC'));
  142.         return $this->render('index.html.twig',array(
  143.             'pagina'                        => $pagina,
  144.             'esHome'                        => 1,
  145.             'fotos'                         => $fotos,
  146.             'objDarreraHora'                => $objDarreraHora,
  147.             'aGeneral'                      => $aGeneral,
  148.             'general'                       => $objGeneral[0],
  149.             'general2'                      => $objGeneral2[0],
  150.             'videoYoutubeDestacatCentral'   => (array_key_exists('0'$aVideoYoutubeDestacatCentral)?$aVideoYoutubeDestacatCentral[0]:array()),
  151.             'VideoYoutubeDestacat'          => (array_key_exists('0'$aVideoYoutubeDestacat)?$aVideoYoutubeDestacat[0]:array()),
  152.             'entMenu'                       => array(),
  153.             'iClassBox'                     => $iClassBox,
  154.             'sFotoDelDia'                   => $sFotoDelDia,
  155.             'enFoto'                        => $enFoto,
  156.             'enPestanyes'                   => $enPestanyes,
  157.             'enFotosHome'                   => $enFotosHome
  158.         ));
  159.     }
  160.     
  161.     public function menuListAction($isMobileVersion=false)
  162.     {
  163.         $repository $this->getDoctrine()->getRepository(Pagina::class);
  164.         $list $repository->getSecciones();
  165.         
  166.         return $this->render('menuList.html.twig', array(
  167.             "isMobileVersion"   => $isMobileVersion
  168.             "list"              => $list
  169.         ));
  170.     }
  171.     
  172.     /**
  173.      * Només visible per dev
  174.      *
  175.      * @param string $email
  176.      * @param string $password
  177.      * @return \App\Controller\Response
  178.      */
  179.     public function createUserAction($email$password
  180.     {
  181.         $factory $this->get('security.encoder_factory');
  182.         $user = new Usuari();
  183.         $encoder $factory->getEncoder($user);
  184.         $user->setSalt(md5(time()));
  185.         $pass $encoder->encodePassword($password$user->getSalt());
  186.         $user->setEmail($email);
  187.         $user->setPassword($pass);
  188.         $user->setActivat(1);
  189.         $this->em->persist($user);
  190.         $this->em->flush();
  191.         return new Response('Usuari creat!');
  192.     }
  193.     
  194.     /**
  195.      * Funciona para limpiar la cache de produccion
  196.      * 
  197.      * @return Response
  198.      */
  199.     public function limpiaCacheAction()
  200.     {
  201.         if ($_SERVER['SERVER_NAME'] == 'www.masella.com'
  202.                 || $_SERVER['SERVER_NAME'] == 'beta.masella.com')
  203.         {
  204.             $sResposta shell_exec("/opt/plesk/php/7.3/bin/php ../app/console assets:install");
  205.             echo '1<pre>' $sResposta '</pre>';
  206.             $sResposta shell_exec("chmod -R 777 ../app/cache/ ../app/logs/");
  207.             echo '2<pre>' $sResposta '</pre>';
  208.             $sResposta shell_exec("/opt/plesk/php/7.3/bin/php ../app/console cache:clear --env=prod");
  209.             echo '3<pre>' $sResposta '</pre>';
  210.         } else {
  211.             $sResposta shell_exec("php ../app/console assets:install");
  212.             echo '1<pre>' $sResposta '</pre>';
  213.             $sResposta shell_exec("chmod -R 777 ../app/cache/ ../app/logs/");
  214.             echo '2<pre>' $sResposta '</pre>';
  215.             $sResposta shell_exec("php ../app/console cache:clear --env=prod");
  216.             echo '3<pre>' $sResposta '</pre>';
  217.         }
  218.         return new Response("Cielo de junio, limpio como ninguno!");
  219.     }
  220.     /**
  221.      * @param Request $request
  222.      * @return Response
  223.      */
  224.     public function loginAction(Request $request)
  225.     {
  226.         $session $request->getSession();
  227.         //////////////////////////////////////
  228.         // get the login error if there is one
  229.         //////////////////////////////////////
  230.         if ($request->attributes->has(Security::AUTHENTICATION_ERROR))
  231.         {
  232.             $error $request->attributes->get(Security::AUTHENTICATION_ERROR);
  233.         } else {
  234.             $error $session->get(Security::AUTHENTICATION_ERROR);
  235.             $session->remove(Security::AUTHENTICATION_ERROR);
  236.         }
  237.         return $this->render('login.html.twig', array(
  238.             'last_username' => $session->get(Security::LAST_USERNAME),
  239.             'error'         => $error,
  240.             )
  241.         );
  242.     }
  243.     /**
  244.      * @param $pagina
  245.      * @return Response
  246.      */
  247.     public function getPaginaSlugAction($pagina)
  248.     {
  249.         $entity $this->em->getRepository(Pagina::class)->find($pagina);
  250.         return new Response($entity->getSlug($this->localeSwitcher->getLocale()));
  251.     }
  252.     
  253.     public function cookiesAction(Request $request)
  254.     {
  255.         $value $request->cookies->get('cookie_accepted');
  256.         
  257.         if ($value != 'si'
  258.         {
  259.             return $this->render('cookies.html.twig');
  260.         } else {
  261.             return new Response();            
  262.         }
  263.     }
  264.     public function cookiesGoogleAnalyticsAction(Request $request)
  265.     {
  266.         $value $request->cookies->get('cookie_accepted_google_analytics');
  267.         
  268.         if ($value == 'si')
  269.         {
  270.             return new Response('<!-- Global site tag (gtag.js) - Google Analytics -->'
  271.                     '<!-- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-4478510-1"></script> -->'
  272.                     '<script src="/frontoffice/js/googleAnalytics.js?v2"></script>'
  273.                     '<script async src="https://www.googletagmanager.com/gtag/js?id=G-1CJZZCQC36"></script>'
  274.                     '<script src="/frontoffice/js/googleAnalytics2.js?v2"></script>'
  275.             );
  276.         } else {
  277.             return new Response();            
  278.         }
  279.     }
  280.     /**
  281.      * @param Request $request
  282.      * @return Response
  283.      */
  284.     public function cookiesGoogleAnalyticsBodyAction(Request $request): Response
  285.     {
  286.         $value $request->cookies->get('cookie_accepted_google_analytics');
  287.         if ($value == 'si')
  288.         {
  289.             return new Response('<!-- Google Tag Manager (noscript) -->'
  290.                     '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-THMVSV8" '
  291.                     'height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'
  292.                     '<!-- End Google Tag Manager (noscript) -->');
  293.         } else {
  294.             return new Response();            
  295.         }
  296.     }
  297.     
  298.     public function appAction(Request $request)
  299.     {
  300.         $response = new Response();
  301.         $value $request->cookies->get('cookie_app');
  302.         /*
  303.         if ($value!='si') {
  304.             $cookie = new Cookie('cookie_app', 'si', time() + 365 * 3600 * 24 * 7);
  305.             $response->headers->setCookie($cookie);
  306.             $response->send();
  307.             
  308.             return $this->render('app.html.twig');
  309.         } else {
  310.             return new Response();
  311.         }
  312.         */
  313.         return new Response();            
  314.     }
  315.     public function aceptarCookieAction(Request $request)
  316.     {
  317.         $cookie = new Cookie('cookie_accepted''si'time() + 365 3600 24 7);
  318.         $response = new Response();
  319.         $response->headers->setCookie($cookie);
  320.         
  321.         return $response->send();
  322.     }
  323.     public function aceptarCookieGoogleAnalyticsAction(Request $request)
  324.     {
  325.         $cookie = new Cookie('cookie_accepted_google_analytics''si'time() + 365 3600 24 7);
  326.         $response = new Response();
  327.         $response->headers->setCookie($cookie);
  328.         
  329.         return $response->send();
  330.     }
  331.     public function eliminarCookiesAction(Request $request)
  332.     {
  333.         $cookie = new Cookie('cookie_accepted_google_analytics'''time() - 3600'/');
  334.         // Crear cookies amb una data d'expiració en el passat per eliminar-les
  335.         $gaCookie = new Cookie('_ga'''time() - 3600'/');
  336.         $gidCookie = new Cookie('_gid'''time() - 3600'/');
  337.         $gatCookie = new Cookie('_gat'''time() - 3600'/');
  338.         $response = new Response();
  339.         $response->headers->setCookie($cookie);
  340.         // Afegir les cookies als encapçalaments de la resposta per eliminar-les
  341.         $response->headers->setCookie($gaCookie);
  342.         $response->headers->setCookie($gidCookie);
  343.         $response->headers->setCookie($gatCookie);
  344.         return $response->send();
  345.     }
  346.     public function getBasesSlugAction()
  347.     {
  348.         $pagina $this->getParameter("PAGE_ID_BASES");
  349.         
  350.         return $this->getPaginaSlugAction($pagina);
  351.     }
  352.     
  353.     public function getPrivacitatSlugAction()
  354.     {
  355.         $pagina=$this->getParameter("PAGE_ID_PRIVACITAT");
  356.         
  357.         return $this->getPaginaSlugAction($pagina);
  358.     }
  359.     public function getPrivacitatEscolaSlugAction()
  360.     {
  361.         $pagina=$this->getParameter("PAGE_ID_PRIVACITAT_ESCOLA");
  362.         return $this->getPaginaSlugAction($pagina);
  363.     }
  364.     public function getCondicionsGeneralsSlugAction()
  365.     {
  366.         $pagina=$this->getParameter("PAGE_ID_CONDICIONS_GENERALS");
  367.         
  368.         return $this->getPaginaSlugAction($pagina);
  369.     }
  370.     public function getCondicionsGeneralsEscolaSlugAction()
  371.     {
  372.         $pagina=$this->getParameter("PAGE_ID_CONDICIONS_GENERALS_ESCOLA");
  373.         return $this->getPaginaSlugAction($pagina);
  374.     }
  375.     public function getPoliticaSlugAction()
  376.     {
  377.         $pagina=$this->getParameter("PAGE_ID_AVIS_LEGAL");
  378.         
  379.         return $this->getPaginaSlugAction($pagina);
  380.     }
  381.     public function getPoliticaEscolaSlugAction()
  382.     {
  383.         $pagina=$this->getParameter("PAGE_ID_AVIS_LEGAL_ESCOLA");
  384.         return $this->getPaginaSlugAction($pagina);
  385.     }
  386.     public function getCookiesSlugAction()
  387.     {
  388.         $pagina=$this->getParameter("PAGE_ID_COOKIES");
  389.         
  390.         return $this->getPaginaSlugAction($pagina);
  391.     }
  392.     
  393.     public function getAppSlugAction(): Response
  394.     {
  395.         $pagina $this->getParameter("PAGE_ID_APP");
  396.         return $this->getPaginaSlugAction($pagina);
  397.     }
  398.     
  399.     public function getMapaPistesSlugAction()
  400.     {
  401.         $pagina $this->getParameter("PAGE_ID_MAPA_PISTES");
  402.         return $this->getPaginaSlugAction($pagina);
  403.     }
  404.     
  405.     public function getNocturnSlugAction()
  406.     {
  407.         $pagina $this->getParameter("PAGE_ID_NOCTURN");
  408.         return $this->getPaginaSlugAction($pagina);
  409.     }
  410.     
  411.     public function getAllotjamentSlugAction()
  412.     {
  413.         $pagina $this->getParameter("PAGE_ID_ALLOTJAMENT");
  414.         return $this->getPaginaSlugAction($pagina);
  415.     }
  416.     
  417.     public function getDenunciaSlugAction()
  418.     {
  419.         $pagina $this->getParameter("PAGE_ID_DENUNCIA");
  420.         
  421.         return $this->getPaginaSlugAction($pagina);
  422.     }
  423.     public function getPromoSlugAction()
  424.     {
  425.         $pagina 111;
  426.         return $this->getPaginaSlugAction($pagina);
  427.     }
  428.     /**
  429.      * Funciona para limpiar la cache de produccion
  430.      * 
  431.      * @return Response
  432.      */
  433.     public function cronVideosYoutubeAction()
  434.     {
  435.         ////////////////////////////////////////////////////////
  436.         // Si es dissabte al migdia es desmarca el vidio central
  437.         ////////////////////////////////////////////////////////
  438.         echo 'Dia (' date("w") . ') i hora (' date("G") . ')';
  439.         echo '<br>';
  440.         if (date("w") == 
  441.                 && date("G") >= '8')
  442.         {
  443.             $sQuery =   "UPDATE App:VideosYoutube p SET "
  444.                                 " p.destacat_central = :destacat_central"
  445.                                 " WHERE p.destacat_central = :destacat_central_where";
  446.             $query $this->em->createQuery($sQuery)
  447.                 ->setParameter('destacat_central'0)
  448.                 ->setParameter('destacat_central_where'1);
  449.             $enVideosYoutube $query->getResult();
  450.             echo 'Desativat destacat central';
  451.             echo '<br>';
  452.         } else {
  453.             echo "No s'ha desativat destacat central";
  454.             echo '<br>';
  455.         }
  456.         
  457.         return new Response("Desactivar destacat central VideosYoutube");
  458.     }
  459. }