src/Aviatur/BlogBundle/Controller/DefaultController.php line 510

Open in your IDE?
  1. <?php
  2. namespace Aviatur\BlogBundle\Controller;
  3. use Aviatur\FormBundle\Entity\Newsletter;
  4. use Aviatur\GeneralBundle\Services\AviaturErrorHandler;
  5. use Aviatur\TwigBundle\Services\TwigFolder;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  12. class DefaultController extends AbstractController
  13. {
  14.     public function indexAction(Request $requestSessionInterface $sessionTwigFolder $twigFolderAuthorizationCheckerInterface $authorizationCheckerAviaturErrorHandler $errorHandlerPaginatorInterface $paginator$page$active)
  15.     {
  16.         $em $this->getDoctrine()->getManager();
  17.         $fullRequest $request;
  18.         $routeParams $fullRequest->attributes->get('_route_params');
  19.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
  20.         $agencyId $session->get('agencyId');
  21.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  22.         $agencyFolder $twigFolder->twigFlux();
  23.         $homePromoList $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'slider''agency' => $agency]);
  24.         $homePromos $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoList, ['date' => 'DESC']);
  25.         $homePromoListMain $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'main_slider''agency' => $agency]);
  26.         $homePromosMain $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoListMain);
  27.         $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');
  28.         $query $query->setParameter('agency'$agency);
  29.         $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');
  30.         $queryIn $queryIn->setParameter('agency'$agency);
  31.         if ('activo' == $active) {
  32.             $articulos $query->getResult();
  33.         } elseif ('inactivo' == $active) {
  34.             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')) {
  35.                 $articulos $queryIn->getResult();
  36.             } else {
  37.                 return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
  38.             }
  39.         }
  40.         $actualArticles = [];
  41.         foreach ($articulos as $articulo) {
  42.             $description json_decode($articulo->getDescription(), true);
  43.             if ($description && is_array($description) && 'general' == $description['type']) {
  44.                 $actualArticles[] = $articulo;
  45.             }
  46.         }
  47.         if (empty($actualArticles)) {
  48.             return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  49.         }
  50.         $cantdatos count($actualArticles);
  51.         $cantRegis 6;
  52.         $totalRegi ceil($cantdatos $cantRegis);
  53.         $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  54.         $blog = new Newsletter();
  55.         $blogForm $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
  56.         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/index.html.twig'), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRegi'ajaxUrl' => $requestUrl'slider' => $homePromos'contenidos' => $homePromosMain'blog_form' => $blogForm->createView()]);
  57.     }
  58.     public function indexDestinosAction(Request $requestSessionInterface $sessionTwigFolder $twigFolder)
  59.     {
  60.         $em $this->getDoctrine()->getManager();
  61.         $fullRequest $request;
  62.         $routeParams $fullRequest->attributes->get('_route_params');
  63.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
  64.         $agencyId $session->get('agencyId');
  65.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  66.         $agencyFolder $twigFolder->twigFlux();
  67.         $blog = new Newsletter();
  68.         $blogForm $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
  69.         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/destinos.html.twig'), ['blog_form' => $blogForm->createView()]);
  70.     }
  71.     public function listAction(Request $requestSessionInterface $sessionTwigFolder $twigFolderAviaturErrorHandler $errorHandlerPaginatorInterface $paginator$page$active$type)
  72.     {
  73.         $em $this->getDoctrine()->getManager();
  74.         $fullRequest $request;
  75.         $routeParams $fullRequest->attributes->get('_route_params');
  76.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
  77.         $agencyId $session->get('agencyId');
  78.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
  79.         $agencyFolder $twigFolder->twigFlux();
  80.         $blog = new Newsletter();
  81.         $blogForm $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
  82.         if ($fullRequest->isXmlHttpRequest()) {
  83.             $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.publicationenddate DESC');
  84.             $query $query->setParameter('agency'$agency);
  85.             $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.publicationenddate DESC');
  86.             $queryIn $queryIn->setParameter('agency'$agency);
  87.             if (isset($routeParams['content'])) {
  88.                 $path '/Blog/Default/Ajaxindex_destinos.html.twig';
  89.             } else {
  90.                 $path '/Blog/Default/Ajaxindex_contenidos.html.twig';
  91.             }
  92.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  93.             $colombia = [];
  94.             $america = [];
  95.             $oceania = [];
  96.             $europa = [];
  97.             $africa = [];
  98.             $asia = [];
  99.             $tipsArticles = [];
  100.             $gastronomiaArticles = [];
  101.             $experienciasArticles = [];
  102.             $actualArticles = [];
  103.             $cantRegis 9;
  104.             if ('activo' == $active) {
  105.                 $articulos $query->getResult();
  106.             }
  107.             if (isset($routeParams['content'])) {
  108.                 if ('general' == $type) {
  109.                     foreach ($articulos as $articulo) {
  110.                         $description json_decode($articulo->getDescription(), true);
  111.                         if ($description && is_array($description)) {
  112.                             if ('destinos-blog' == $description['type']) {
  113.                                 $actualArticles[] = $articulo;
  114.                             }
  115.                         }
  116.                     }
  117.                     if (empty($actualArticles)) {
  118.                         return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  119.                     }
  120.                     $cantDestinos count($actualArticles);
  121.                     $totalDestinos ceil($cantDestinos $cantRegis);
  122.                     $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  123.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinos'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  124.                 } else {
  125.                     foreach ($articulos as $articulo) {
  126.                         $description json_decode($articulo->getDescription(), true);
  127.                         if ($description && is_array($description)) {
  128.                             if ('destinos-blog' == $description['type'] && 'colombia' == $description['type2']) {
  129.                                 $colombia[] = $articulo;
  130.                             }
  131.                             if ('destinos-blog' == $description['type'] && 'america' == $description['type2']) {
  132.                                 $america[] = $articulo;
  133.                             }
  134.                             if ('destinos-blog' == $description['type'] && 'oceania' == $description['type2']) {
  135.                                 $oceania[] = $articulo;
  136.                             }
  137.                             if ('destinos-blog' == $description['type'] && 'europa' == $description['type2']) {
  138.                                 $europa[] = $articulo;
  139.                             }
  140.                             if ('destinos-blog' == $description['type'] && 'africa' == $description['type2']) {
  141.                                 $africa[] = $articulo;
  142.                             }
  143.                             if ('destinos-blog' == $description['type'] && 'asia' == $description['type2']) {
  144.                                 $asia[] = $articulo;
  145.                             }
  146.                         }
  147.                     }
  148.                     if (empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  149.                         return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  150.                     }
  151.                     
  152.                     /* Redireccion articulos destinos y aerolineas */
  153.                     if ('colombia' == $type) {
  154.                         $cantDestinosC count($colombia);
  155.                         $totalDestinosC ceil($cantDestinosC $cantRegis);
  156.                         $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  157.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  158.                     }
  159.                     if ('america' == $type) {
  160.                         $cantDestinosA count($america);
  161.                         $totalDestinosA ceil($cantDestinosA $cantRegis);
  162.                         $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  163.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  164.                     }
  165.                     if ('oceania' == $type) {
  166.                         $cantDestinosO count($oceania);
  167.                         $totalDestinosO ceil($cantDestinosO $cantRegis);
  168.                         $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  169.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  170.                     }
  171.                     if ('europa' == $type) {
  172.                         $cantDestinosE count($europa);
  173.                         $totalDestinosE ceil($cantDestinosE $cantRegis);
  174.                         $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  175.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  176.                     }
  177.                     if ('africa' == $type) {
  178.                         $cantDestinosAF count($africa);
  179.                         $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  180.                         $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  181.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  182.                     }
  183.                     if ('asia' == $type) {
  184.                         $cantDestinosAS count($asia);
  185.                         $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  186.                         $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  187.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  188.                     }
  189.                     if ('ciudades-mundialistas' == $type) {
  190.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/ciudades_mundialistas.html.twig'), ['agencyId' => $agencyId'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  191.                     }
  192.                 }
  193.             } else {
  194.                 foreach ($articulos as $articulo) {
  195.                     $description json_decode($articulo->getDescription(), true);
  196.                     if ($description && is_array($description)) {
  197.                         if (isset($description['type'])) {
  198.                             if ('general' == $description['type']) {
  199.                                 if ('tips' == $description['categoria']) {
  200.                                     $tipsArticles[] = $articulo;
  201.                                 }
  202.                                 if ('sostenibilidad' == $description['categoria']) {
  203.                                     $tipsArticles[] = $articulo;
  204.                                 }
  205.                                 if ('gastronomia' == $description['categoria']) {
  206.                                     $gastronomiaArticles[] = $articulo;
  207.                                 }
  208.                                 if ('experiencias' == $description['categoria']) {
  209.                                     $experienciasArticles[] = $articulo;
  210.                                 }
  211.                             } else {
  212.                                 $actualArticles[] = $articulo;
  213.                             }
  214.                         } else {
  215.                             $actualArticles[] = $articulo;
  216.                         }
  217.                     }
  218.                 }
  219.                 /* Redireccion articulos contenido general, revista e información */
  220.                 if ('contenidos' == $type) {
  221.                     $cantGeneral count($tipsArticles);
  222.                     $totalGeneral ceil($cantGeneral $cantRegis);
  223.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  224.                     return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/division_contenidos.html.twig'), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  225.                 }
  226.                 if ('sostenibilidad' == $type) {
  227.                     $cantGeneral count($tipsArticles);
  228.                     $totalGeneral ceil($cantGeneral $cantRegis);
  229.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  230.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  231.                 }
  232.                 if ('tips' == $type) {
  233.                     $cantGeneral count($tipsArticles);
  234.                     $totalGeneral ceil($cantGeneral $cantRegis);
  235.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  236.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  237.                 }
  238.                 if ('gastronomia' == $type) {
  239.                     $cantRevista count($gastronomiaArticles);
  240.                     $totalRevista ceil($cantRevista $cantRegis);
  241.                     $pagination $paginator->paginate($gastronomiaArticles$fullRequest->query->get('page'$page), $cantRegis);
  242.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  243.                 }
  244.                 if ('experiencias' == $type) {
  245.                     $cantInformacion count($experienciasArticles);
  246.                     $totalInformacion ceil($cantInformacion $cantRegis);
  247.                     $pagination $paginator->paginate($experienciasArticles$fullRequest->query->get('page'$page), $cantRegis);
  248.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  249.                 }
  250.             }
  251.         } else {
  252.             $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.publicationenddate DESC');
  253.             $query $query->setParameter('agency'$agency);
  254.             $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.publicationenddate DESC');
  255.             $queryIn $queryIn->setParameter('agency'$agency);
  256.             if (isset($routeParams['content'])) {
  257.                 $path '/Blog/Default/index_destinos.html.twig';
  258.             } else {
  259.                 $path '/Blog/Default/index_contenidos.html.twig';
  260.             }
  261.             $urlReturn '@AviaturTwig/'.$agencyFolder.$path;
  262.             $colombia = [];
  263.             $america = [];
  264.             $oceania = [];
  265.             $europa = [];
  266.             $africa = [];
  267.             $asia = [];
  268.             $tipsArticles = [];
  269.             $gastronomiaArticles = [];
  270.             $experienciasArticles = [];
  271.             $actualArticles = [];
  272.             $cantRegis 9;
  273.             if ('activo' == $active) {
  274.                 $articulos $query->getResult();
  275.             }
  276.             if (isset($routeParams['content'])) {
  277.                 if ('general' == $type) {
  278.                     foreach ($articulos as $articulo) {
  279.                         $description json_decode($articulo->getDescription(), true);
  280.                         if ($description && is_array($description)) {
  281.                             if ('destinos-blog' == $description['type']) {
  282.                                 $actualArticles[] = $articulo;
  283.                             }
  284.                         }
  285.                     }
  286.                     if (empty($actualArticles)) {
  287.                         return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  288.                     }
  289.                     $cantDestinos count($actualArticles);
  290.                     $totalDestinos ceil($cantDestinos $cantRegis);
  291.                     $pagination $paginator->paginate($actualArticles$fullRequest->query->get('page'$page), $cantRegis);
  292.                     
  293.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinos'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  294.                 } else {
  295.                     foreach ($articulos as $articulo) {
  296.                         $description json_decode($articulo->getDescription(), true);
  297.                         if ($description && is_array($description)) {
  298.                             if ('destinos-blog' == $description['type'] && 'colombia' == $description['type2']) {
  299.                                 $colombia[] = $articulo;
  300.                             }
  301.                             if ('destinos-blog' == $description['type'] && 'america' == $description['type2']) {
  302.                                 $america[] = $articulo;
  303.                             }
  304.                             if ('destinos-blog' == $description['type'] && 'oceania' == $description['type2']) {
  305.                                 $oceania[] = $articulo;
  306.                             }
  307.                             if ('destinos-blog' == $description['type'] && 'europa' == $description['type2']) {
  308.                                 $europa[] = $articulo;
  309.                             }
  310.                             if ('destinos-blog' == $description['type'] && 'africa' == $description['type2']) {
  311.                                 $africa[] = $articulo;
  312.                             }
  313.                             if ('destinos-blog' == $description['type'] && 'asia' == $description['type2']) {
  314.                                 $asia[] = $articulo;
  315.                             }
  316.                         }
  317.                     }
  318.                     if (empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
  319.                         return $this->redirect($errorHandler->errorRedirectNoEmail('/''''No existen contenidos para esta agencia.'));
  320.                     }
  321.                     /* Redireccion articulos destinos y aerolineas */
  322.                     if ('colombia' == $type) {
  323.                         $cantDestinosC count($colombia);
  324.                         $totalDestinosC ceil($cantDestinosC $cantRegis);
  325.                         $pagination $paginator->paginate($colombia$fullRequest->query->get('page'$page), $cantRegis);
  326.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosC'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  327.                     }
  328.                     if ('america' == $type) {
  329.                         $cantDestinosA count($america);
  330.                         $totalDestinosA ceil($cantDestinosA $cantRegis);
  331.                         $pagination $paginator->paginate($america$fullRequest->query->get('page'$page), $cantRegis);
  332.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosA'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  333.                     }
  334.                     if ('oceania' == $type) {
  335.                         $cantDestinosO count($oceania);
  336.                         $totalDestinosO ceil($cantDestinosO $cantRegis);
  337.                         $pagination $paginator->paginate($oceania$fullRequest->query->get('page'$page), $cantRegis);
  338.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosO'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  339.                     }
  340.                     if ('europa' == $type) {
  341.                         $cantDestinosE count($europa);
  342.                         $totalDestinosE ceil($cantDestinosE $cantRegis);
  343.                         $pagination $paginator->paginate($europa$fullRequest->query->get('page'$page), $cantRegis);
  344.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosE'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  345.                     }
  346.                     if ('africa' == $type) {
  347.                         $cantDestinosAF count($africa);
  348.                         $totalDestinosAF ceil($cantDestinosAF $cantRegis);
  349.                         $pagination $paginator->paginate($africa$fullRequest->query->get('page'$page), $cantRegis);
  350.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAF'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  351.                     }
  352.                     if ('asia' == $type) {
  353.                         $cantDestinosAS count($asia);
  354.                         $totalDestinosAS ceil($cantDestinosAS $cantRegis);
  355.                         $pagination $paginator->paginate($asia$fullRequest->query->get('page'$page), $cantRegis);
  356.                         return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalDestinosAS'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  357.                     }
  358.                     if ('ciudades-mundialistas' == $type) {
  359.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/ciudades_mundialistas.html.twig'), ['agencyId' => $agencyId'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  360.                     }
  361.                 }
  362.             } else {
  363.                 foreach ($articulos as $articulo) {
  364.                     $description json_decode($articulo->getDescription(), true);
  365.                     if ($description && is_array($description)) {
  366.                         if (isset($description['type'])) {
  367.                             if ('general' == $description['type']) {
  368.                                 if ('tips' == $description['categoria']) {
  369.                                     $tipsArticles[] = $articulo;
  370.                                 }
  371.                                 if ('sostenibilidad' == $description['categoria']) {
  372.                                     $tipsArticles[] = $articulo;
  373.                                 }
  374.                                 if ('gastronomia' == $description['categoria']) {
  375.                                     $gastronomiaArticles[] = $articulo;
  376.                                 }
  377.                                 if ('experiencias' == $description['categoria']) {
  378.                                     $experienciasArticles[] = $articulo;
  379.                                 }
  380.                             } else {
  381.                                 $actualArticles[] = $articulo;
  382.                             }
  383.                         } else {
  384.                             $actualArticles[] = $articulo;
  385.                         }
  386.                     }
  387.                 }
  388.                 /* Redireccion articulos contenido general, revista e información */
  389.                 if ('contenidos' == $type) {
  390.                     $cantGeneral count($tipsArticles);
  391.                     $totalGeneral ceil($cantGeneral $cantRegis);
  392.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  393.                     return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/division_contenidos.html.twig'), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  394.                 }
  395.                 if ('tips' == $type) {
  396.                     $cantGeneral count($tipsArticles);
  397.                     $totalGeneral ceil($cantGeneral $cantRegis);
  398.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  399.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  400.                 }
  401.                 if ('sostenibilidad' == $type) {
  402.                     $cantGeneral count($tipsArticles);
  403.                     $totalGeneral ceil($cantGeneral $cantRegis);
  404.                     $pagination $paginator->paginate($tipsArticles$fullRequest->query->get('page'$page), $cantRegis);
  405.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalGeneral'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  406.                 }
  407.                 if ('gastronomia' == $type) {
  408.                     $cantRevista count($gastronomiaArticles);
  409.                     $totalRevista ceil($cantRevista $cantRegis);
  410.                     $pagination $paginator->paginate($gastronomiaArticles$fullRequest->query->get('page'$page), $cantRegis);
  411.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalRevista'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  412.                 }
  413.                 if ('experiencias' == $type) {
  414.                     $cantInformacion count($experienciasArticles);
  415.                     $totalInformacion ceil($cantInformacion $cantRegis);
  416.                     $pagination $paginator->paginate($experienciasArticles$fullRequest->query->get('page'$page), $cantRegis);
  417.                     return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId'articulo' => $pagination'page' => $page'active' => $active'totalRegi' => $totalInformacion'ajaxUrl' => $requestUrl'typeArticle' => $type'params' => $routeParams'blog_form' => $blogForm->createView()]);
  418.                 }
  419.             }
  420.         }
  421.     }
  422.     public function extractDescriptionAction($text)
  423.     {
  424.         $article $text;
  425.         $separator1 '<p style="text-align: justify;">';
  426.         $separator2 '</p>';
  427.         $articleText $article->getText();
  428.         $pos strrpos($articleText$separator1);
  429.         if (false !== $pos) {
  430.             $position strpos($articleText$separator1);
  431.             $pText substr($articleText$position strlen($separator1));
  432.             $posText strrpos($pText$separator2);
  433.             if (false !== $posText) {
  434.                 $newPosition strpos($pText$separator2);
  435.                 $description substr($pText0$newPosition);
  436.                 $descriptionArticle preg_replace('/<.+?>/'''$description);
  437.                 $descriptionArticle html_entity_decode($descriptionArticleENT_QUOTES'UTF-8');
  438.                 return new Response($descriptionArticle);
  439.             }
  440.         }
  441.         return new Response('vacio');
  442.     }
  443.     public function nameCityBlogAction($iata)
  444.     {
  445.         $em $this->getDoctrine()->getManager();
  446.         $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $iata]);
  447.         if (!empty($dest)) {
  448.             $cityName $dest->getCity();
  449.             $cities = ['Paris''Mexico''Cancun''Panama City''Puerto Asis''Amsterdam''Iguazu''Zurich''Moscow''Dublin''Kazan''Monte Carlo''Malaga''Rio de Janeiro''Cordoba''Dubai''Seul'];
  450.             $citiesCorrection = ['París''Ciudad de México''Cancún''Panamá''Puerto Asís''Ámsterdam''Iguazú''Zúrich''Moscú''Dublín''Kazán''Mónaco''Málaga''Río de Janeiro''Córdoba''Dubái''Seúl'];
  451.             $city str_replace($cities$citiesCorrection$cityName);
  452.         } else {
  453.             $city 'vacio';
  454.         }
  455.         return new Response($city);
  456.     }
  457.     /*
  458.      * Visualiza el articulo seleccionado
  459.      */
  460.     public function viewAction(SessionInterface $sessionTwigFolder $twigFolder$id)
  461.     {
  462.         $em $this->getDoctrine()->getManager();
  463.         $articulo $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
  464.         
  465.         // $validateExplore = ((null === $em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]) ? 0 : count($em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]))) > 0) ? true : false; 
  466.         $validateExplore=false;
  467.         $aviaturSearchExploreEntity=$em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore''value' => 1]);
  468.         if (! is_null($aviaturSearchExploreEntity)) {
  469.             $aviaturSearchExploreEntity $em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore''value' => 1]);
  470.             if (is_countable($aviaturSearchExploreEntity) ) {
  471.                 if (count($aviaturSearchExploreEntity) > 0) {
  472.                     $validateExplore=true;
  473.                 }
  474.             }
  475.         }
  476.         if (isset($articulo[0]) && (null != $articulo[0])) {
  477.             $agencyFolder $twigFolder->twigFlux();
  478.             $description json_decode($articulo[0]->getDescription(), true);
  479.             $blog = new Newsletter();
  480.             $blogForm $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
  481.             // determine content type based on eventual json encoded description
  482.             if ($description && is_array($description)) {
  483.                 $pos strpos($agencyFolder'aviatur');
  484.                 if (false !== $pos) {
  485.                     if ('destinos' == $description['type'] || 'destinos-blog' == $description['type']) {
  486.                         $cookieArray = [];
  487.                         foreach ($description as $key => $value) {
  488.                             $cookieArray[$key] = $value;
  489.                         }
  490.                         if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['origin1'])) {
  491.                             $ori $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
  492.                             $cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
  493.                         } else {
  494.                             $cookieArray['originLabel1'] = '';
  495.                         }
  496.                         if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/'$cookieArray['destination1'])) {
  497.                             $dest $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
  498.                             $cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
  499.                             $cookieArray['destinationIata'] = $dest->getIata();
  500.                         } else {
  501.                             $cookieArray['destinationLabel1'] = '';
  502.                             $cookieArray['destinationIata'] = '';
  503.                         }
  504.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray'validateExplore' => $validateExplore'blog_form' => $blogForm->createView()]);
  505.                     } else {
  506.                         // eg: {"categoria":"tips|gastronomia|experiencias"}
  507.                         $cookieArray = [];
  508.                         foreach ($description as $key => $value) {
  509.                             $cookieArray[$key] = $value;
  510.                         }
  511.                         return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view_contenidos.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray'validateExplore' => $validateExplore'blog_form' => $blogForm->createView()]);
  512.                     }
  513.                 }
  514.             }
  515.             return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view.html.twig'), ['articulo' => $articulo[0]]);
  516.         } else {
  517.             throw $this->createNotFoundException('Contenido no encontrado');
  518.         }
  519.     }
  520.     public function subscriptionAction(Request $requestSessionInterface $session)
  521.     {
  522.         $resgisterBlog = new Newsletter();
  523.         $em $this->getDoctrine()->getManager();
  524.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($session->get('agencyId'));
  525.         $form $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $resgisterBlog);
  526.         $form->handleRequest($request);
  527.         if ($form->isSubmitted()) {
  528.             $post $request->request->get('blog_form');
  529.             if ($form->isValid()) {
  530.                 if ($request->isXmlHttpRequest()) {
  531.                     $resgisterBlog->setFirstname(ucwords(mb_strtolower($post['firstname'])));
  532.                     $resgisterBlog->setLastname(ucwords(mb_strtolower($post['lastname'])));
  533.                     $resgisterBlog->setEmail($post['email']);
  534.                     $typeBlog '{"newsletter":"no","blog":"si"}';
  535.                     $resgisterBlog->setType($typeBlog);
  536.                     $resgisterBlog->setAgency($agency);
  537.                     $resgisterBlog->setPublicationDate(new \DateTime());
  538.                     $em->persist($resgisterBlog);
  539.                     $em->flush();
  540.                     $response = new Response();
  541.                     $output = ['success' => true];
  542.                     $response->headers->set('Content-Type''application/json');
  543.                     $response->setContent(json_encode($output));
  544.                 } else {
  545.                     $response = new Response();
  546.                     $output = ['error' => true];
  547.                     $response->headers->set('Content-Type''application/json');
  548.                     $response->setContent(json_encode($output));
  549.                     return $response;
  550.                 }
  551.             } else {
  552.                 $emailRegister $em->getRepository(\Aviatur\FormBundle\Entity\Newsletter::class)->findByEmail($post['email']);
  553.                 if ($emailRegister) {
  554.                     $type json_decode($emailRegister[0]->getType(), true);
  555.                     if ('no' == $type['blog']) {
  556.                         $typeBlog '{"newsletter":"si","blog":"si"}';
  557.                         $emailRegister[0]->setType($typeBlog);
  558.                         $em->persist($emailRegister[0]);
  559.                         $em->flush();
  560.                         $response = new Response();
  561.                         $output = ['success' => true];
  562.                         $response->headers->set('Content-Type''application/json');
  563.                         $response->setContent(json_encode($output));
  564.                         return $response;
  565.                     } else {
  566.                         $response = new Response();
  567.                         $output = ['email' => true];
  568.                         $response->headers->set('Content-Type''application/json');
  569.                         $response->setContent(json_encode($output));
  570.                         return $response;
  571.                     }
  572.                 } else {
  573.                     $response = new Response();
  574.                     $output = ['error' => true];
  575.                     $response->headers->set('Content-Type''application/json');
  576.                     $response->setContent(json_encode($output));
  577.                     return $response;
  578.                 }
  579.             }
  580.         } else {
  581.             $response = new Response();
  582.             $output = ['error' => true];
  583.             $response->headers->set('Content-Type''application/json');
  584.             $response->setContent(json_encode($output));
  585.             return $response;
  586.         }
  587.     }
  588. }