src/Controller/InfoneuController.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\General;
  4. use App\Entity\Sidebar;
  5. use App\Entity\Sponsors;
  6. use App\Entity\Usuari;
  7. use App\Entity\Meteo;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  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\Mailer\MailerInterface;
  16. use Symfony\Component\Security\Core\Security;
  17. use Symfony\Component\Security\Core\SecurityContext;
  18. use App\Entity\Temps;
  19. use Symfony\Component\Translation\LocaleSwitcher;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class InfoneuController extends AbstractController 
  22. {
  23.     private $em;
  24.     private $objUtil;
  25.     private $session;
  26.     private $mailer;
  27.     private $translator;
  28.     private $sPathUploads;
  29.     public function __construct(private LocaleSwitcher $localeSwitcherEntityManagerInterface $em,Security $security,TranslatorInterface $translator,RequestStack $requestStack,MailerInterface $mailer)
  30.     {
  31.         $this->em $em;
  32.         $this->objUtil = new \App\Util\Util($this->em);
  33.         $this->mailer $mailer;
  34.         $this->session $requestStack->getSession();
  35.         $this->translator $translator;
  36.         $this->sPathUploads =  realpath(dirname(__FILE__)) . '/../../public/uploads/';
  37.     }
  38.     public function indexAction(Request $peticion)
  39.     {
  40.         $aRequest $peticion->request;
  41.         /////////////////////////
  42.         // Recoger dades generals
  43.         ////////////////////////
  44.         $enGeneral $this->em->getRepository(General::class)->findAll();
  45.         $query $this->em->createQuery(
  46.                                 'SELECT p
  47.                                 FROM App:Pistes p 
  48.                                 WHERE p.estatDia = :estat_dia
  49.                                 AND p.pista_relacionada is null 
  50.                                 ORDER BY p.zones ASC
  51.                                 '
  52.         )->setParameter('estat_dia''1');
  53.         $enPistes $query->getResult();
  54.         $iTotalLongitudPises 0;
  55.         $aZones = array();
  56.         $aPistes = array();
  57.         
  58.         foreach ($enPistes as $key => $val)
  59.         {
  60.             $iTotalLongitudPises $iTotalLongitudPises $val->getLongitud();
  61.             $sFuntion 'getNom' ucfirst($peticion->attributes->get('_locale'));
  62.             $iIndex 0;
  63.             //echo '-' . $val->getZones() . '-';
  64.             if (array_key_exists($val->getZones()->getNom() . ''$aPistes))
  65.             {
  66.                 $iIndex count($aPistes[$val->getZones()->getNom() . '']);
  67.             } else {
  68.                $aZones[] = $val->getZones()->getNom(); 
  69.             }
  70.             $aPistes[$val->getZones()->getNom() . ''][$iIndex]['nom'] = $val->$sFuntion();
  71.             $aPistes[$val->getZones()->getNom() . ''][$iIndex]['color'] = (method_exists($val->getColors(), 'getCodi')?$val->getColors()->getCodi():'000');
  72.             
  73.         }
  74.         
  75.         $query $this->em->createQuery(
  76.                                 'SELECT p
  77.                                 FROM App:Remuntadors p
  78.                                 WHERE p.estatDia = :estat_dia
  79.                                 ORDER BY p.remuntadorsTipus ASC
  80.                                 '
  81.         )->setParameter('estat_dia''1');
  82.         $enRemuntadors $query->getResult();
  83.         
  84.         $aTipus = array();
  85.         $aRemuntadors = array();
  86.         foreach ($enRemuntadors as $key => $val)
  87.         {
  88.             $sFuntion 'getNom' ucfirst($peticion->attributes->get('_locale'));
  89.             $iIndex 0;
  90.             //echo '-' . $val->getRemuntadorsTipus() . '-';
  91.             if (array_key_exists($val->getRemuntadorsTipus()->$sFuntion() . ''$aRemuntadors))
  92.             {
  93.                 $iIndex count($aRemuntadors[$val->getRemuntadorsTipus()->$sFuntion() . '']);
  94.             } else {
  95.                $aTipus[] = $val->getRemuntadorsTipus()->$sFuntion(); 
  96.             }
  97.             $aRemuntadors[$val->getRemuntadorsTipus()->$sFuntion() . ''][$iIndex] = $val->getNom();
  98.            // echo $val->getNom();
  99.         }
  100.         $sFecha $this->translator->trans(date("l")) . ', ' date("d") . ' ' $this->translator->trans('of ' date("F")) . ' ' $this->translator->trans('de') . ' ' date("Y");
  101.         if (
  102.                 (date("G") < 
  103.                 && (date('W') == 
  104.                 || date('W') == 6
  105.                 ) 
  106.             ||
  107.                 (
  108.                     date("G") < 8
  109. //                    ||
  110. //                    (
  111. //                        date("G") == 8
  112. //                        && date("i") < 30
  113. //                    )
  114.                     && 
  115.                     (
  116.                         date('W') != 
  117.                         && date('W') != 6
  118.                     
  119.                 )
  120.             || date("G") > 15
  121.         )
  122.         {
  123.             if (date("G") > 15)
  124.             {
  125.                 $date strtotime("+1 day");
  126.                 $sFecha $this->translator->trans(date("l"$date)) . ', ' date("d"$date) . ' ' $this->translator->trans('of ' date("F"$date)) . ' ' $this->translator->trans('de') . ' ' date("Y"$date);
  127.             }
  128.             $sFecha $this->translator->trans("PREVISIÓ PEL") . ' ' $sFecha;
  129.         }
  130.         
  131.         $enTemps $this->em->getRepository(Temps::class)->findBy(
  132.             array(),
  133.             array(  'data'  => 'DESC'),
  134.             3
  135.         );
  136.         
  137.         if (date("G") <= 15)
  138.         {
  139.             unset($enTemps[2]);
  140.         }
  141.         
  142.         $fecha date('y/m/d');
  143.         
  144.         $sQuery "SELECT p "
  145.                 " FROM App:PrediccioMeteo p "
  146.                 " WHERE ";
  147.         /*
  148.         if (date('h') >= 18)
  149.         {
  150.             $sQuery .= " p.data > :now ";
  151.         } else {
  152.             $sQuery .= " p.data >= :now ";
  153.         } 
  154.          * 
  155.          */
  156.         $sQuery .= " p.data = :now ";
  157.         $sQuery .= " ORDER BY p.data ASC";
  158.         $query $this->em->createQuery($sQuery);
  159.         $query->setParameter('now'$fecha);
  160.         $enPrediccioMeteo $query->getResult();
  161.         $enMeteo $this->em->getRepository(Meteo::class)->findAll();
  162.         
  163.         foreach ($enMeteo as $aMeteoPartial)
  164.         {
  165.             $aMeteo[$aMeteoPartial->getCodi()] = $aMeteoPartial
  166.             //$sHora = ($aMeteoPartial->getDataExtrem() != ''?' ' . $this->translator->trans("a les") . ' ' . $aMeteoPartial->getDataExtrem()->format('H:i') . ' h ':'');
  167.             $sHora '';
  168.             $aMeteo[$aMeteoPartial->getCodi()] = number_format$aMeteoPartial->getValor(), $aMeteoPartial->getDecimals(), ","".") . ' ' $aMeteoPartial->getUnitats() . $sHora;
  169.         }
  170.         
  171.         //dump($aMeteo);
  172.         
  173.         //die();
  174.         $aGeneral['iMin'] = $aGeneral['iMax'] = $enGeneral[0]->getMasellaCm();
  175.         if ($enGeneral[0]->getBoscCm() != '')
  176.         {
  177.             if ($enGeneral[0]->getBoscCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $enGeneral[0]->getBoscCm();
  178.             if ($enGeneral[0]->getBoscCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $enGeneral[0]->getBoscCm();
  179.         }
  180.         if ($enGeneral[0]->getTosaCm() != '')
  181.         {
  182.             if ($enGeneral[0]->getTosaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $enGeneral[0]->getTosaCm();
  183.             if ($enGeneral[0]->getTosaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $enGeneral[0]->getTosaCm();
  184.         }
  185.         if ($enGeneral[0]->getComaOriolaCm() != '')
  186.         {
  187.             if ($enGeneral[0]->getComaOriolaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $enGeneral[0]->getComaOriolaCm();
  188.             if ($enGeneral[0]->getComaOriolaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $enGeneral[0]->getComaOriolaCm();
  189.         }
  190.         if ($enGeneral[0]->getLaPletaCm() != '')
  191.         {
  192.             if ($enGeneral[0]->getLaPletaCm() > $aGeneral['iMax']) $aGeneral['iMax'] = $enGeneral[0]->getLaPletaCm();
  193.             if ($enGeneral[0]->getLaPletaCm() < $aGeneral['iMin']) $aGeneral['iMin'] = $enGeneral[0]->getLaPletaCm();
  194.         }
  195.         return $this->render('infoneu.html.twig', array(
  196.             'enGeneral'             => $enGeneral,
  197.             'general'               => $enGeneral[0],
  198.             'enPistes'              => $enPistes,
  199.             'enRemuntadors'         => $enRemuntadors,
  200.             'iTotalLongitudPises'   => $iTotalLongitudPises,
  201.             'aZones'                => $aZones,
  202.             'aPistes'               => $aPistes,
  203.             'sFecha'                => $sFecha,
  204.             'aTipus'                => $aTipus,
  205.             'aRemuntadors'          => $aRemuntadors,
  206.             'enTemps'               => $enTemps,
  207.             'enPrediccioMeteo'      => key_exists(0$enPrediccioMeteo)?$enPrediccioMeteo[0]:arraY(),
  208.             'aMeteo'                => $aMeteo,
  209.             'aGeneral'              => $aGeneral
  210.         ));
  211.     }
  212.     
  213.     public function instagramAction(Request $peticion)
  214.     {
  215.         $aRequest $peticion->request;
  216.         /////////////////////////
  217.         // Recoger dades generals
  218.         /////////////////////////
  219.         $enGeneral $this->em->getRepository(General::class)->findAll();
  220.         $query $this->em->createQuery(
  221.                                 'SELECT p
  222.                                 FROM App:Pistes p 
  223.                                 WHERE p.estatDia = :estat_dia
  224.                                 AND p.pista_relacionada is null 
  225.                                 ORDER BY p.zones ASC
  226.                                 '
  227.         )->setParameter('estat_dia''1');
  228.         $enPistes $query->getResult();
  229.         $iTotalLongitudPises 0;
  230.         $aZones = array();
  231.         $aPistes = array();
  232.         foreach ($enPistes as $key => $val)
  233.         {
  234.             $iTotalLongitudPises $iTotalLongitudPises $val->getLongitud();
  235.             $sFuntion 'getNom' ucfirst($peticion->attributes->get('_locale'));
  236.             $iIndex 0;
  237.             //echo '-' . $val->getZones() . '-';
  238.             if (array_key_exists($val->getZones()->getNom() . ''$aPistes))
  239.             {
  240.                 $iIndex count($aPistes[$val->getZones()->getNom() . '']);
  241.             } else {
  242.                $aZones[] = $val->getZones()->getNom(); 
  243.             }
  244.             $aPistes[$val->getZones()->getNom() . ''][$iIndex]['nom'] = $val->$sFuntion();
  245.             $aPistes[$val->getZones()->getNom() . ''][$iIndex]['color'] = (method_exists($val->getColors(), 'getCodi')?$val->getColors()->getCodi():'000');
  246.             
  247.         }
  248.         $query $this->em->createQuery(
  249.                                 'SELECT p
  250.                                 FROM App:Remuntadors p
  251.                                 WHERE p.estatDia = :estat_dia
  252.                                 ORDER BY p.remuntadorsTipus ASC
  253.                                 '
  254.         )->setParameter('estat_dia''1');
  255.         $enRemuntadors $query->getResult();
  256.         $aTipus = array();
  257.         $aRemuntadors = array();
  258.         foreach ($enRemuntadors as $key => $val)
  259.         {
  260.             $sFuntion 'getNom' ucfirst($peticion->attributes->get('_locale'));
  261.             $iIndex 0;
  262.             //echo '-' . $val->getRemuntadorsTipus() . '-';
  263.             if (array_key_exists($val->getRemuntadorsTipus()->$sFuntion() . ''$aRemuntadors))
  264.             {
  265.                 $iIndex count($aRemuntadors[$val->getRemuntadorsTipus()->$sFuntion() . '']);
  266.             } else {
  267.                $aTipus[] = $val->getRemuntadorsTipus()->$sFuntion(); 
  268.             }
  269.             $aRemuntadors[$val->getRemuntadorsTipus()->$sFuntion() . ''][$iIndex] = $val->getNom();
  270.            // echo $val->getNom();
  271.         }
  272.         $sFecha $this->translator->trans(date("l")) . ', ' date("d") . ' ' $this->translator->trans('of ' date("F")) . ' ' $this->translator->trans('de') . ' ' date("Y");
  273.         if (date("G") > 15 || date("G") < 7)
  274.         {
  275.             $date strtotime("+1 day");
  276.             $sFecha $this->translator->trans(date("l"$date)) . ', ' date("d"$date) . ' ' $this->translator->trans('of ' date("F"$date)) . ' ' $this->translator->trans('de') . ' ' date("Y"$date);
  277.             $sFecha $this->translator->trans("PREVISIÓ PEL") . ' ' $sFecha;
  278.         }
  279.         
  280.         $enTemps $this->em->getRepository(Temps::class)->findBy(
  281.             array(),
  282.             array(  'data'  => 'DESC'),
  283.             3
  284.         );
  285.         
  286.         if (date("G") <= 15)
  287.         {
  288.             unset($enTemps[2]);
  289.         }
  290.         
  291.         $fecha date('y/m/d');
  292.         
  293.         $sQuery "SELECT p "
  294.                 " FROM App:PrediccioMeteo p "
  295.                 " WHERE ";
  296.         /*
  297.         if (date('h') >= 18)
  298.         {
  299.             $sQuery .= " p.data > :now ";
  300.         } else {
  301.             $sQuery .= " p.data >= :now ";
  302.         } 
  303.          * 
  304.          */ 
  305.         $sQuery .= " p.data = :now ";
  306.         $sQuery .= " ORDER BY p.data ASC";
  307.         $query $this->em->createQuery($sQuery);
  308.         $query->setParameter('now'$fecha);
  309.         $enPrediccioMeteo $query->getResult();
  310.         $enMeteo $this->em->getRepository(Meteo::class)->findAll();
  311.         
  312.         foreach ($enMeteo as $aMeteoPartial)
  313.         {
  314.             $aMeteo[$aMeteoPartial->getCodi()] = $aMeteoPartial
  315.             //$sHora = ($aMeteoPartial->getDataExtrem() != ''?' ' . $this->translator->trans("a les") . ' ' . $aMeteoPartial->getDataExtrem()->format('H:i') . ' h ':'');
  316.             $sHora '';
  317.             $aMeteo[$aMeteoPartial->getCodi()] = number_format$aMeteoPartial->getValor(), $aMeteoPartial->getDecimals(), ","".") . ' ' $aMeteoPartial->getUnitats() . $sHora;
  318.         }
  319.         
  320.         //dump($aMeteo);
  321.         //die();
  322.         $aZonaManual[0][0] = 'TSC | 4';
  323.         $aZonaManual[0][1] = 'TSD | 4';
  324.         $aZonaManual[0][2] = 'TSD | 6';
  325.         $aZonaManual[1][0] = 'TQ | 1';
  326.         $aZonaManual[2][0] = 'CT | 1';
  327.         $aZonaManual[2][1] = 'TCD | 1';
  328.         
  329.         //dump($aRemuntadors);
  330.         //die();
  331.         
  332.         return $this->render('infoneuInstagram.html.twig', array(
  333.             'enGeneral'             => $enGeneral,
  334.             'general'               => $enGeneral[0],
  335.             'enPistes'              => $enPistes,
  336.             'enRemuntadors'         => $enRemuntadors,
  337.             'iTotalLongitudPises'   => $iTotalLongitudPises,
  338.             'aZones'                => $aZones,
  339.             'aPistes'               => $aPistes,
  340.             'sFecha'                => $sFecha,
  341.             'aTipus'                => $aTipus,
  342.             'aRemuntadors'          => $aRemuntadors,
  343.             'enTemps'               => $enTemps,
  344.             'enPrediccioMeteo'      => (array_key_exists(0$enPrediccioMeteo)? $enPrediccioMeteo[0]:array()),
  345.             'aMeteo'                => $aMeteo,
  346.             'aZonaManual'           => $aZonaManual
  347.         ));
  348.     }
  349.     
  350.     public function pdfAction(Request $peticion)
  351.     {
  352.         $sIdioma $peticion->attributes->get('_locale');
  353.         $sSubName 'INFONEU';
  354.                 
  355.         if ($sIdioma != 'ca')
  356.         {
  357.             $sIdioma 'es';
  358.             $sSubName 'INFONIEVE';
  359.         }
  360.         $dData date('Y-m-d');
  361.         
  362.         $sName $dData '_' $sSubName '.pdf';
  363.         $sUrlDesti $this->sPathUploads 'infoneu/' $sName;
  364.         $sUrl 'https://www.masella.com/' $sIdioma '/infoneu';
  365.         
  366. //        echo $sName;
  367. //        echo '<br>';
  368. //        echo $sUrl;
  369. //        die();
  370.         
  371. //        $sUrl = 'http://masella15.developer.entorno.es/app_dev.php/' . $peticion->attributes->get('_locale') . '/infoneu';
  372.         
  373.  //       mail ('manuel@entorno.es','resultados/controller/resultats_pdf', $sUrl . '<br>' . "wkhtmltopdf $sUrl " . $sUrlDesti);
  374.    
  375.         /*
  376.         * Important: l'usuari ha de ser apache per que pugui executar el wkhtmltopdf
  377.         */
  378.         //$blah = shell_exec("/bin/wkhtmltopdf $sUrl " . $sUrlDesti . ' --footer-center "Masella infoneu" --footer-right "[page] de [toPage]"');
  379.         
  380. //        echo $sUrlDesti;
  381.         
  382. //        echo '<br>';
  383.         
  384.         $blah shell_exec("/usr/local/bin/wkhtmltopdf --margin-top 5 --margin-bottom 0 --margin-left 5 --margin-right 5 $sUrl " $sUrlDesti);
  385.         
  386. //        echo $blah;
  387.         
  388. //        echo 'hola';
  389. //        die();
  390.             
  391.         header('Pragma: public');
  392.         header('Expires: 0');
  393.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  394.         header('Cache-Control: private'false); // required for certain browsers 
  395.         header ("Content-disposition: attachment; filename=" $sName);
  396.         header ("Content-type: application/pdf");
  397.         header('Content-Length: ' filesize($sUrlDesti));
  398.         readfile ($sUrlDesti);
  399.         unlink($sUrlDesti);
  400.     die();
  401.     }
  402. }