src/Aviatur/ContentBundle/Controller/ContentController.php line 32

Open in your IDE?
  1. <?php
  2. namespace Aviatur\ContentBundle\Controller;
  3. use Aviatur\ContentBundle\Entity\Content;
  4. use Aviatur\ContentBundle\Entity\HistoricalContent;
  5. use Aviatur\GeneralBundle\Entity\Weather;
  6. use Aviatur\GeneralBundle\Services\AviaturErrorHandler;
  7. use Aviatur\TwigBundle\Services\TwigFolder;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  14. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  15. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  16. use Symfony\Component\Validator\Validator\ValidatorInterface;
  17. class ContentController extends AbstractController
  18. {
  19.     /*
  20.      * Pantalla inicial, muestra los articulos
  21.      */
  22.     public function indexAction(Request $requestSessionInterface $sessionAviaturErrorHandler $errorHandlerTwigFolder $twigFolderAuthorizationCheckerInterface $authorizationCheckerPaginatorInterface $paginator$page$active$search null)
  23.     {
  24.         $em $this->getDoctrine()->getManager();
  25.         $fullRequest $request;
  26.         $routeParams $fullRequest->attributes->get('_route_params');
  27.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
  28.         $agencyId $session->get('agencyId');
  29.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  30.         $agencyFolder $twigFolder->twigFlux();
  31.         if ($request->isXmlHttpRequest()) {
  32.             //BUSCADOR
  33.             $query $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.id = :id AND a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  34.             $query $query->setParameter('agency'$agency);
  35.             $query $query->setParameter('id'$search);
  36.             $queryIn $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.id = :id AND a.isactive = 0 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  37.             $queryIn $queryIn->setParameter('agency'$agency);
  38.             $queryIn $queryIn->setParameter('id'$search);
  39.             if (isset($routeParams['content'])) {
  40.                 $path '/Content/Content/AjaxIndex_promo.html.twig';
  41.             } else {
  42.                 $path '/Content/Content/AjaxIndex.html.twig';
  43.             }
  44.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  45.             if ('activo' == $active) {
  46.                 $articulos $query->getResult();
  47.             } elseif ('inactivo' == $active) {
  48.                 if ($authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_CREATE_'.$agencyId) || $authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_EDIT_'.$agencyId) || $authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
  49.                     $articulos $queryIn->getResult();
  50.                 } else {
  51.                     return $twigFolder->pathWithLocale('aviatur_general_homepage');
  52.                 }
  53.             }
  54.             $actualArticles = [];
  55.             if (isset($routeParams['content'])) {
  56.                 foreach ($articulos as $articulo) {
  57.                     $description json_decode($articulo->getDescription(), true);
  58.                     if ($description && is_array($description)) {
  59.                         $actualArticles[] = $articulo;
  60.                         $type $description['type2'];
  61.                     }
  62.                 }
  63.             } else {
  64.                 foreach ($articulos as $articulo) {
  65.                     $description json_decode($articulo->getDescription(), true);
  66.                     if (null == $description || !is_array($description)) {
  67.                         $actualArticles[] = $articulo;
  68.                     } else {
  69.                         $actualArticles[] = $articulo;
  70.                         $type $description['type'];
  71.                     }
  72.                 }
  73.             }
  74.             if (empty($actualArticles)) {
  75.                 return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  76.             }
  77.             $cantdatos count($actualArticles);
  78.             $cantRegis 10;
  79.             $totalRegi ceil($cantdatos $cantRegis);
  80.             $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  81.             if (isset($type)) {
  82.                 //return $this->render($errorHandler->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type]);
  83.                 return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl'typeArticle' => $type]);
  84.             } else {
  85.                 //return $this->render($errorHandler->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
  86.                 return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl]);
  87.             }
  88.         } else {
  89.             //INDEX
  90.             $query $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  91.             $query $query->setParameter('agency'$agency);
  92.             $queryIn $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 0 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  93.             $queryIn $queryIn->setParameter('agency'$agency);
  94.             if (isset($routeParams['content'])) {
  95.                 $path '/Content/Content/index_promo.html.twig';
  96.             } else {
  97.                 $path '/Content/Content/index.html.twig';
  98.             }
  99.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  100.             if ('activo' == $active) {
  101.                 $articulos $query->getResult();
  102.             } elseif ('inactivo' == $active) {
  103.                 if ($authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_CREATE_'.$agencyId) || $authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_EDIT_'.$agencyId) || $authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
  104.                     $articulos $queryIn->getResult();
  105.                 } else {
  106.                     return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
  107.                 }
  108.             }
  109.             $pos strpos($agencyFolder'aviatur');
  110.             if (false !== $pos) {
  111.                 if (isset($routeParams['content'])) {
  112.                     return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/index_tickets.html.twig'), ['agencyId' => $agencyId]);
  113.                 } else {
  114.                     return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/index_content.html.twig'), ['agencyId' => $agencyId]);
  115.                 }
  116.             } else {
  117.                 $actualArticles = [];
  118.                 if (isset($routeParams['content'])) {
  119.                     foreach ($articulos as $articulo) {
  120.                         $description json_decode($articulo->getDescription(), true);
  121.                         if ($description && is_array($description)) {
  122.                             $actualArticles[] = $articulo;
  123.                             $type $description['type2'];
  124.                         }
  125.                     }
  126.                 } else {
  127.                     foreach ($articulos as $articulo) {
  128.                         $descrip $articulo->getDescription();
  129.                         $description json_decode($descriptrue);
  130.                         if(isset($description['type'])){
  131.                             $type $description['type'];
  132.                         }else{
  133.                             $type '';
  134.                         }
  135.                         $actualArticles[] = $articulo;
  136.                     }
  137.                 }
  138.                 if (empty($actualArticles)) {
  139.                     return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  140.                 }
  141.                 $cantdatos count($actualArticles);
  142.                 $cantRegis 10;
  143.                 $totalRegi ceil($cantdatos $cantRegis);
  144.                 $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  145.                 // $description = json_decode($actualArticles->getDescription(), true);
  146.                 return $this->render($twigFolder->twigExists($urlReturn), ['typeArticle' => $type,'agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl]);
  147.             }
  148.         }
  149.     }
  150.     public function listAction(Request $requestSessionInterface $sessionAviaturErrorHandler $errorHandlerTwigFolder $twigFolderAuthorizationCheckerInterface $authorizationCheckerPaginatorInterface $paginator$page$active$type)
  151.     {
  152.         $em $this->getDoctrine()->getManager();
  153.         $fullRequest $request;
  154.         $routeParams $fullRequest->attributes->get('_route_params');
  155.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
  156.         $agencyId $session->get('agencyId');
  157.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  158.         $agencyFolder $twigFolder->twigFlux();
  159.         if ($request->isXmlHttpRequest()) {
  160.             //CARGAR MÁS
  161.             $query $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  162.             $query $query->setParameter('agency'$agency);
  163.             $queryIn $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 0 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  164.             $queryIn $queryIn->setParameter('agency'$agency);
  165.             if (isset($routeParams['content'])) {
  166.                 $path '/Content/Content/AjaxIndex_promo.html.twig';
  167.             } else {
  168.                 $path '/Content/Content/AjaxIndex.html.twig';
  169.             }
  170.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  171.             $aerolineasArticles = [];
  172.             $colombia = [];
  173.             $america = [];
  174.             $oceania = [];
  175.             $europa = [];
  176.             $africa = [];
  177.             $asia = [];
  178.             $generalArticles = [];
  179.             $revistaArticles = [];
  180.             $informacionArticles = [];
  181.             $actualArticles = [];
  182.             $destinosBlog = [];
  183.             $cantRegis 9;
  184.             if ('activo' == $active) {
  185.                 $articulos $query->getResult();
  186.             } elseif ('inactivo' == $active) {
  187.                 if ($authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_CREATE_'.$agencyId) || $authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_EDIT_'.$agencyId) || $authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
  188.                     $articulos $queryIn->getResult();
  189.                     if (isset($routeParams['content'])) {
  190.                         foreach ($articulos as $articulo) {
  191.                             $description json_decode($articulo->getDescription(), true);
  192.                             if ($description && is_array($description)) {
  193.                                 if ('aerolineas' == $description['type']) {
  194.                                     $aerolineasArticles[] = $articulo;
  195.                                 }
  196.                                 if ('destinos' == $description['type']) {
  197.                                     if ('colombia' == $description['type2']) {
  198.                                         $colombia[] = $articulo;
  199.                                     }
  200.                                     if ('america' == $description['type2']) {
  201.                                         $america[] = $articulo;
  202.                                     }
  203.                                     if ('oceania' == $description['type2']) {
  204.                                         $oceania[] = $articulo;
  205.                                     }
  206.                                     if ('europa' == $description['type2']) {
  207.                                         $europa[] = $articulo;
  208.                                     }
  209.                                     if ('africa' == $description['type2']) {
  210.                                         $africa[] = $articulo;
  211.                                     }
  212.                                     if ('asia' == $description['type2']) {
  213.                                         $asia[] = $articulo;
  214.                                     }
  215.                                 }
  216.                                 if ('destinos-blog' == $description['type']) {
  217.                                     $destinosBlog[] = $articulo;
  218.                                 }
  219.                             }
  220.                         }
  221.                         if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  222.                             return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  223.                         }
  224.                         $cookieArray = [];
  225.                         /* Redireccion articulos destinos y aerolineas */
  226.                         if ('aerolinea' == $type) {
  227.                             $cantAerolineas count($aerolineasArticles);
  228.                             $totalAero ceil($cantAerolineas $cantRegis);
  229.                             $pagination $paginator->paginate($aerolineasArticles$fullRequest->query->get('page'$page), $cantRegis);
  230.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalAero'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  231.                         }
  232.                         if ('colombia' == $type) {
  233.                             $cantDestinosC count($colombia);
  234.                             $totalDestinosC ceil($cantDestinosC $cantRegis);
  235.                             $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  236.                             $cookieArray['origin1'] = '';
  237.                             $cookieArray['destination1'] = 'SMR';
  238.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  239.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  240.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  241.                             } else {
  242.                                 $cookieArray['originLabel1'] = '';
  243.                             }
  244.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  245.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  246.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  247.                             } else {
  248.                                 $cookieArray['destinationLabel1'] = '';
  249.                             }
  250.                             $cookieArray['date1'] = '';
  251.                             $cookieArray['date2'] = '';
  252.                             $cookieArray['adults'] = '';
  253.                             $cookieArray['children'] = '';
  254.                             $cookieArray['infants'] = '';
  255.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  256.                         }
  257.                         if ('america' == $type) {
  258.                             $cantDestinosA count($america);
  259.                             $totalDestinosA ceil($cantDestinosA $cantRegis);
  260.                             $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  261.                             $cookieArray['origin1'] = '';
  262.                             $cookieArray['destination1'] = 'MIA';
  263.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  264.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  265.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  266.                             } else {
  267.                                 $cookieArray['originLabel1'] = '';
  268.                             }
  269.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  270.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  271.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  272.                             } else {
  273.                                 $cookieArray['destinationLabel1'] = '';
  274.                             }
  275.                             $cookieArray['date1'] = '';
  276.                             $cookieArray['date2'] = '';
  277.                             $cookieArray['adults'] = '';
  278.                             $cookieArray['children'] = '';
  279.                             $cookieArray['infants'] = '';
  280.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  281.                         }
  282.                         if ('oceania' == $type) {
  283.                             $cantDestinosO count($oceania);
  284.                             $totalDestinosO ceil($cantDestinosO $cantRegis);
  285.                             $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  286.                             $cookieArray['origin1'] = '';
  287.                             $cookieArray['destination1'] = 'SYD';
  288.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  289.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  290.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  291.                             } else {
  292.                                 $cookieArray['originLabel1'] = '';
  293.                             }
  294.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  295.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  296.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  297.                             } else {
  298.                                 $cookieArray['destinationLabel1'] = '';
  299.                             }
  300.                             $cookieArray['date1'] = '';
  301.                             $cookieArray['date2'] = '';
  302.                             $cookieArray['adults'] = '';
  303.                             $cookieArray['children'] = '';
  304.                             $cookieArray['infants'] = '';
  305.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  306.                         }
  307.                         if ('europa' == $type) {
  308.                             $cantDestinosE count($europa);
  309.                             $totalDestinosE ceil($cantDestinosE $cantRegis);
  310.                             $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  311.                             $cookieArray['origin1'] = '';
  312.                             $cookieArray['destination1'] = 'MAD';
  313.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  314.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  315.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  316.                             } else {
  317.                                 $cookieArray['originLabel1'] = '';
  318.                             }
  319.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  320.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  321.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  322.                             } else {
  323.                                 $cookieArray['destinationLabel1'] = '';
  324.                             }
  325.                             $cookieArray['date1'] = '';
  326.                             $cookieArray['date2'] = '';
  327.                             $cookieArray['adults'] = '';
  328.                             $cookieArray['children'] = '';
  329.                             $cookieArray['infants'] = '';
  330.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  331.                         }
  332.                         if ('africa' == $type) {
  333.                             $cantDestinosAF count($africa);
  334.                             $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  335.                             $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  336.                             $cookieArray['origin1'] = '';
  337.                             $cookieArray['destination1'] = 'CAI';
  338.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  339.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  340.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  341.                             } else {
  342.                                 $cookieArray['originLabel1'] = '';
  343.                             }
  344.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  345.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  346.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  347.                             } else {
  348.                                 $cookieArray['destinationLabel1'] = '';
  349.                             }
  350.                             $cookieArray['date1'] = '';
  351.                             $cookieArray['date2'] = '';
  352.                             $cookieArray['adults'] = '';
  353.                             $cookieArray['children'] = '';
  354.                             $cookieArray['infants'] = '';
  355.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  356.                         }
  357.                         if ('asia' == $type) {
  358.                             $cantDestinosAS count($asia);
  359.                             $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  360.                             $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  361.                             $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => 'MIA']);
  362.                             $cookieArray['origin1'] = '';
  363.                             $cookieArray['destination1'] = 'TYO';
  364.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  365.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  366.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  367.                             } else {
  368.                                 $cookieArray['originLabel1'] = '';
  369.                             }
  370.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  371.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  372.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  373.                             } else {
  374.                                 $cookieArray['destinationLabel1'] = '';
  375.                             }
  376.                             $cookieArray['date1'] = '';
  377.                             $cookieArray['date2'] = '';
  378.                             $cookieArray['adults'] = '';
  379.                             $cookieArray['children'] = '';
  380.                             $cookieArray['infants'] = '';
  381.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  382.                         }
  383.                         if ('blog' == $type) {
  384.                             $cantDestinosBL count($destinosBlog);
  385.                             $totalDestinosBL ceil($cantDestinosBL $cantRegis);
  386.                             $pagination $paginator->paginate($destinosBlog$fullRequest->query->get('page'$page), $cantRegis);
  387.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosBL'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  388.                         }
  389.                     } else {
  390.                         foreach ($articulos as $articulo) {
  391.                             $description json_decode($articulo->getDescription(), true);
  392.                             if ($description && is_array($description)) {
  393.                                 if (isset($description['type'])) {
  394.                                     if ('general' == $description['type']) {
  395.                                         $generalArticles[] = $articulo;
  396.                                     }
  397.                                     if ('revista-horizontes' == $description['type']) {
  398.                                         $revistaArticles[] = $articulo;
  399.                                     }
  400.                                     if ('informacion-aviatur' == $description['type']) {
  401.                                         $informacionArticles[] = $articulo;
  402.                                     }
  403.                                 } else {
  404.                                     $actualArticles[] = $articulo;
  405.                                 }
  406.                             }
  407.                         }
  408.                         /* Redireccion articulos contenido general, revista e información */
  409.                         if ('general' == $type) {
  410.                             $cantGeneral count($generalArticles);
  411.                             $totalGeneral ceil($cantGeneral $cantRegis);
  412.                             $pagination $paginator->paginate($generalArticles$fullRequest->query->get('page'$page), $cantRegis);
  413.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  414.                         }
  415.                         if ('revista-horizontes' == $type) {
  416.                             $cantRevista count($revistaArticles);
  417.                             $totalRevista ceil($cantRevista $cantRegis);
  418.                             $pagination $paginator->paginate($revistaArticles$fullRequest->query->get('page'$page), $cantRegis);
  419.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  420.                         }
  421.                         if ('informacion-aviatur' == $type) {
  422.                             $cantInformacion count($informacionArticles);
  423.                             $totalInformacion ceil($cantInformacion $cantRegis);
  424.                             $pagination $paginator->paginate($informacionArticles$fullRequest->query->get('page'$page), $cantRegis);
  425.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  426.                         }
  427.                     }
  428.                 } else {
  429.                     return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
  430.                 }
  431.             }
  432.             if (isset($routeParams['content'])) {
  433.                 foreach ($articulos as $articulo) {
  434.                     $description json_decode($articulo->getDescription(), true);
  435.                     if ($description && is_array($description)) {
  436.                         if ('aerolineas' == $description['type']) {
  437.                             $aerolineasArticles[] = $articulo;
  438.                         }
  439.                         if ('destinos' == $description['type']) {
  440.                             if ('colombia' == $description['type2']) {
  441.                                 $colombia[] = $articulo;
  442.                             }
  443.                             if ('america' == $description['type2']) {
  444.                                 $america[] = $articulo;
  445.                             }
  446.                             if ('oceania' == $description['type2']) {
  447.                                 $oceania[] = $articulo;
  448.                             }
  449.                             if ('europa' == $description['type2']) {
  450.                                 $europa[] = $articulo;
  451.                             }
  452.                             if ('africa' == $description['type2']) {
  453.                                 $africa[] = $articulo;
  454.                             }
  455.                             if ('asia' == $description['type2']) {
  456.                                 $asia[] = $articulo;
  457.                             }
  458.                         }
  459.                         if ('destinos-blog' == $description['type']) {
  460.                             $destinosBlog[] = $articulo;
  461.                         }
  462.                     }
  463.                 }
  464.                 if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  465.                     return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  466.                 }
  467.                 $cookieArray = [];
  468.                 /* Redireccion articulos destinos y aerolineas */
  469.                 if ('aerolinea' == $type) {
  470.                     $cantAerolineas count($aerolineasArticles);
  471.                     $totalAero ceil($cantAerolineas $cantRegis);
  472.                     $pagination $paginator->paginate($aerolineasArticles$fullRequest->query->get('page'$page), $cantRegis);
  473.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalAero'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  474.                 }
  475.                 if ('colombia' == $type) {
  476.                     $cantDestinosC count($colombia);
  477.                     $totalDestinosC ceil($cantDestinosC $cantRegis);
  478.                     $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  479.                     $cookieArray['origin1'] = '';
  480.                     $cookieArray['destination1'] = 'SMR';
  481.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  482.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  483.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  484.                     } else {
  485.                         $cookieArray['originLabel1'] = '';
  486.                     }
  487.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  488.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  489.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  490.                     } else {
  491.                         $cookieArray['destinationLabel1'] = '';
  492.                     }
  493.                     $cookieArray['date1'] = '';
  494.                     $cookieArray['date2'] = '';
  495.                     $cookieArray['adults'] = '';
  496.                     $cookieArray['children'] = '';
  497.                     $cookieArray['infants'] = '';
  498.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  499.                 }
  500.                 if ('america' == $type) {
  501.                     $cantDestinosA count($america);
  502.                     $totalDestinosA ceil($cantDestinosA $cantRegis);
  503.                     $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  504.                     $cookieArray['origin1'] = '';
  505.                     $cookieArray['destination1'] = 'MIA';
  506.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  507.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  508.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  509.                     } else {
  510.                         $cookieArray['originLabel1'] = '';
  511.                     }
  512.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  513.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  514.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  515.                     } else {
  516.                         $cookieArray['destinationLabel1'] = '';
  517.                     }
  518.                     $cookieArray['date1'] = '';
  519.                     $cookieArray['date2'] = '';
  520.                     $cookieArray['adults'] = '';
  521.                     $cookieArray['children'] = '';
  522.                     $cookieArray['infants'] = '';
  523.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  524.                 }
  525.                 if ('oceania' == $type) {
  526.                     $cantDestinosO count($oceania);
  527.                     $totalDestinosO ceil($cantDestinosO $cantRegis);
  528.                     $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  529.                     $cookieArray['origin1'] = '';
  530.                     $cookieArray['destination1'] = 'SYD';
  531.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  532.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  533.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  534.                     } else {
  535.                         $cookieArray['originLabel1'] = '';
  536.                     }
  537.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  538.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  539.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  540.                     } else {
  541.                         $cookieArray['destinationLabel1'] = '';
  542.                     }
  543.                     $cookieArray['date1'] = '';
  544.                     $cookieArray['date2'] = '';
  545.                     $cookieArray['adults'] = '';
  546.                     $cookieArray['children'] = '';
  547.                     $cookieArray['infants'] = '';
  548.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  549.                 }
  550.                 if ('europa' == $type) {
  551.                     $cantDestinosE count($europa);
  552.                     $totalDestinosE ceil($cantDestinosE $cantRegis);
  553.                     $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  554.                     $cookieArray['origin1'] = '';
  555.                     $cookieArray['destination1'] = 'MAD';
  556.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  557.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  558.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  559.                     } else {
  560.                         $cookieArray['originLabel1'] = '';
  561.                     }
  562.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  563.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  564.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  565.                     } else {
  566.                         $cookieArray['destinationLabel1'] = '';
  567.                     }
  568.                     $cookieArray['date1'] = '';
  569.                     $cookieArray['date2'] = '';
  570.                     $cookieArray['adults'] = '';
  571.                     $cookieArray['children'] = '';
  572.                     $cookieArray['infants'] = '';
  573.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  574.                 }
  575.                 if ('africa' == $type) {
  576.                     $cantDestinosAF count($africa);
  577.                     $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  578.                     $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  579.                     $cookieArray['origin1'] = '';
  580.                     $cookieArray['destination1'] = 'CAI';
  581.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  582.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  583.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  584.                     } else {
  585.                         $cookieArray['originLabel1'] = '';
  586.                     }
  587.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  588.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  589.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  590.                     } else {
  591.                         $cookieArray['destinationLabel1'] = '';
  592.                     }
  593.                     $cookieArray['date1'] = '';
  594.                     $cookieArray['date2'] = '';
  595.                     $cookieArray['adults'] = '';
  596.                     $cookieArray['children'] = '';
  597.                     $cookieArray['infants'] = '';
  598.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  599.                 }
  600.                 if ('asia' == $type) {
  601.                     $cantDestinosAS count($asia);
  602.                     $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  603.                     $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  604.                     $cookieArray['origin1'] = '';
  605.                     $cookieArray['destination1'] = 'TYO';
  606.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  607.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  608.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  609.                     } else {
  610.                         $cookieArray['originLabel1'] = '';
  611.                     }
  612.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  613.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  614.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  615.                     } else {
  616.                         $cookieArray['destinationLabel1'] = '';
  617.                     }
  618.                     $cookieArray['date1'] = '';
  619.                     $cookieArray['date2'] = '';
  620.                     $cookieArray['adults'] = '';
  621.                     $cookieArray['children'] = '';
  622.                     $cookieArray['infants'] = '';
  623.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  624.                 }
  625.                 if ('blog' == $type) {
  626.                     $cantDestinosBL count($destinosBlog);
  627.                     $totalDestinosBL ceil($cantDestinosBL $cantRegis);
  628.                     $pagination $paginator->paginate($destinosBlog$fullRequest->query->get('page'$page), $cantRegis);
  629.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosBL'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  630.                 }
  631.             } else {
  632.                 foreach ($articulos as $articulo) {
  633.                     $description json_decode($articulo->getDescription(), true);
  634.                     if (null == $description || is_array($description)) {
  635.                         if (isset($description['type'])) {
  636.                             if ('general' == $description['type']) {
  637.                                 $generalArticles[] = $articulo;
  638.                             }
  639.                             if ('revista-horizontes' == $description['type']) {
  640.                                 $revistaArticles[] = $articulo;
  641.                             }
  642.                             if ('informacion-aviatur' == $description['type']) {
  643.                                 $informacionArticles[] = $articulo;
  644.                             }
  645.                         } else {
  646.                             $actualArticles[] = $articulo;
  647.                         }
  648.                     }
  649.                 }
  650.                 if (empty($generalArticles) && empty($revistaArticles) && empty($informacionArticles)) {
  651.                     return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  652.                 }
  653.                 /* Redireccion articulos contenido general, revista e información */
  654.                 if (!empty($generalArticles) && !empty($revistaArticles) && !empty($informacionArticles)) {
  655.                     if ('general' == $type) {
  656.                         $cantGeneral count($generalArticles);
  657.                         $totalGeneral ceil($cantGeneral $cantRegis);
  658.                         $pagination $paginator->paginate($generalArticles$fullRequest->query->get('page'$page), $cantRegis);
  659.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  660.                     }
  661.                     if ('revista-horizontes' == $type) {
  662.                         $cantRevista count($revistaArticles);
  663.                         $totalRevista ceil($cantRevista $cantRegis);
  664.                         $pagination $paginator->paginate($revistaArticles$fullRequest->query->get('page'$page), $cantRegis);
  665.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  666.                     }
  667.                     if ('informacion-aviatur' == $type) {
  668.                         $cantInformacion count($informacionArticles);
  669.                         $totalInformacion ceil($cantInformacion $cantRegis);
  670.                         $pagination $paginator->paginate($informacionArticles$fullRequest->query->get('page'$page), $cantRegis);
  671.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  672.                     }
  673.                 } else {
  674.                     $cantdatos count($actualArticles);
  675.                     $cantRegis 10;
  676.                     $totalRegi ceil($cantdatos $cantRegis);
  677.                     $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  678.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl]);
  679.                 }
  680.             }
  681.         } else {
  682.             //INDEX
  683.             $query $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  684.             $query $query->setParameter('agency'$agency);
  685.             $queryIn $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 0 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.creationdate DESC');
  686.             $queryIn $queryIn->setParameter('agency'$agency);
  687.             if (isset($routeParams['content'])) {
  688.                 $path '/Content/Content/index_promo.html.twig';
  689.             } else {
  690.                 $path '/Content/Content/index.html.twig';
  691.             }
  692.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  693.             $aerolineasArticles = [];
  694.             $colombia = [];
  695.             $america = [];
  696.             $oceania = [];
  697.             $europa = [];
  698.             $africa = [];
  699.             $asia = [];
  700.             $generalArticles = [];
  701.             $revistaArticles = [];
  702.             $informacionArticles = [];
  703.             $actualArticles = [];
  704.             $destinosBlog = [];
  705.             $cantRegis 9;
  706.             if ('activo' == $active) {
  707.                 $articulos $query->getResult();
  708.             } elseif ('inactivo' == $active) {
  709.                 if ($authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_CREATE_'.$agencyId) || $authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_PROMO_PRODUCT_EDIT_'.$agencyId) || $authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
  710.                     $articulos $queryIn->getResult();
  711.                     if (isset($routeParams['content'])) {
  712.                         foreach ($articulos as $articulo) {
  713.                             $description json_decode($articulo->getDescription(), true);
  714.                             if ($description && is_array($description)) {
  715.                                 if ('aerolineas' == $description['type']) {
  716.                                     $aerolineasArticles[] = $articulo;
  717.                                 }
  718.                                 if ('destinos' == $description['type']) {
  719.                                     if ('colombia' == $description['type2']) {
  720.                                         $colombia[] = $articulo;
  721.                                     }
  722.                                     if ('america' == $description['type2']) {
  723.                                         $america[] = $articulo;
  724.                                     }
  725.                                     if ('oceania' == $description['type2']) {
  726.                                         $oceania[] = $articulo;
  727.                                     }
  728.                                     if ('europa' == $description['type2']) {
  729.                                         $europa[] = $articulo;
  730.                                     }
  731.                                     if ('africa' == $description['type2']) {
  732.                                         $africa[] = $articulo;
  733.                                     }
  734.                                     if ('asia' == $description['type2']) {
  735.                                         $asia[] = $articulo;
  736.                                     }
  737.                                 }
  738.                                 if ('destinos-blog' == $description['type']) {
  739.                                     $destinosBlog[] = $articulo;
  740.                                 }
  741.                             }
  742.                         }
  743.                         if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  744.                             return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  745.                         }
  746.                         $cookieArray = [];
  747.                         /* Redireccion articulos destinos y aerolineas */
  748.                         if ('aerolinea' == $type) {
  749.                             $cantAerolineas count($aerolineasArticles);
  750.                             $totalAero ceil($cantAerolineas $cantRegis);
  751.                             $pagination $paginator->paginate($aerolineasArticles$fullRequest->query->get('page'$page), $cantRegis);
  752.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalAero'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  753.                         }
  754.                         if ('colombia' == $type) {
  755.                             $cantDestinosC count($colombia);
  756.                             $totalDestinosC ceil($cantDestinosC $cantRegis);
  757.                             $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  758.                             $cookieArray['origin1'] = '';
  759.                             $cookieArray['destination1'] = 'SMR';
  760.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  761.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  762.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  763.                             } else {
  764.                                 $cookieArray['originLabel1'] = '';
  765.                             }
  766.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  767.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  768.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  769.                             } else {
  770.                                 $cookieArray['destinationLabel1'] = '';
  771.                             }
  772.                             $cookieArray['date1'] = '';
  773.                             $cookieArray['date2'] = '';
  774.                             $cookieArray['adults'] = '';
  775.                             $cookieArray['children'] = '';
  776.                             $cookieArray['infants'] = '';
  777.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  778.                         }
  779.                         if ('america' == $type) {
  780.                             $cantDestinosA count($america);
  781.                             $totalDestinosA ceil($cantDestinosA $cantRegis);
  782.                             $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  783.                             $cookieArray['origin1'] = '';
  784.                             $cookieArray['destination1'] = 'MIA';
  785.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  786.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  787.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  788.                             } else {
  789.                                 $cookieArray['originLabel1'] = '';
  790.                             }
  791.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  792.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  793.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  794.                             } else {
  795.                                 $cookieArray['destinationLabel1'] = '';
  796.                             }
  797.                             $cookieArray['date1'] = '';
  798.                             $cookieArray['date2'] = '';
  799.                             $cookieArray['adults'] = '';
  800.                             $cookieArray['children'] = '';
  801.                             $cookieArray['infants'] = '';
  802.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  803.                         }
  804.                         if ('oceania' == $type) {
  805.                             $cantDestinosO count($oceania);
  806.                             $totalDestinosO ceil($cantDestinosO $cantRegis);
  807.                             $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  808.                             $cookieArray['origin1'] = '';
  809.                             $cookieArray['destination1'] = 'SYD';
  810.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  811.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  812.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  813.                             } else {
  814.                                 $cookieArray['originLabel1'] = '';
  815.                             }
  816.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  817.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  818.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  819.                             } else {
  820.                                 $cookieArray['destinationLabel1'] = '';
  821.                             }
  822.                             $cookieArray['date1'] = '';
  823.                             $cookieArray['date2'] = '';
  824.                             $cookieArray['adults'] = '';
  825.                             $cookieArray['children'] = '';
  826.                             $cookieArray['infants'] = '';
  827.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  828.                         }
  829.                         if ('europa' == $type) {
  830.                             $cantDestinosE count($europa);
  831.                             $totalDestinosE ceil($cantDestinosE $cantRegis);
  832.                             $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  833.                             $cookieArray['origin1'] = '';
  834.                             $cookieArray['destination1'] = 'MAD';
  835.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  836.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  837.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  838.                             } else {
  839.                                 $cookieArray['originLabel1'] = '';
  840.                             }
  841.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  842.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  843.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  844.                             } else {
  845.                                 $cookieArray['destinationLabel1'] = '';
  846.                             }
  847.                             $cookieArray['date1'] = '';
  848.                             $cookieArray['date2'] = '';
  849.                             $cookieArray['adults'] = '';
  850.                             $cookieArray['children'] = '';
  851.                             $cookieArray['infants'] = '';
  852.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  853.                         }
  854.                         if ('africa' == $type) {
  855.                             $cantDestinosAF count($africa);
  856.                             $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  857.                             $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  858.                             $cookieArray['origin1'] = '';
  859.                             $cookieArray['destination1'] = 'CAI';
  860.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  861.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  862.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  863.                             } else {
  864.                                 $cookieArray['originLabel1'] = '';
  865.                             }
  866.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  867.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  868.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  869.                             } else {
  870.                                 $cookieArray['destinationLabel1'] = '';
  871.                             }
  872.                             $cookieArray['date1'] = '';
  873.                             $cookieArray['date2'] = '';
  874.                             $cookieArray['adults'] = '';
  875.                             $cookieArray['children'] = '';
  876.                             $cookieArray['infants'] = '';
  877.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  878.                         }
  879.                         if ('asia' == $type) {
  880.                             $cantDestinosAS count($asia);
  881.                             $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  882.                             $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  883.                             $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => 'MIA']);
  884.                             $cookieArray['origin1'] = '';
  885.                             $cookieArray['destination1'] = 'TYO';
  886.                             if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  887.                                 $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  888.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  889.                             } else {
  890.                                 $cookieArray['originLabel1'] = '';
  891.                             }
  892.                             if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  893.                                 $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  894.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  895.                             } else {
  896.                                 $cookieArray['destinationLabel1'] = '';
  897.                             }
  898.                             $cookieArray['date1'] = '';
  899.                             $cookieArray['date2'] = '';
  900.                             $cookieArray['adults'] = '';
  901.                             $cookieArray['children'] = '';
  902.                             $cookieArray['infants'] = '';
  903.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  904.                         }
  905.                         if ('blog' == $type) {
  906.                             $cantDestinosBL count($destinosBlog);
  907.                             $totalDestinosBL ceil($cantDestinosBL $cantRegis);
  908.                             $pagination $paginator->paginate($destinosBlog$fullRequest->query->get('page'$page), $cantRegis);
  909.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosBL'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  910.                         }
  911.                     } else {
  912.                         foreach ($articulos as $articulo) {
  913.                             $description json_decode($articulo->getDescription(), true);
  914.                             if ($description && is_array($description)) {
  915.                                 if (isset($description['type'])) {
  916.                                     if ('general' == $description['type']) {
  917.                                         $generalArticles[] = $articulo;
  918.                                     }
  919.                                     if ('revista-horizontes' == $description['type']) {
  920.                                         $revistaArticles[] = $articulo;
  921.                                     }
  922.                                     if ('informacion-aviatur' == $description['type']) {
  923.                                         $informacionArticles[] = $articulo;
  924.                                     }
  925.                                 } else {
  926.                                     $actualArticles[] = $articulo;
  927.                                 }
  928.                             }
  929.                         }
  930.                         /* Redireccion articulos contenido general, revista e información */
  931.                         if ('general' == $type) {
  932.                             $cantGeneral count($generalArticles);
  933.                             $totalGeneral ceil($cantGeneral $cantRegis);
  934.                             $pagination $paginator->paginate($generalArticles$fullRequest->query->get('page'$page), $cantRegis);
  935.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  936.                         }
  937.                         if ('revista-horizontes' == $type) {
  938.                             $cantRevista count($revistaArticles);
  939.                             $totalRevista ceil($cantRevista $cantRegis);
  940.                             $pagination $paginator->paginate($revistaArticles$fullRequest->query->get('page'$page), $cantRegis);
  941.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  942.                         }
  943.                         if ('informacion-aviatur' == $type) {
  944.                             $cantInformacion count($informacionArticles);
  945.                             $totalInformacion ceil($cantInformacion $cantRegis);
  946.                             $pagination $paginator->paginate($informacionArticles$fullRequest->query->get('page'$page), $cantRegis);
  947.                             return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  948.                         }
  949.                     }
  950.                 } else {
  951.                     return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
  952.                 }
  953.             }
  954.             if (isset($routeParams['content'])) {
  955.                 foreach ($articulos as $articulo) {
  956.                     $description json_decode($articulo->getDescription(), true);
  957.                     if ($description && is_array($description)) {
  958.                         if ('aerolineas' == $description['type']) {
  959.                             $aerolineasArticles[] = $articulo;
  960.                         }
  961.                         if ('destinos' == $description['type']) {
  962.                             if ('colombia' == $description['type2']) {
  963.                                 $colombia[] = $articulo;
  964.                             }
  965.                             if ('america' == $description['type2']) {
  966.                                 $america[] = $articulo;
  967.                             }
  968.                             if ('oceania' == $description['type2']) {
  969.                                 $oceania[] = $articulo;
  970.                             }
  971.                             if ('europa' == $description['type2']) {
  972.                                 $europa[] = $articulo;
  973.                             }
  974.                             if ('africa' == $description['type2']) {
  975.                                 $africa[] = $articulo;
  976.                             }
  977.                             if ('asia' == $description['type2']) {
  978.                                 $asia[] = $articulo;
  979.                             }
  980.                         }
  981.                         if ('destinos-blog' == $description['type']) {
  982.                             $destinosBlog[] = $articulo;
  983.                         }
  984.                     }
  985.                 }
  986.                 if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  987.                     return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  988.                 }
  989.                 $cookieArray = [];
  990.                 /* Redireccion articulos destinos y aerolineas */
  991.                 if ('aerolinea' == $type) {
  992.                     $cantAerolineas count($aerolineasArticles);
  993.                     $totalAero ceil($cantAerolineas $cantRegis);
  994.                     $pagination $paginator->paginate($aerolineasArticles$fullRequest->query->get('page'$page), $cantRegis);
  995.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalAero'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  996.                 }
  997.                 if ('colombia' == $type) {
  998.                     $cantDestinosC count($colombia);
  999.                     $totalDestinosC ceil($cantDestinosC $cantRegis);
  1000.                     $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  1001.                     $cookieArray['origin1'] = '';
  1002.                     $cookieArray['destination1'] = 'SMR';
  1003.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1004.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1005.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1006.                     } else {
  1007.                         $cookieArray['originLabel1'] = '';
  1008.                     }
  1009.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1010.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1011.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1012.                     } else {
  1013.                         $cookieArray['destinationLabel1'] = '';
  1014.                     }
  1015.                     $cookieArray['date1'] = '';
  1016.                     $cookieArray['date2'] = '';
  1017.                     $cookieArray['adults'] = '';
  1018.                     $cookieArray['children'] = '';
  1019.                     $cookieArray['infants'] = '';
  1020.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1021.                 }
  1022.                 if ('america' == $type) {
  1023.                     $cantDestinosA count($america);
  1024.                     $totalDestinosA ceil($cantDestinosA $cantRegis);
  1025.                     $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  1026.                     $cookieArray['origin1'] = '';
  1027.                     $cookieArray['destination1'] = 'MIA';
  1028.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1029.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1030.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1031.                     } else {
  1032.                         $cookieArray['originLabel1'] = '';
  1033.                     }
  1034.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1035.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1036.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1037.                     } else {
  1038.                         $cookieArray['destinationLabel1'] = '';
  1039.                     }
  1040.                     $cookieArray['date1'] = '';
  1041.                     $cookieArray['date2'] = '';
  1042.                     $cookieArray['adults'] = '';
  1043.                     $cookieArray['children'] = '';
  1044.                     $cookieArray['infants'] = '';
  1045.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1046.                 }
  1047.                 if ('oceania' == $type) {
  1048.                     $cantDestinosO count($oceania);
  1049.                     $totalDestinosO ceil($cantDestinosO $cantRegis);
  1050.                     $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  1051.                     $cookieArray['origin1'] = '';
  1052.                     $cookieArray['destination1'] = 'SYD';
  1053.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1054.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1055.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1056.                     } else {
  1057.                         $cookieArray['originLabel1'] = '';
  1058.                     }
  1059.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1060.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1061.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1062.                     } else {
  1063.                         $cookieArray['destinationLabel1'] = '';
  1064.                     }
  1065.                     $cookieArray['date1'] = '';
  1066.                     $cookieArray['date2'] = '';
  1067.                     $cookieArray['adults'] = '';
  1068.                     $cookieArray['children'] = '';
  1069.                     $cookieArray['infants'] = '';
  1070.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1071.                 }
  1072.                 if ('europa' == $type) {
  1073.                     $cantDestinosE count($europa);
  1074.                     $totalDestinosE ceil($cantDestinosE $cantRegis);
  1075.                     $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  1076.                     $cookieArray['origin1'] = '';
  1077.                     $cookieArray['destination1'] = 'MAD';
  1078.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1079.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1080.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1081.                     } else {
  1082.                         $cookieArray['originLabel1'] = '';
  1083.                     }
  1084.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1085.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1086.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1087.                     } else {
  1088.                         $cookieArray['destinationLabel1'] = '';
  1089.                     }
  1090.                     $cookieArray['date1'] = '';
  1091.                     $cookieArray['date2'] = '';
  1092.                     $cookieArray['adults'] = '';
  1093.                     $cookieArray['children'] = '';
  1094.                     $cookieArray['infants'] = '';
  1095.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1096.                 }
  1097.                 if ('africa' == $type) {
  1098.                     $cantDestinosAF count($africa);
  1099.                     $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  1100.                     $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  1101.                     $cookieArray['origin1'] = '';
  1102.                     $cookieArray['destination1'] = 'CAI';
  1103.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1104.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1105.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1106.                     } else {
  1107.                         $cookieArray['originLabel1'] = '';
  1108.                     }
  1109.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1110.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1111.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1112.                     } else {
  1113.                         $cookieArray['destinationLabel1'] = '';
  1114.                     }
  1115.                     $cookieArray['date1'] = '';
  1116.                     $cookieArray['date2'] = '';
  1117.                     $cookieArray['adults'] = '';
  1118.                     $cookieArray['children'] = '';
  1119.                     $cookieArray['infants'] = '';
  1120.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1121.                 }
  1122.                 if ('asia' == $type) {
  1123.                     $cantDestinosAS count($asia);
  1124.                     $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  1125.                     $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  1126.                     $cookieArray['origin1'] = '';
  1127.                     $cookieArray['destination1'] = 'TYO';
  1128.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1129.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1130.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1131.                     } else {
  1132.                         $cookieArray['originLabel1'] = '';
  1133.                     }
  1134.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1135.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1136.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1137.                     } else {
  1138.                         $cookieArray['destinationLabel1'] = '';
  1139.                     }
  1140.                     $cookieArray['date1'] = '';
  1141.                     $cookieArray['date2'] = '';
  1142.                     $cookieArray['adults'] = '';
  1143.                     $cookieArray['children'] = '';
  1144.                     $cookieArray['infants'] = '';
  1145.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'cookieLastSearch' => $cookieArray]);
  1146.                 }
  1147.                 if ('blog' == $type) {
  1148.                     $cantDestinosBL count($destinosBlog);
  1149.                     $totalDestinosBL ceil($cantDestinosBL $cantRegis);
  1150.                     $pagination $paginator->paginate($destinosBlog$fullRequest->query->get('page'$page), $cantRegis);
  1151.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosBL'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  1152.                 }
  1153.             } else {
  1154.                 foreach ($articulos as $articulo) {
  1155.                     $description json_decode($articulo->getDescription(), true);
  1156.                     if (null == $description || is_array($description)) {
  1157.                         if (isset($description['type'])) {
  1158.                             if ('general' == $description['type']) {
  1159.                                 $generalArticles[] = $articulo;
  1160.                             }
  1161.                             if ('revista-horizontes' == $description['type']) {
  1162.                                 $revistaArticles[] = $articulo;
  1163.                             }
  1164.                             if ('informacion-aviatur' == $description['type']) {
  1165.                                 $informacionArticles[] = $articulo;
  1166.                             }
  1167.                         } else {
  1168.                             $actualArticles[] = $articulo;
  1169.                         }
  1170.                     }
  1171.                 }
  1172.                 if (empty($generalArticles) && empty($revistaArticles) && empty($informacionArticles)) {
  1173.                     return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  1174.                 }
  1175.                 /* Redireccion articulos contenido general, revista e información */
  1176.                 if (!empty($generalArticles) && !empty($revistaArticles) && !empty($informacionArticles)) {
  1177.                     if ('general' == $type) {
  1178.                         $cantGeneral count($generalArticles);
  1179.                         $totalGeneral ceil($cantGeneral $cantRegis);
  1180.                         $pagination $paginator->paginate($generalArticles$fullRequest->query->get('page'$page), $cantRegis);
  1181.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  1182.                     }
  1183.                     if ('revista-horizontes' == $type) {
  1184.                         $cantRevista count($revistaArticles);
  1185.                         $totalRevista ceil($cantRevista $cantRegis);
  1186.                         $pagination $paginator->paginate($revistaArticles$fullRequest->query->get('page'$page), $cantRegis);
  1187.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  1188.                     }
  1189.                     if ('informacion-aviatur' == $type) {
  1190.                         $cantInformacion count($informacionArticles);
  1191.                         $totalInformacion ceil($cantInformacion $cantRegis);
  1192.                         $pagination $paginator->paginate($informacionArticles$fullRequest->query->get('page'$page), $cantRegis);
  1193.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams]);
  1194.                     }
  1195.                 } else {
  1196.                     $cantdatos count($actualArticles);
  1197.                     $cantRegis 10;
  1198.                     $totalRegi ceil($cantdatos $cantRegis);
  1199.                     $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  1200.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl]);
  1201.                 }
  1202.             }
  1203.         }
  1204.     }
  1205.     public function searchAction(Request $requestSessionInterface $session)
  1206.     {
  1207.         $em $this->getDoctrine()->getManager();
  1208.         if ($request->isXmlHttpRequest()) {
  1209.             $agencyId $session->get('agencyId');
  1210.             $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  1211.             $term $request->query->get('term');
  1212.             $url $request->query->get('url');
  1213.             $pos strpos($url'tiquetes-baratos-a');
  1214.             if (false !== $pos) {
  1215.                 $queryIn $em->createQuery('SELECT a.id, a.title, a.url, a.description, a.isactive FROM AviaturContentBundle:Content a WHERE a.title LIKE :title AND a.description LIKE :description AND (a.agency = :agency OR a.agency IS NULL)');
  1216.                 $queryIn $queryIn->setParameter('title''%'.$term.'%');
  1217.                 $queryIn $queryIn->setParameter('description''%\"destinos\"%');
  1218.                 $queryIn $queryIn->setParameter('agency'$agency);
  1219.                 $articulos $queryIn->getResult();
  1220.             } else {
  1221.                 $queryIn $em->createQuery('SELECT a.id, a.title, a.url, a.description, a.isactive FROM AviaturContentBundle:Content a WHERE a.title LIKE :title AND a.description NOT LIKE :description AND a.description NOT LIKE :description1  AND (a.agency = :agency OR a.agency IS NULL)');
  1222.                 $queryIn $queryIn->setParameter('title''%'.$term.'%');
  1223.                 $queryIn $queryIn->setParameter('description''%\"destinos\"%');
  1224.                 $queryIn $queryIn->setParameter('description1''%\"autos\"%');
  1225.                 $queryIn $queryIn->setParameter('agency'$agency);
  1226.                 $articulos $queryIn->getResult();
  1227.             }
  1228.             $type '';
  1229.             $json_template '<value>:<label>*';
  1230.             $json '';
  1231.             if ($articulos) {
  1232.                 foreach ($articulos as $contenidos) {
  1233.                     $description json_decode($contenidos['description'], true);
  1234.                     if (null == $description || is_array($description)) {
  1235.                         if (isset($description['type'])) {
  1236.                             $type $description['type'];
  1237.                             if ('destinos' == $type) {
  1238.                                 $type $description['type2'];
  1239.                             }
  1240.                         } else {
  1241.                             $type 'general';
  1242.                         }
  1243.                     }
  1244.                     $json .= str_replace(['<value>''<label>'], [$contenidos['id'].'|'.$type.'|'.$contenidos['url'], $contenidos['title']], $json_template);
  1245.                 }
  1246.                 $json = \rtrim($json'-');
  1247.             } else {
  1248.                 $json 'NN:No hay Resultados';
  1249.             }
  1250.             $response = \rtrim($json'*');
  1251.             return new Response($response);
  1252.         } else {
  1253.             return new Response('Acceso Restringido');
  1254.         }
  1255.     }
  1256.     /*
  1257.      * Muestra la vista y ejecuta la creacion de un nuevo articulo
  1258.      */
  1259.     public function newAction(Request $requestSessionInterface $sessionTokenStorageInterface $tokenStorageTwigFolder $twigFolderValidatorInterface $validator)
  1260.     {
  1261.         $article = new Content();
  1262.         $em $this->getDoctrine()->getManager();
  1263.         $fullRequest $request;
  1264.         $routeParams $fullRequest->get('_route_params');
  1265.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($session->get('agencyId'));
  1266.         $agencyId $session->get('agencyId');
  1267.         $form $this->createForm(\Aviatur\ContentBundle\Form\ContentType::class, $article);
  1268.         $user $tokenStorage->getToken()->getUser();
  1269.         $caracteres = ['\\''¨''º''~''#''@''|''!''"''·''$''%''&''/''('')''?'"'"'¡''¿''[''^''`'']''+''}''{''¨''´''>''< '';'','':''.'' '];
  1270.         $form->handleRequest($request);
  1271.         if ($form->isSubmitted()) {
  1272.             $post $fullRequest->request->get('content_form');
  1273.             if ($form->isValid()) {
  1274.                 $newUrl str_replace($caracteres'-'mb_strtolower($post['url']));
  1275.                 $article->setUser($user);
  1276.                 $article->setAgency($agency);
  1277.                 $article->setTitle($post['title']);
  1278.                 $article->setDescription($post['description']);
  1279.                 $article->setText($fullRequest->request->get('notificacion'));
  1280.                 $article->setUrl($newUrl);
  1281.                 $article->setPublicationStartDate(new \DateTime());
  1282.                 $article->setPublicationEndDate(new \DateTime());
  1283.                 $article->setCreationDate(new \DateTime());
  1284.                 $article->setkeywords($post['keywords']);
  1285.                 $article->setIsactive(1);
  1286.                 $em $this->getDoctrine()->getManager();
  1287.                 $em->persist($article);
  1288.                 $postAll $fullRequest->request;
  1289.                 $info json_encode($postAll->all());
  1290.                 $historicalContent = new HistoricalContent();
  1291.                 $historicalContent->setContent($article);
  1292.                 $historicalContent->setCustomer($user);
  1293.                 $historicalContent->setInfo($info);
  1294.                 $historicalContent->setDate(new \DateTime());
  1295.                 $em->persist($historicalContent);
  1296.                 $em->flush();
  1297.                 if (isset($routeParams['content'])) {
  1298.                     return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
  1299.                 } else {
  1300.                     return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
  1301.                 }
  1302.             } else {
  1303.                 $errors $validator->validate($article);
  1304.                 $datos = ['agencyId' => $agencyId'form' => $form->createView(), 'errors' => $errors];
  1305.                 $agencyFolder $twigFolder->twigFlux();
  1306.                 return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/create.html.twig'), $datos);
  1307.             }
  1308.         } else {
  1309.             $agencyFolder $twigFolder->twigFlux();
  1310.             return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/create.html.twig'), ['agencyId' => $agencyId'form' => $form->createView()]);
  1311.         }
  1312.     }
  1313.     /*
  1314.      * Recibe parametro (id = identificador del articulo) para mostrar el articulo deseado
  1315.      */
  1316.     public function editAction(TwigFolder $twigFolder$id)
  1317.     {
  1318.         $em $this->getDoctrine()->getManager();
  1319.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
  1320.         $agencyFolder $twigFolder->twigFlux();
  1321.         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/edit.html.twig'), ['articulo' => $articulo'id' => $id'url' => 'edition']);
  1322.     }
  1323.     /*
  1324.      * Controlador que recibe parametro (id = identificador del articulo) para ejecutar el update del articulo
  1325.      */
  1326.     public function editionAction(Request $requestTokenStorageInterface $tokenStorage$id)
  1327.     {
  1328.         $routeParams $request->get('_route_params');
  1329.         $post $request->request;
  1330.         $caracteres = ['\\''¨''º''_''~''#''@''|''!''"''·''$''%''&''/''('')''?'"'"'¡''¿''[''^''`'']''+''}''{''¨''´''>''< '';'','':''.'' '];
  1331.         $newUrl str_replace($caracteres'-'mb_strtolower($post->get('url')));
  1332.         $user $tokenStorage->getToken()->getUser();
  1333.         $em $this->getDoctrine()->getManager();
  1334.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
  1335.         $articulo->setText($post->get('notificacion'));
  1336.         $articulo->setTitle($post->get('title'));
  1337.         $articulo->setUrl($newUrl);
  1338.         $articulo->setDescription($post->get('description'));
  1339.         $articulo->setkeywords($post->get('keywords'));
  1340.         $articulo->setPublicationEndDate(new \DateTime());
  1341.         $em->persist($articulo);
  1342.         $info json_encode($post->all());
  1343.         $historicalContent = new HistoricalContent();
  1344.         $historicalContent->setContent($articulo);
  1345.         $historicalContent->setCustomer($user);
  1346.         $historicalContent->setInfo($info);
  1347.         $historicalContent->setDate(new \DateTime());
  1348.         $em->persist($historicalContent);
  1349.         $em->flush();
  1350.         if (isset($routeParams['content'])) {
  1351.             return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
  1352.         } else {
  1353.             return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
  1354.         }
  1355.     }
  1356.     /*
  1357.      * Muestra el articulo al que se desea cambiar el estado
  1358.      */
  1359.     public function deleteAction(TwigFolder $twigFolder$id)
  1360.     {
  1361.         $em $this->getDoctrine()->getManager();
  1362.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
  1363.         $agencyFolder $twigFolder->twigFlux();
  1364.         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/edit.html.twig'), ['articulo' => $articulo'id' => $id'url' => 'deleting']);
  1365.     }
  1366.     /*
  1367.      * Recibe el parametro del articulo y cambia el estado para activar e inactivar
  1368.      */
  1369.     public function deletingAction(Request $requestTokenStorageInterface $tokenStorage$id)
  1370.     {
  1371.         $routeParams $request->get('_route_params');
  1372.         $post $request->request;
  1373.         $em $this->getDoctrine()->getManager();
  1374.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
  1375.         $isActive $articulo->getIsactive();
  1376.         $user $tokenStorage->getToken()->getUser();
  1377.         if (== $isActive):
  1378.             $isActive 1; else:
  1379.             $isActive 0;
  1380.         endif;
  1381.         $articulo->setIsactive($isActive);
  1382.         $articulo->setPublicationEndDate(new \DateTime());
  1383.         $em->persist($articulo);
  1384.         $info json_encode($post->all());
  1385.         $historicalContent = new HistoricalContent();
  1386.         $historicalContent->setContent($articulo);
  1387.         $historicalContent->setCustomer($user);
  1388.         $historicalContent->setInfo($info);
  1389.         $historicalContent->setIsactive($isActive);
  1390.         $historicalContent->setDate(new \DateTime());
  1391.         $em->persist($historicalContent);
  1392.         $em->flush();
  1393.         if (isset($routeParams['content'])) {
  1394.             return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
  1395.         } else {
  1396.             return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
  1397.         }
  1398.     }
  1399.     /*
  1400.      * Visualiza el articulo seleccionado
  1401.      */
  1402.     public function viewAction(Request $requestSessionInterface $sessionTwigFolder $twigFolder$id)
  1403.     {
  1404.         $em $this->getDoctrine()->getManager();
  1405.         $agencyId $session->get('agencyId');
  1406.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  1407.         $routeParams $request->get('_route_params');
  1408.         if (isset($routeParams['content']) && 'destinos' == $routeParams['content']) {
  1409.             $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyTypeNull($session->get('agencyId'), $id'%\"destinos\"%');
  1410.         } else {
  1411.             $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
  1412.         }
  1413.         if (isset($articulo[0]) && (null != $articulo[0])) {
  1414.             $agencyFolder $twigFolder->twigFlux();
  1415.             $description json_decode($articulo[0]->getDescription(), true);
  1416.             $url $articulo[0]->getURL();
  1417.             // determine content type based on eventual json encoded description
  1418.             if ($description && is_array($description)) {
  1419.                 $pos strpos($agencyFolder'aviatur');
  1420.                 if (false !== $pos) {
  1421.                     if ('aerolineas' == $description['type'] || 'destinos' == $description['type']) {
  1422.                         // eg: {"type":"destinos|aerolineas","type2":"nuevo|aerolinea|colombia|america|oceania|europa|africa|asia" , "description":"texto", "origin1":"BOG", "destination1":"MDE", "date1":"2016-11-18", "date2":"2016-11-25", "adults":"2", "children":"", "infants":""}
  1423.                         $cookieArray = [];
  1424.                         foreach ($description as $key => $value) {
  1425.                             $cookieArray[$key] = $value;
  1426.                         }
  1427.                         if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1428.                             $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1429.                             if (null == $ori) {
  1430.                                 $airport $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1431.                                 if (null != $airport) {
  1432.                                     $cookieArray['originLabel1'] = $airport->getName().', '.$airport->getCity().', '.$airport->getCountry().' ('.$airport->getIata().')';
  1433.                                 } else {
  1434.                                     $cookieArray['originLabel1'] = '';
  1435.                                 }
  1436.                             } else {
  1437.                                 $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1438.                             }
  1439.                         } else {
  1440.                             $cookieArray['originLabel1'] = '';
  1441.                         }
  1442.                         if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1443.                             $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1444.                             if (null == $dest || empty($dest)) {
  1445.                                 $airport $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1446.                                 if (null != $airport) {
  1447.                                     $cookieArray['destinationLabel1'] = $airport->getName().', '.$airport->getCity().', '.$airport->getCountry().' ('.$airport->getIata().')';
  1448.                                 } else {
  1449.                                     $cookieArray['destinationLabel1'] = '';
  1450.                                 }
  1451.                             } else {
  1452.                                 $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1453.                             }
  1454.                         } else {
  1455.                             $cookieArray['destinationLabel1'] = '';
  1456.                         }
  1457.                         $ticketsPromoList $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'vuelos-destinos''agency' => $agency]);
  1458.                         $ticketsPromosTitle '';
  1459.                         $ticketsPromosSubtitle '';
  1460.                         if ('aerolineas' == $description['type']) {
  1461.                             if ('avianca' == $url || 'vivaair' == $url || 'easyfly' == $url || 'satena' == $url || 'latam-airlines' == $url) {
  1462.                                 $ticketsPromoListAirline $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'vuelos-airlines''agency' => $agency]);
  1463.                                 if (null != $ticketsPromoListAirline) {
  1464.                                     $ticketsPromosTitle $ticketsPromoListAirline->getTitle();
  1465.                                     $ticketsPromosSubtitle $ticketsPromoListAirline->getSubtitle();
  1466.                                     if ('avianca' == $url || 'vivaair' == $url || 'easyfly' == $url || 'satena' == $url || 'latam-airlines' == $url) {
  1467.                                         $ticketsPromos $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['linkSwitch' => $url'homePromoList' => $ticketsPromoListAirline]);
  1468.                                     } else {
  1469.                                         $ticketsPromos = [];
  1470.                                     }
  1471.                                 } else {
  1472.                                     $ticketsPromos = [];
  1473.                                 }
  1474.                                 $promoType 'vuelos-airlines';
  1475.                             } else {
  1476.                                 if (null != $ticketsPromoList) {
  1477.                                     $ticketsPromos $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['content' => $url'homePromoList' => $ticketsPromoList], ['date' => 'DESC']);
  1478.                                 } else {
  1479.                                     $ticketsPromos = [];
  1480.                                 }
  1481.                                 $promoType 'vuelos-destinos';
  1482.                             }
  1483.                         } else {
  1484.                             if (null != $ticketsPromoList) {
  1485.                                 $ticketsPromos $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['content' => $url'homePromoList' => $ticketsPromoList], ['date' => 'DESC']);
  1486.                             } else {
  1487.                                 $ticketsPromos = [];
  1488.                             }
  1489.                             $promoType 'vuelos-destinos';
  1490.                         }
  1491.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/promo.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray'flightPromos' => $ticketsPromos'flightPromosTitle' => $ticketsPromosTitle'flightPromosSubtitle' => $ticketsPromosSubtitle'promoType' => $promoType]);
  1492.                     } else {
  1493.                         // eg: {"type":"nuevo|general|revista-horizontes|informacion-aviatur","column":"si|no","description":"texto"}
  1494.                         $cookieArray = [];
  1495.                         foreach ($description as $key => $value) {
  1496.                             $cookieArray[$key] = $value;
  1497.                         }
  1498.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray]);
  1499.                     }
  1500.                 } else {
  1501.                     $cookieArray = [];
  1502.                     foreach ($description as $key => $value) {
  1503.                         $cookieArray[$key] = $value;
  1504.                     }
  1505.                     if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  1506.                         $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  1507.                         $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  1508.                     } else {
  1509.                         $cookieArray['originLabel1'] = '';
  1510.                     }
  1511.                     if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  1512.                         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  1513.                         $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  1514.                     } else {
  1515.                         $cookieArray['destinationLabel1'] = '';
  1516.                     }
  1517.                     return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray]);
  1518.                 }
  1519.             }
  1520.             return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0]]);
  1521.         } else {
  1522.             throw $this->createNotFoundException('Contenido no encontrado');
  1523.         }
  1524.     }
  1525.     /*
  1526.      * Visualiza el articulo seleccionado en ventana sola
  1527.      */
  1528.     public function onlyAction(SessionInterface $sessionTwigFolder $twigFolder$id)
  1529.     {
  1530.         $em $this->getDoctrine()->getManager();
  1531.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
  1532.         if (isset($articulo[0]) && (null != $articulo[0])) {
  1533.             $agencyFolder $twigFolder->twigFlux();
  1534.             return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/only.html.twig'), ['articulo' => $articulo[0]]);
  1535.         } else {
  1536.             throw $this->createNotFoundException('Contenido no encontrado');
  1537.         }
  1538.     }
  1539.     /*
  1540.      * Trae URL de una imagen en el Twig para Open Graph SEO
  1541.      */
  1542.     public function extractUrlAction($separator1 null$separator2 null$text$type)
  1543.     {
  1544.         switch ($type) {
  1545.             case 'content':
  1546.                 $titleImage 'Aviatur';
  1547.                 $article $text;
  1548.                 $articleText $article->getText();
  1549.                 $pos strrpos($articleText, (string) $separator1);
  1550.                 $posSlider strrpos($articleText"background-image: url('");
  1551.                 if (false !== $pos) {
  1552.                     $posTitle strrpos($articleText'title="');
  1553.                     if (false !== $posTitle) {
  1554.                         $position strpos($articleText'title="');
  1555.                         $title substr($articleText$position strlen('title="'));
  1556.                         $newPosition strpos($title'"');
  1557.                         $titleImage substr($title0$newPosition);
  1558.                     }
  1559.                     $position strpos($articleText, (string) $separator1);
  1560.                     $srcImage substr($articleText$position strlen($separator1));
  1561.                     $posImage strrpos($srcImage, (string) $separator2);
  1562.                     if (false !== $posImage) {
  1563.                         $newPosition strpos($srcImage, (string) $separator2);
  1564.                         $newSrcImage substr($srcImage0$newPosition);
  1565.                         $validateImage strpos($newSrcImage'.html');
  1566.                         $validateVideo strpos($newSrcImage'.mp');
  1567.                         $validateVideoYTB strpos($newSrcImage'youtube.com');
  1568.                         if (false !== $validateImage || false !== $validateVideo || false !== $validateVideoYTB) {
  1569.                             return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => $titleImage]);
  1570.                         } else {
  1571.                             $validateUrl strpos($newSrcImage'.com');
  1572.                             if (false !== $validateUrl) {
  1573.                                 $urlImage $newSrcImage;
  1574.                             } else {
  1575.                                 $urlImage $_SERVER['SERVER_NAME'].$newSrcImage;
  1576.                             }
  1577.                             $url curl_init($urlImage);
  1578.                             curl_setopt($urlCURLOPT_TIMEOUT5);
  1579.                             curl_setopt($urlCURLOPT_CONNECTTIMEOUT5);
  1580.                             curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  1581.                             curl_setopt($urlCURLOPT_SSL_VERIFYPEERfalse);
  1582.                             curl_exec($url);
  1583.                             $httpcode curl_getinfo($urlCURLINFO_HTTP_CODE);
  1584.                             curl_close($url);
  1585.                             if (200 == $httpcode || 301 == $httpcode) {
  1586.                                 return $this->json(['img' => $newSrcImage'title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1587.                             } else {
  1588.                                 return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1589.                             }
  1590.                         }
  1591.                     }
  1592.                 } elseif (false !== $posSlider) {
  1593.                     $separator1 "background-image: url('";
  1594.                     $separator2 "');";
  1595.                     $posTitle strrpos($articleText'title="');
  1596.                     if (false !== $posTitle) {
  1597.                         $position strpos($articleText'title="');
  1598.                         $title substr($articleText$position strlen('title="'));
  1599.                         $newPosition strpos($title'"');
  1600.                         $titleImage substr($title0$newPosition);
  1601.                     }
  1602.                     $position strpos($articleText$separator1);
  1603.                     $srcImage substr($articleText$position strlen($separator1));
  1604.                     $posImage strrpos($srcImage$separator2);
  1605.                     if (false !== $posImage) {
  1606.                         $newPosition strpos($srcImage$separator2);
  1607.                         $newSrcImage substr($srcImage0$newPosition);
  1608.                         $validateImage strpos($newSrcImage'.html');
  1609.                         $validateVideo strpos($newSrcImage'.mp');
  1610.                         $validateVideoYTB strpos($newSrcImage'youtube.com');
  1611.                         if (false !== $validateImage || false !== $validateVideo || false !== $validateVideoYTB) {
  1612.                             return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => $titleImage]);
  1613.                         } else {
  1614.                             $validateUrl strpos($newSrcImage'.com');
  1615.                             if (false !== $validateUrl) {
  1616.                                 $urlImage $newSrcImage;
  1617.                             } else {
  1618.                                 $urlImage $_SERVER['SERVER_NAME'].$newSrcImage;
  1619.                             }
  1620.                             $url curl_init($urlImage);
  1621.                             curl_setopt($urlCURLOPT_TIMEOUT5);
  1622.                             curl_setopt($urlCURLOPT_CONNECTTIMEOUT5);
  1623.                             curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  1624.                             curl_setopt($urlCURLOPT_SSL_VERIFYPEERfalse);
  1625.                             curl_exec($url);
  1626.                             $httpcode curl_getinfo($urlCURLINFO_HTTP_CODE);
  1627.                             curl_close($url);
  1628.                             if (200 == $httpcode || 301 == $httpcode) {
  1629.                                 return $this->json(['img' => $newSrcImage'title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1630.                             } else {
  1631.                                 return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1632.                             }
  1633.                         }
  1634.                     } else {
  1635.                         $validateImage strpos($srcImage'.html');
  1636.                         $validateJs strpos($srcImage'.js');
  1637.                         if (false !== $validateImage || false !== $validateJs) {
  1638.                             return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1639.                         } else {
  1640.                             return $this->json(['img' => $srcImage'title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1641.                         }
  1642.                     }
  1643.                 } else {
  1644.                     return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp''title' => html_entity_decode($titleImageENT_QUOTES'UTF-8')]);
  1645.                 }
  1646.                 break;
  1647.             case 'availability':
  1648.                 $srcImage $_SERVER['SERVER_NAME'].'/assets/aviatur_assets/img/places/'.$text.'.jpg';
  1649.                 $url curl_init($srcImage);
  1650.                 curl_setopt($urlCURLOPT_TIMEOUT5);
  1651.                 curl_setopt($urlCURLOPT_CONNECTTIMEOUT5);
  1652.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  1653.                 curl_setopt($urlCURLOPT_SSL_VERIFYPEERfalse);
  1654.                 curl_exec($url);
  1655.                 $httpcode curl_getinfo($urlCURLINFO_HTTP_CODE);
  1656.                 curl_close($url);
  1657.                 if (200 == $httpcode || 301 == $httpcode) {
  1658.                     return new Response('/assets/aviatur_assets/img/places/'.$text.'.jpg');
  1659.                 } else {
  1660.                     return new Response('/assets/aviatur_assets/img/header/aviatur_logo.png');
  1661.                 }
  1662.                 break;
  1663.         }
  1664.         return new Response('/assets/aviatur_assets/img/header/aviatur_logo.png');
  1665.     }
  1666.     public function weatherAction($citySearch)
  1667.     {
  1668.         $forecastJson = [];
  1669.         $em $this->getDoctrine()->getManager();
  1670.         $key 'e211234b154f087975c17e74cb343e0b';
  1671.         /* $key = "2c573f0ce919bbb3221089f625cf78a4"; key pruebas */
  1672.         setlocale(LC_ALL'es_CO''esp');
  1673.         $countries = ['á''é''í''ó''ú''Brasil''Mexico, Mexico''Rusia',
  1674.             'La Coruña, España''España''Republica Checa''Estados Unidos''Republica Irlanda''Francia',
  1675.             'Republica Dominicana''Alemania''Japon''Nueva Zelanda''Turquia',
  1676.             'Tailandia''Emiratos Arabes Unidos''Curacao, Curaçao''Bélgica',
  1677.             'Aruba, Aruba''Paises Bajos''Argelia''Camboya Riel''Congo Brazzaville',
  1678.             'Costa de Marfil''Croacia''Dinamarca''Eslovaquia''Eslovenia''Etiopia',
  1679.             'Filipinas''Finlandia''Grecia''Hungria''Laos''Lituania''Noruega',
  1680.             'Sudafrica''Corea del Norte''Corea del Sur (Republica)''Republica Camerun',
  1681.             'Republica Centro-Africana''Republica Democratica del Congo''Edimburgo, Gran Bretaña',
  1682.             'Gran Bretaña''Italia''Venecia, Italy''Milan, Italy''Roma, Italy',
  1683.             ', Egipto''Dakhla Oasis''Santa Katarina''Taba''Alejandria''Suiza''Marruecos''Zimbabue',
  1684.             'Ucrania''Tunez''Suecia''Siria''San Vicente y Las Granadinas''Rumania''Puerto Carreno',
  1685.             'Afganistan''Arabia Saudi''Bielorusia''Groenlandia''Guadalupe''Guayana''Guayana Francesa',
  1686.             'Guinea Conakry''Guinea Ecuatorial''Islandia''Kenia''Nueva Caledonia''Papua Nueva Guinea',
  1687.             'Polonia''Singapore, Singapore''Varsovia''Estocolmo''Estrasburgo''Filadelfia''Malasya',
  1688.             'Luxembourg, Luxemburgo', ];
  1689.         $replace = ['a''e''i''o''u''Brazil''Distrito Federal, Mexico''Russia',
  1690.             'La Coruña''Spain''Czech Republic''United States of America''Ireland''France',
  1691.             'Dominican Republic''Germany''Japan''New Zealand''Turkey',
  1692.             'Thailand''United Arab Emirates''Willemstad, Curazao''Belgium',
  1693.             'Oranjestad, Aruba''Netherlands''Algeria''Cambodia''Congo',
  1694.             "Cote d'Ivoire"'Croatia''Denmark''Slovakia''Slovenia''Ethiopia',
  1695.             'Philippines''Finland''Greece''Hungary'"Lao People's Democratic Republic",
  1696.             'Lithuania''Norway''South Africa''North Korea''South Korea''Cameroon',
  1697.             'Central African Republic''Democratic Republic of Congo''Edimburgo',
  1698.             'United Kingdom''Italy''Venecia''Milan''Roma, Italia''',
  1699.             'Dakhla Oasis, Egipto''Santa Katarina, Egipto''Taba, Egypt''Alejandría''Switzerland''Morocco',
  1700.             'Zimbabwe''Ukraine''Tunisia''Sweden''Syria''Saint Vincent and the Grenadines',
  1701.             'Romania''Colombia''Afghanistan''Saudi Arabia''Belarus''Greenland''Guadeloupe',
  1702.             'Guyana''French Guiana''Guinea''Equatorial Guinea''Iceland''Kenya''New Caledonia',
  1703.             'Papua New Guinea''Poland''Singapore, Singapur''Warsaw''Stockholm''Strasburg''Philadelphia',
  1704.             'Malaysia''Luxembourg, Luxembourg', ];
  1705.         $location = ['Brazil''Russia''Spain''Czech Republic''United States of America',
  1706.             'Ireland''France''Dominican Republic''Germany''Japan''New Zealand''Turkey',
  1707.             'Thailand''United Arab Emirates''Willemstad, Países Bajos Antilles''Belgica''Netherlands''Algeria''Cambodia',
  1708.             "Cote d'Ivoire"'Croatia''Denmark''Slovakia''Slovenia''Ethiopia',
  1709.             'Philippines''Finland''Greece''Hungary'"Lao People's Democratic Republic",
  1710.             'Lithuania''Norway''South Africa''North Korea''South Korea''Cameroon',
  1711.             'Central African Republic''Democratic Republic of Congo''United Kingdom''Reino Unido',
  1712.             'Italy''Itália''Egypt''Switzerland''Morocco''Zimbabwe''Ukraine''Tunisia',
  1713.             'Sweden''Syria''Saint Vincent and the Grenadines''Romania''Afghanistan''Saudi Arabia',
  1714.             'Belarus''Greenland''Guadeloupe''Guyana''French Guiana''Guinea''Equatorial Guinea',
  1715.             'Iceland''Kenya''New Caledonia''Papua New Guinea''Poland''Singapore, Singapore''Warsaw''Stockholm',
  1716.             'Strasburg''Philadelphia''Malaysia''Luxembourg, Luxembourg', ];
  1717.         $replaceLocation = ['Brasil''Rusia''España''República Checa''Estados Unidos',
  1718.             'República Irlanda''Francia''República Dominicana''Alemania''Japón''Nueva Zelanda''Turquía',
  1719.             'Tailandia''Emiratos Arabes Unidos''Willemstad, Curaçao''Bélgica''Países Bajos''Argelia''Camboya Riel',
  1720.             'Costa de Marfil''Croacia''Dinamarca''Eslovaquia''Eslovenia''Etiopia',
  1721.             'Filipinas''Finlandia''Grecia''Hungría''Laos''Lituania''Noruega',
  1722.             'Sudáfrica''Corea del Norte''Corea del Sur (República)''República Camerun',
  1723.             'República Centro-Africana''República Democratica del Congo''Gran Bretaña''Gran Bretaña',
  1724.             'Italia''Italia''Egipto''Suiza''Marruecos''Zimbabue''Ucrania''Túnez',
  1725.             'Suecia''Siria''San Vicente y Las Granadinas''Rumanía''Afganistán''Arabia Saudí',
  1726.             'Bielorusia''Groenlandia''Guadalupe''Guayana''Guayana Francesa''Guinea Conakry''Guinea Ecuatorial',
  1727.             'Islandia''Kenia''Nueva Caledonia''Papua Nueva Guinea''Polonia''Singapore, Singapur''Varsovia''Estocolmo',
  1728.             'Estrasburgo''Filadelfia''Malasya''Luxembourg, Luxemburgo', ];
  1729.         $findCity preg_replace("/\((.*?)\)/i"''$citySearch); /* Quitar parentesis y su contenido */
  1730.         $searchCity str_replace($countries$replacetrim($findCity));
  1731.         $city urlencode($searchCity);
  1732.         $url "https://api.weatherstack.com/forecast?access_key=$key&language=es&query=$city&forecast_days=7&hourly=1&interval=24";
  1733.         $searchWeather $em->getRepository(\Aviatur\GeneralBundle\Entity\Weather::class)->findBy(['location' => trim($findCity)]);
  1734.         $ch curl_init();
  1735.         curl_setopt($chCURLOPT_URL$url);
  1736.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1737.         curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1738.         $json_output curl_exec($ch);
  1739.         $weather json_decode($json_output);
  1740.         if (isset($weather->success) && !$weather->success) {
  1741.             return $this->json('Error API');
  1742.         } else {
  1743.             if (!empty($searchWeather)) {
  1744.                 $timeCurrent = new \DateTime(date('Y-m-d H:i:s'));
  1745.                 $timeBD = new \DateTime($searchWeather[0]->getEntrydate()->format('Y-m-d H:i:s'));
  1746.                 $difference $timeCurrent->diff($timeBD);
  1747.                 $differenceDate $difference->days;
  1748.                 $differenceHour $difference->format('%H');
  1749.                 if ('0' == $differenceDate && $differenceHour '4') { /* Si no ha pasado mas de 4 horas o 1 día no se actualiza el registro en BD */
  1750.                     $forecast json_decode($searchWeather[0]->getForecast(), true);
  1751.                     $forecastArray = [];
  1752.                     if ($forecast && is_array($forecast)) {
  1753.                         foreach ($forecast as $key => $value) {
  1754.                             $forecastArray[$key] = $value;
  1755.                         }
  1756.                         $weatherInfo = [];
  1757.                         $dateLocale strtotime($searchWeather[0]->getDay()->format('Y-m-d'));
  1758.                         $dateCurrent strftime('%B %d'$dateLocale);
  1759.                         $countDays count($forecastArray) / 5;
  1760.                         for ($i 0$i $countDays; ++$i) {
  1761.                             $dateWeather = new \DateTime($forecastArray['date'.$i]);
  1762.                             $actualDate = new \DateTime($searchWeather[0]->getDay()->format('Y-m-d'));
  1763.                             $difference $actualDate->diff($dateWeather);
  1764.                             $differenceDates $difference->format('%r%a');
  1765.                             if ($differenceDates 0) {
  1766.                                 $time strtotime($forecastArray['date'.$i]);
  1767.                                 $date strftime('%B %d'$time);
  1768.                                 $icon $forecastArray['icon'.$i];
  1769.                                 $weatherInfo[$i] = [
  1770.                                     'date' => $date,
  1771.                                     'icon' => $icon,
  1772.                                     'condition' => $forecastArray['condition'.$i],
  1773.                                     'maxTemp' => $forecastArray['maxTemp'.$i],
  1774.                                     'minTemp' => $forecastArray['minTemp'.$i],
  1775.                                     'dateFormat' => $forecastArray['date'.$i],
  1776.                                 ];
  1777.                             }
  1778.                         }
  1779.                         foreach ($searchWeather as $weather) {
  1780.                             $weatherInfo['current'] = [
  1781.                                 'locationName' => $weather->getlocation(),
  1782.                                 'background' => '/assets/aviatur_assets/img/weather/background/'.((== $weather->getIsday()) ? 'is-day.jpg' 'is-night.jpg'),
  1783.                                 'dateCurrent' => $dateCurrent,
  1784.                                 'dateFormat' => $searchWeather[0]->getDay()->format('Y-m-d'),
  1785.                                 'temp' => $weather->getTemperature(),
  1786.                                 'condition' => $weather->getState(),
  1787.                                 'icon' => '/assets/aviatur_assets/img/weather/icons/'.$weather->getIcon(),
  1788.                             ];
  1789.                         }
  1790.                         return $this->json($weatherInfo);
  1791.                     } else {
  1792.                         return $this->json('No se encontro la ubicación');
  1793.                     }
  1794.                 } else { /* Si ha pasado mas de 4 horas o 1 día se actualiza el registro en BD */
  1795.                     $ch curl_init();
  1796.                     curl_setopt($chCURLOPT_URL$url);
  1797.                     curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1798.                     curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  1799.                     $json_output curl_exec($ch);
  1800.                     $weather json_decode($json_output);
  1801.                     if (isset($weather->location) && isset($weather->forecast)) {
  1802.                         $forecastUpdate = [];
  1803.                         $forecastSearch = [];
  1804.                         foreach ($weather->forecast as $key => $value) {
  1805.                             $forecastSearch[] = $value;
  1806.                         }
  1807.                         $indice 0;
  1808.                         $dateA substr($weather->location->localtime0, -5);
  1809.                         $dateLocale strtotime($dateA);
  1810.                         $dateCurrent strftime('%B %d'$dateLocale);
  1811.                         for ($i 1$i count($forecastSearch); ++$i) {
  1812.                             $time strtotime($forecastSearch[$i]->date);
  1813.                             setlocale(LC_ALL'es_CO''esp');
  1814.                             $date strftime('%B %d'$time);
  1815.                             $icon explode('_64/'$forecastSearch[$i]->hourly[0]->weather_icons[0]);
  1816.                             $forecastUpdate[$indice] = [
  1817.                                 'date' => $date,
  1818.                                 'icon' => '/assets/aviatur_assets/img/weather/icons/'.$icon[1],
  1819.                                 'condition' => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
  1820.                                 'maxTemp' => $forecastSearch[$i]->maxtemp,
  1821.                                 'minTemp' => $forecastSearch[$i]->mintemp,
  1822.                                 'dateFormat' => $forecastSearch[$i]->date,
  1823.                             ];
  1824.                             $forecastJson[$indice] = [
  1825.                                 'date'.$indice => $forecastSearch[$i]->date,
  1826.                                 'icon'.$indice => '/assets/aviatur_assets/img/weather/icons/'.$icon[1],
  1827.                                 'condition'.$indice => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
  1828.                                 'maxTemp'.$indice => $forecastSearch[$i]->maxtemp,
  1829.                                 'minTemp'.$indice => $forecastSearch[$i]->mintemp,
  1830.                             ];
  1831.                             ++$indice;
  1832.                         }
  1833.                         $iconCurrent explode('_64/'$weather->current->weather_icons[0]);
  1834.                         $background = ('yes' == $weather->current->is_day) ? 'is-day.jpg' 'is-night.jpg';
  1835.                         if ('Puerto Rico' == $weather->location->region) {
  1836.                             $name $weather->location->name.', '.$weather->location->region;
  1837.                         } else {
  1838.                             $name $weather->location->name.', '.$weather->location->country;
  1839.                         }
  1840.                         $locationName str_replace($location$replaceLocation$name);
  1841.                         $forecastUpdate['current'] = [
  1842.                             'locationName' => $locationName,
  1843.                             'icon' => '/assets/aviatur_assets/img/weather/icons/'.$iconCurrent[1],
  1844.                             'background' => '/assets/aviatur_assets/img/weather/background/'.$background,
  1845.                             'temp' => $weather->current->temperature,
  1846.                             'condition' => $weather->current->weather_descriptions_es[0],
  1847.                             'dateCurrent' => $dateCurrent,
  1848.                             'dateFormat' => $dateA, ];
  1849.                         $acentos = ['á''é''í''ó''ú'];
  1850.                         $replaceAcentos = ['a''e''i''o''u'];
  1851.                         $country explode(', 'trim($findCity));
  1852.                         $countryReplace str_replace($acentos$replaceAcentos$country);
  1853.                         $countrySearch explode(', '$locationName);
  1854.                         $countrySearchReplace str_replace($acentos$replaceAcentos$countrySearch);
  1855.                         if ($countryReplace[1] == $countrySearchReplace[1]) {
  1856.                             $forecastW json_encode($forecastJson);
  1857.                             $forecastJSON trim($forecastW'[]');
  1858.                             $forecastJSON str_replace('},{'','$forecastJSON);
  1859.                             $idWeather $searchWeather[0]->getId();
  1860.                             $Weather $em->getRepository(\Aviatur\GeneralBundle\Entity\Weather::class)->find($idWeather);
  1861.                             $Weather->setDay(new \DateTime($dateA));
  1862.                             $Weather->setIsday(('yes' == $weather->current->is_day) ? 0);
  1863.                             $Weather->setTemperature($forecastUpdate['current']['temp']);
  1864.                             $Weather->setState($forecastUpdate['current']['condition']);
  1865.                             $Weather->setIcon($iconCurrent[1]);
  1866.                             $Weather->setForecast($forecastJSON);
  1867.                             $Weather->setEntryDate(new \DateTime());
  1868.                             $em->persist($Weather);
  1869.                             $em->flush();
  1870.                             return $this->json($forecastUpdate);
  1871.                         } else {
  1872.                             return $this->json('No se encontro la ubicación');
  1873.                         }
  1874.                     } else {
  1875.                         return $this->json('No se encontro la ubicación');
  1876.                     }
  1877.                 }
  1878.             } else { /* Se genera nuevo registro en la BD */
  1879.                 if (isset($weather->location) && isset($weather->forecast)) {
  1880.                     $forecastNew = [];
  1881.                     $indice 0;
  1882.                     $dateC substr($weather->location->localtime0, -5);
  1883.                     $dateLocale strtotime($dateC);
  1884.                     $dateCurrent strftime('%B %d'$dateLocale);
  1885.                     $forecastSearch = [];
  1886.                     $iconCurrent explode('_64/'$weather->current->weather_icons[0]);
  1887.                     $background = ('yes' == $weather->current->is_day) ? 'is-day.jpg' 'is-night.jpg';
  1888.                     foreach ($weather->forecast as $key => $value) {
  1889.                         $forecastSearch[] = $value;
  1890.                     }
  1891.                     for ($i 1$i count($forecastSearch); ++$i) {
  1892.                         $dateWeather = new \DateTime($forecastSearch[$i]->date);
  1893.                         $currentDate = new \DateTime($dateC);
  1894.                         $difference $currentDate->diff($dateWeather);
  1895.                         $differenceDates $difference->format('%r%a');
  1896.                         if ($differenceDates 0) {
  1897.                             $time strtotime($forecastSearch[$i]->date);
  1898.                             setlocale(LC_ALL'es_CO''esp');
  1899.                             $date strftime('%B %d'$time);
  1900.                             $icon $iconCurrent[1];
  1901.                             $forecastNew[$indice] = [
  1902.                                 'date' => $date,
  1903.                                 'icon' => '/assets/aviatur_assets/img/weather/icons/'.$icon,
  1904.                                 'condition' => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
  1905.                                 'maxTemp' => $forecastSearch[$i]->maxtemp,
  1906.                                 'minTemp' => $forecastSearch[$i]->mintemp,
  1907.                                 'dateFormat' => $forecastSearch[$i]->date,
  1908.                             ];
  1909.                             $forecastJson[$indice] = [
  1910.                                 'date'.$indice => $forecastSearch[$i]->date,
  1911.                                 'icon'.$indice => '/assets/aviatur_assets/img/weather/icons/'.$icon,
  1912.                                 'condition'.$indice => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
  1913.                                 'maxTemp'.$indice => $forecastSearch[$i]->maxtemp,
  1914.                                 'minTemp'.$indice => $forecastSearch[$i]->mintemp,
  1915.                             ];
  1916.                             ++$indice;
  1917.                         }
  1918.                     }
  1919.                     if ('Puerto Rico' == $weather->location->region) {
  1920.                         $name $weather->location->name.', '.$weather->location->region;
  1921.                     } else {
  1922.                         $name $weather->location->name.', '.$weather->location->country;
  1923.                     }
  1924.                     $locationName str_replace($location$replaceLocation$name);
  1925.                     $forecastNew['current'] = [
  1926.                         'locationName' => $locationName,
  1927.                         'icon' => '/assets/aviatur_assets/img/weather/icons/'.$iconCurrent[1],
  1928.                         'background' => '/assets/aviatur_assets/img/weather/background/'.$background,
  1929.                         'temp' => $weather->current->temperature,
  1930.                         'condition' => $weather->current->weather_descriptions_es[0],
  1931.                         'dateCurrent' => $dateCurrent,
  1932.                         'dateFormat' => $dateC,
  1933.                     ];
  1934.                     $acentos = ['á''é''í''ó''ú'];
  1935.                     $replaceAcentos = ['a''e''i''o''u'];
  1936.                     $country explode(', 'trim($findCity));
  1937.                     $countryReplace str_replace($acentos$replaceAcentos$country);
  1938.                     $countrySearch explode(', '$locationName);
  1939.                     $countrySearchReplace str_replace($acentos$replaceAcentos$countrySearch);
  1940.                     if ($countryReplace[1] == $countrySearchReplace[1]) {
  1941.                         $jsonForecast json_encode($forecastJson);
  1942.                         $forecastJSON trim($jsonForecast'[]');
  1943.                         $forecastJSON str_replace('},{'','$forecastJSON);
  1944.                         $weatherAdd = new Weather();
  1945.                         $weatherAdd->setLocation(trim($findCity));
  1946.                         $weatherAdd->setDay(new \DateTime($dateC));
  1947.                         $weatherAdd->setIsday(('yes' == $weather->current->is_day) ? 0);
  1948.                         $weatherAdd->setTemperature($forecastNew['current']['temp']);
  1949.                         $weatherAdd->setState($forecastNew['current']['condition']);
  1950.                         $weatherAdd->setIcon($iconCurrent[1]);
  1951.                         $weatherAdd->setForecast($forecastJSON);
  1952.                         $weatherAdd->setEntrydate(new \DateTime());
  1953.                         $em->persist($weatherAdd);
  1954.                         $em->flush();
  1955.                         return $this->json($forecastNew);
  1956.                     } else {
  1957.                         return $this->json('No se encontro la ubicación');
  1958.                     }
  1959.                 } else {
  1960.                     return $this->json('No se encontro la ubicación');
  1961.                 }
  1962.             }
  1963.         }
  1964.     }
  1965.     public function promoTicketsAction(SessionInterface $session)
  1966.     {
  1967.         $em $this->getDoctrine()->getManager();
  1968.         $agencyId $session->get('agencyId');
  1969.         $homePromoList $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findBy(['type' => '__tiquetes''agency' => $agencyId]);
  1970.         $promos = [];
  1971.         $indice 0;
  1972.         if (null != $homePromoList) {
  1973.             $homePromos $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoList);
  1974.             for ($i 0$i < (is_countable($homePromos) ? count($homePromos) : 0); ++$i) {
  1975.                 $city $homePromos[$i]->getTitle();
  1976.                 $country $homePromos[$i]->getTitleSwitch();
  1977.                 $pos strpos($city'-');
  1978.                 $pos1 strpos($city' a ');
  1979.                 if (false != $pos) {
  1980.                     $cityArray explode('-'$city);
  1981.                     $city trim($cityArray[0]);
  1982.                     $dataCity $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city'country' => $country]);
  1983.                 } elseif (false != $pos1) {
  1984.                     $cityArray explode(' a '$city);
  1985.                     $city trim($cityArray[1]);
  1986.                     $dataCity $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city'country' => $country]);
  1987.                 } else {
  1988.                     $dataCity $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city'country' => $country]);
  1989.                 }
  1990.                 if (!empty($dataCity)) {
  1991.                     foreach ($dataCity as $data) {
  1992.                         $iataCode $data->getIata();
  1993.                     }
  1994.                 } else {
  1995.                     $iataCode 'null';
  1996.                 }
  1997.                 $promos[$indice] = [
  1998.                     'id' => $homePromos[$i]->getId(),
  1999.                     'city' => $homePromos[$i]->getTitle(),
  2000.                     'country' => $homePromos[$i]->getTitleSwitch(),
  2001.                     'description' => $homePromos[$i]->getContent(),
  2002.                     'price' => $homePromos[$i]->getPrice(),
  2003.                     'url' => $homePromos[$i]->getLink(),
  2004.                     'urlImage' => $homePromos[$i]->getLinkSwitch(),
  2005.                     'date' => $homePromos[$i]->getDate(),
  2006.                     'iata' => $iataCode,
  2007.                     'promoType' => '__tiquetes',
  2008.                 ];
  2009.                 ++$indice;
  2010.             }
  2011.             return $this->json($promos);
  2012.         } else {
  2013.             $homePromos = [];
  2014.             return $this->json($homePromos);
  2015.         }
  2016.     }
  2017. }