<?php
namespace Aviatur\ContentBundle\Controller;
use Aviatur\ContentBundle\Entity\Content;
use Aviatur\ContentBundle\Entity\HistoricalContent;
use Aviatur\GeneralBundle\Entity\Weather;
use Aviatur\GeneralBundle\Services\AviaturErrorHandler;
use Aviatur\TwigBundle\Services\TwigFolder;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class ContentController extends AbstractController
{
/*
* Pantalla inicial, muestra los articulos
*/
public function indexAction(Request $request, SessionInterface $session, AviaturErrorHandler $errorHandler, TwigFolder $twigFolder, AuthorizationCheckerInterface $authorizationChecker, PaginatorInterface $paginator, $page, $active, $search = null)
{
$em = $this->getDoctrine()->getManager();
$fullRequest = $request;
$routeParams = $fullRequest->attributes->get('_route_params');
$requestUrl = $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
$agencyId = $session->get('agencyId');
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
$agencyFolder = $twigFolder->twigFlux();
if ($request->isXmlHttpRequest()) {
//BUSCADOR
$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');
$query = $query->setParameter('agency', $agency);
$query = $query->setParameter('id', $search);
$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');
$queryIn = $queryIn->setParameter('agency', $agency);
$queryIn = $queryIn->setParameter('id', $search);
if (isset($routeParams['content'])) {
$path = '/Content/Content/AjaxIndex_promo.html.twig';
} else {
$path = '/Content/Content/AjaxIndex.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
if ('activo' == $active) {
$articulos = $query->getResult();
} elseif ('inactivo' == $active) {
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')) {
$articulos = $queryIn->getResult();
} else {
return $twigFolder->pathWithLocale('aviatur_general_homepage');
}
}
$actualArticles = [];
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
$actualArticles[] = $articulo;
$type = $description['type2'];
}
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if (null == $description || !is_array($description)) {
$actualArticles[] = $articulo;
} else {
$actualArticles[] = $articulo;
$type = $description['type'];
}
}
}
if (empty($actualArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cantdatos = count($actualArticles);
$cantRegis = 10;
$totalRegi = ceil($cantdatos / $cantRegis);
$pagination = $paginator->paginate($actualArticles, $fullRequest->query->get('page', $page), $cantRegis);
if (isset($type)) {
//return $this->render($errorHandler->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type]);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type]);
} else {
//return $this->render($errorHandler->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
}
} else {
//INDEX
$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');
$query = $query->setParameter('agency', $agency);
$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');
$queryIn = $queryIn->setParameter('agency', $agency);
if (isset($routeParams['content'])) {
$path = '/Content/Content/index_promo.html.twig';
} else {
$path = '/Content/Content/index.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
if ('activo' == $active) {
$articulos = $query->getResult();
} elseif ('inactivo' == $active) {
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')) {
$articulos = $queryIn->getResult();
} else {
return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
}
}
$pos = strpos($agencyFolder, 'aviatur');
if (false !== $pos) {
if (isset($routeParams['content'])) {
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/index_tickets.html.twig'), ['agencyId' => $agencyId]);
} else {
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/index_content.html.twig'), ['agencyId' => $agencyId]);
}
} else {
$actualArticles = [];
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
$actualArticles[] = $articulo;
$type = $description['type2'];
}
}
} else {
foreach ($articulos as $articulo) {
$descrip = $articulo->getDescription();
$description = json_decode($descrip, true);
if(isset($description['type'])){
$type = $description['type'];
}else{
$type = '';
}
$actualArticles[] = $articulo;
}
}
if (empty($actualArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cantdatos = count($actualArticles);
$cantRegis = 10;
$totalRegi = ceil($cantdatos / $cantRegis);
$pagination = $paginator->paginate($actualArticles, $fullRequest->query->get('page', $page), $cantRegis);
// $description = json_decode($actualArticles->getDescription(), true);
return $this->render($twigFolder->twigExists($urlReturn), ['typeArticle' => $type,'agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
}
}
}
public function listAction(Request $request, SessionInterface $session, AviaturErrorHandler $errorHandler, TwigFolder $twigFolder, AuthorizationCheckerInterface $authorizationChecker, PaginatorInterface $paginator, $page, $active, $type)
{
$em = $this->getDoctrine()->getManager();
$fullRequest = $request;
$routeParams = $fullRequest->attributes->get('_route_params');
$requestUrl = $this->generateUrl($fullRequest->attributes->get('_route'), $routeParams);
$agencyId = $session->get('agencyId');
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
$agencyFolder = $twigFolder->twigFlux();
if ($request->isXmlHttpRequest()) {
//CARGAR MÁS
$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');
$query = $query->setParameter('agency', $agency);
$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');
$queryIn = $queryIn->setParameter('agency', $agency);
if (isset($routeParams['content'])) {
$path = '/Content/Content/AjaxIndex_promo.html.twig';
} else {
$path = '/Content/Content/AjaxIndex.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
$aerolineasArticles = [];
$colombia = [];
$america = [];
$oceania = [];
$europa = [];
$africa = [];
$asia = [];
$generalArticles = [];
$revistaArticles = [];
$informacionArticles = [];
$actualArticles = [];
$destinosBlog = [];
$cantRegis = 9;
if ('activo' == $active) {
$articulos = $query->getResult();
} elseif ('inactivo' == $active) {
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')) {
$articulos = $queryIn->getResult();
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('aerolineas' == $description['type']) {
$aerolineasArticles[] = $articulo;
}
if ('destinos' == $description['type']) {
if ('colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('america' == $description['type2']) {
$america[] = $articulo;
}
if ('oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('asia' == $description['type2']) {
$asia[] = $articulo;
}
}
if ('destinos-blog' == $description['type']) {
$destinosBlog[] = $articulo;
}
}
}
if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cookieArray = [];
/* Redireccion articulos destinos y aerolineas */
if ('aerolinea' == $type) {
$cantAerolineas = count($aerolineasArticles);
$totalAero = ceil($cantAerolineas / $cantRegis);
$pagination = $paginator->paginate($aerolineasArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalAero, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SMR';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MIA';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SYD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MAD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'CAI';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => 'MIA']);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'TYO';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('blog' == $type) {
$cantDestinosBL = count($destinosBlog);
$totalDestinosBL = ceil($cantDestinosBL / $cantRegis);
$pagination = $paginator->paginate($destinosBlog, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosBL, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
$generalArticles[] = $articulo;
}
if ('revista-horizontes' == $description['type']) {
$revistaArticles[] = $articulo;
}
if ('informacion-aviatur' == $description['type']) {
$informacionArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
/* Redireccion articulos contenido general, revista e información */
if ('general' == $type) {
$cantGeneral = count($generalArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($generalArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('revista-horizontes' == $type) {
$cantRevista = count($revistaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($revistaArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRevista, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('informacion-aviatur' == $type) {
$cantInformacion = count($informacionArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($informacionArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalInformacion, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
}
} else {
return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
}
}
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('aerolineas' == $description['type']) {
$aerolineasArticles[] = $articulo;
}
if ('destinos' == $description['type']) {
if ('colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('america' == $description['type2']) {
$america[] = $articulo;
}
if ('oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('asia' == $description['type2']) {
$asia[] = $articulo;
}
}
if ('destinos-blog' == $description['type']) {
$destinosBlog[] = $articulo;
}
}
}
if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cookieArray = [];
/* Redireccion articulos destinos y aerolineas */
if ('aerolinea' == $type) {
$cantAerolineas = count($aerolineasArticles);
$totalAero = ceil($cantAerolineas / $cantRegis);
$pagination = $paginator->paginate($aerolineasArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalAero, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SMR';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MIA';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SYD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MAD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'CAI';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'TYO';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('blog' == $type) {
$cantDestinosBL = count($destinosBlog);
$totalDestinosBL = ceil($cantDestinosBL / $cantRegis);
$pagination = $paginator->paginate($destinosBlog, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosBL, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if (null == $description || is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
$generalArticles[] = $articulo;
}
if ('revista-horizontes' == $description['type']) {
$revistaArticles[] = $articulo;
}
if ('informacion-aviatur' == $description['type']) {
$informacionArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
if (empty($generalArticles) && empty($revistaArticles) && empty($informacionArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
/* Redireccion articulos contenido general, revista e información */
if (!empty($generalArticles) && !empty($revistaArticles) && !empty($informacionArticles)) {
if ('general' == $type) {
$cantGeneral = count($generalArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($generalArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('revista-horizontes' == $type) {
$cantRevista = count($revistaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($revistaArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRevista, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('informacion-aviatur' == $type) {
$cantInformacion = count($informacionArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($informacionArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalInformacion, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
$cantdatos = count($actualArticles);
$cantRegis = 10;
$totalRegi = ceil($cantdatos / $cantRegis);
$pagination = $paginator->paginate($actualArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
}
}
} else {
//INDEX
$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');
$query = $query->setParameter('agency', $agency);
$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');
$queryIn = $queryIn->setParameter('agency', $agency);
if (isset($routeParams['content'])) {
$path = '/Content/Content/index_promo.html.twig';
} else {
$path = '/Content/Content/index.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
$aerolineasArticles = [];
$colombia = [];
$america = [];
$oceania = [];
$europa = [];
$africa = [];
$asia = [];
$generalArticles = [];
$revistaArticles = [];
$informacionArticles = [];
$actualArticles = [];
$destinosBlog = [];
$cantRegis = 9;
if ('activo' == $active) {
$articulos = $query->getResult();
} elseif ('inactivo' == $active) {
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')) {
$articulos = $queryIn->getResult();
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('aerolineas' == $description['type']) {
$aerolineasArticles[] = $articulo;
}
if ('destinos' == $description['type']) {
if ('colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('america' == $description['type2']) {
$america[] = $articulo;
}
if ('oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('asia' == $description['type2']) {
$asia[] = $articulo;
}
}
if ('destinos-blog' == $description['type']) {
$destinosBlog[] = $articulo;
}
}
}
if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cookieArray = [];
/* Redireccion articulos destinos y aerolineas */
if ('aerolinea' == $type) {
$cantAerolineas = count($aerolineasArticles);
$totalAero = ceil($cantAerolineas / $cantRegis);
$pagination = $paginator->paginate($aerolineasArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalAero, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SMR';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MIA';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SYD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MAD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'CAI';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => 'MIA']);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'TYO';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('blog' == $type) {
$cantDestinosBL = count($destinosBlog);
$totalDestinosBL = ceil($cantDestinosBL / $cantRegis);
$pagination = $paginator->paginate($destinosBlog, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosBL, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
$generalArticles[] = $articulo;
}
if ('revista-horizontes' == $description['type']) {
$revistaArticles[] = $articulo;
}
if ('informacion-aviatur' == $description['type']) {
$informacionArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
/* Redireccion articulos contenido general, revista e información */
if ('general' == $type) {
$cantGeneral = count($generalArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($generalArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('revista-horizontes' == $type) {
$cantRevista = count($revistaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($revistaArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRevista, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('informacion-aviatur' == $type) {
$cantInformacion = count($informacionArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($informacionArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalInformacion, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
}
} else {
return $this->redirect($twigFolder->pathWithLocale('aviatur_general_homepage'));
}
}
if (isset($routeParams['content'])) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('aerolineas' == $description['type']) {
$aerolineasArticles[] = $articulo;
}
if ('destinos' == $description['type']) {
if ('colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('america' == $description['type2']) {
$america[] = $articulo;
}
if ('oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('asia' == $description['type2']) {
$asia[] = $articulo;
}
}
if ('destinos-blog' == $description['type']) {
$destinosBlog[] = $articulo;
}
}
}
if (empty($aerolineasArticles) && empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cookieArray = [];
/* Redireccion articulos destinos y aerolineas */
if ('aerolinea' == $type) {
$cantAerolineas = count($aerolineasArticles);
$totalAero = ceil($cantAerolineas / $cantRegis);
$pagination = $paginator->paginate($aerolineasArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalAero, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SMR';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MIA';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'SYD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'MAD';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'CAI';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
$cookieArray['origin1'] = '';
$cookieArray['destination1'] = 'TYO';
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
$cookieArray['date1'] = '';
$cookieArray['date2'] = '';
$cookieArray['adults'] = '';
$cookieArray['children'] = '';
$cookieArray['infants'] = '';
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'cookieLastSearch' => $cookieArray]);
}
if ('blog' == $type) {
$cantDestinosBL = count($destinosBlog);
$totalDestinosBL = ceil($cantDestinosBL / $cantRegis);
$pagination = $paginator->paginate($destinosBlog, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosBL, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if (null == $description || is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
$generalArticles[] = $articulo;
}
if ('revista-horizontes' == $description['type']) {
$revistaArticles[] = $articulo;
}
if ('informacion-aviatur' == $description['type']) {
$informacionArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
if (empty($generalArticles) && empty($revistaArticles) && empty($informacionArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
/* Redireccion articulos contenido general, revista e información */
if (!empty($generalArticles) && !empty($revistaArticles) && !empty($informacionArticles)) {
if ('general' == $type) {
$cantGeneral = count($generalArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($generalArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('revista-horizontes' == $type) {
$cantRevista = count($revistaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($revistaArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRevista, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
if ('informacion-aviatur' == $type) {
$cantInformacion = count($informacionArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($informacionArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalInformacion, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams]);
}
} else {
$cantdatos = count($actualArticles);
$cantRegis = 10;
$totalRegi = ceil($cantdatos / $cantRegis);
$pagination = $paginator->paginate($actualArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl]);
}
}
}
}
public function searchAction(Request $request, SessionInterface $session)
{
$em = $this->getDoctrine()->getManager();
if ($request->isXmlHttpRequest()) {
$agencyId = $session->get('agencyId');
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
$term = $request->query->get('term');
$url = $request->query->get('url');
$pos = strpos($url, 'tiquetes-baratos-a');
if (false !== $pos) {
$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)');
$queryIn = $queryIn->setParameter('title', '%'.$term.'%');
$queryIn = $queryIn->setParameter('description', '%\"destinos\"%');
$queryIn = $queryIn->setParameter('agency', $agency);
$articulos = $queryIn->getResult();
} else {
$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)');
$queryIn = $queryIn->setParameter('title', '%'.$term.'%');
$queryIn = $queryIn->setParameter('description', '%\"destinos\"%');
$queryIn = $queryIn->setParameter('description1', '%\"autos\"%');
$queryIn = $queryIn->setParameter('agency', $agency);
$articulos = $queryIn->getResult();
}
$type = '';
$json_template = '<value>:<label>*';
$json = '';
if ($articulos) {
foreach ($articulos as $contenidos) {
$description = json_decode($contenidos['description'], true);
if (null == $description || is_array($description)) {
if (isset($description['type'])) {
$type = $description['type'];
if ('destinos' == $type) {
$type = $description['type2'];
}
} else {
$type = 'general';
}
}
$json .= str_replace(['<value>', '<label>'], [$contenidos['id'].'|'.$type.'|'.$contenidos['url'], $contenidos['title']], $json_template);
}
$json = \rtrim($json, '-');
} else {
$json = 'NN:No hay Resultados';
}
$response = \rtrim($json, '*');
return new Response($response);
} else {
return new Response('Acceso Restringido');
}
}
/*
* Muestra la vista y ejecuta la creacion de un nuevo articulo
*/
public function newAction(Request $request, SessionInterface $session, TokenStorageInterface $tokenStorage, TwigFolder $twigFolder, ValidatorInterface $validator)
{
$article = new Content();
$em = $this->getDoctrine()->getManager();
$fullRequest = $request;
$routeParams = $fullRequest->get('_route_params');
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($session->get('agencyId'));
$agencyId = $session->get('agencyId');
$form = $this->createForm(\Aviatur\ContentBundle\Form\ContentType::class, $article);
$user = $tokenStorage->getToken()->getUser();
$caracteres = ['\\', '¨', 'º', '~', '#', '@', '|', '!', '"', '·', '$', '%', '&', '/', '(', ')', '?', "'", '¡', '¿', '[', '^', '`', ']', '+', '}', '{', '¨', '´', '>', '< ', ';', ',', ':', '.', ' '];
$form->handleRequest($request);
if ($form->isSubmitted()) {
$post = $fullRequest->request->get('content_form');
if ($form->isValid()) {
$newUrl = str_replace($caracteres, '-', mb_strtolower($post['url']));
$article->setUser($user);
$article->setAgency($agency);
$article->setTitle($post['title']);
$article->setDescription($post['description']);
$article->setText($fullRequest->request->get('notificacion'));
$article->setUrl($newUrl);
$article->setPublicationStartDate(new \DateTime());
$article->setPublicationEndDate(new \DateTime());
$article->setCreationDate(new \DateTime());
$article->setkeywords($post['keywords']);
$article->setIsactive(1);
$em = $this->getDoctrine()->getManager();
$em->persist($article);
$postAll = $fullRequest->request;
$info = json_encode($postAll->all());
$historicalContent = new HistoricalContent();
$historicalContent->setContent($article);
$historicalContent->setCustomer($user);
$historicalContent->setInfo($info);
$historicalContent->setDate(new \DateTime());
$em->persist($historicalContent);
$em->flush();
if (isset($routeParams['content'])) {
return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
} else {
return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
}
} else {
$errors = $validator->validate($article);
$datos = ['agencyId' => $agencyId, 'form' => $form->createView(), 'errors' => $errors];
$agencyFolder = $twigFolder->twigFlux();
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/create.html.twig'), $datos);
}
} else {
$agencyFolder = $twigFolder->twigFlux();
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/create.html.twig'), ['agencyId' => $agencyId, 'form' => $form->createView()]);
}
}
/*
* Recibe parametro (id = identificador del articulo) para mostrar el articulo deseado
*/
public function editAction(TwigFolder $twigFolder, $id)
{
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
$agencyFolder = $twigFolder->twigFlux();
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/edit.html.twig'), ['articulo' => $articulo, 'id' => $id, 'url' => 'edition']);
}
/*
* Controlador que recibe parametro (id = identificador del articulo) para ejecutar el update del articulo
*/
public function editionAction(Request $request, TokenStorageInterface $tokenStorage, $id)
{
$routeParams = $request->get('_route_params');
$post = $request->request;
$caracteres = ['\\', '¨', 'º', '_', '~', '#', '@', '|', '!', '"', '·', '$', '%', '&', '/', '(', ')', '?', "'", '¡', '¿', '[', '^', '`', ']', '+', '}', '{', '¨', '´', '>', '< ', ';', ',', ':', '.', ' '];
$newUrl = str_replace($caracteres, '-', mb_strtolower($post->get('url')));
$user = $tokenStorage->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
$articulo->setText($post->get('notificacion'));
$articulo->setTitle($post->get('title'));
$articulo->setUrl($newUrl);
$articulo->setDescription($post->get('description'));
$articulo->setkeywords($post->get('keywords'));
$articulo->setPublicationEndDate(new \DateTime());
$em->persist($articulo);
$info = json_encode($post->all());
$historicalContent = new HistoricalContent();
$historicalContent->setContent($articulo);
$historicalContent->setCustomer($user);
$historicalContent->setInfo($info);
$historicalContent->setDate(new \DateTime());
$em->persist($historicalContent);
$em->flush();
if (isset($routeParams['content'])) {
return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
} else {
return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
}
}
/*
* Muestra el articulo al que se desea cambiar el estado
*/
public function deleteAction(TwigFolder $twigFolder, $id)
{
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
$agencyFolder = $twigFolder->twigFlux();
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/edit.html.twig'), ['articulo' => $articulo, 'id' => $id, 'url' => 'deleting']);
}
/*
* Recibe el parametro del articulo y cambia el estado para activar e inactivar
*/
public function deletingAction(Request $request, TokenStorageInterface $tokenStorage, $id)
{
$routeParams = $request->get('_route_params');
$post = $request->request;
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->find($id);
$isActive = $articulo->getIsactive();
$user = $tokenStorage->getToken()->getUser();
if (0 == $isActive):
$isActive = 1; else:
$isActive = 0;
endif;
$articulo->setIsactive($isActive);
$articulo->setPublicationEndDate(new \DateTime());
$em->persist($articulo);
$info = json_encode($post->all());
$historicalContent = new HistoricalContent();
$historicalContent->setContent($articulo);
$historicalContent->setCustomer($user);
$historicalContent->setInfo($info);
$historicalContent->setIsactive($isActive);
$historicalContent->setDate(new \DateTime());
$em->persist($historicalContent);
$em->flush();
if (isset($routeParams['content'])) {
return $this->redirect($this->generateUrl('aviatur_content_airline_filtered_pagination', ['content' => $routeParams['content']]));
} else {
return $this->redirect($this->generateUrl('aviatur_content_filtered_pagination'));
}
}
/*
* Visualiza el articulo seleccionado
*/
public function viewAction(Request $request, SessionInterface $session, TwigFolder $twigFolder, $id)
{
$em = $this->getDoctrine()->getManager();
$agencyId = $session->get('agencyId');
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($agencyId);
$routeParams = $request->get('_route_params');
if (isset($routeParams['content']) && 'destinos' == $routeParams['content']) {
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyTypeNull($session->get('agencyId'), $id, '%\"destinos\"%');
} else {
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
}
if (isset($articulo[0]) && (null != $articulo[0])) {
$agencyFolder = $twigFolder->twigFlux();
$description = json_decode($articulo[0]->getDescription(), true);
$url = $articulo[0]->getURL();
// determine content type based on eventual json encoded description
if ($description && is_array($description)) {
$pos = strpos($agencyFolder, 'aviatur');
if (false !== $pos) {
if ('aerolineas' == $description['type'] || 'destinos' == $description['type']) {
// 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":""}
$cookieArray = [];
foreach ($description as $key => $value) {
$cookieArray[$key] = $value;
}
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
if (null == $ori) {
$airport = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneBy(['iata' => $cookieArray['origin1']]);
if (null != $airport) {
$cookieArray['originLabel1'] = $airport->getName().', '.$airport->getCity().', '.$airport->getCountry().' ('.$airport->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
} else {
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
}
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
if (null == $dest || empty($dest)) {
$airport = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneBy(['iata' => $cookieArray['destination1']]);
if (null != $airport) {
$cookieArray['destinationLabel1'] = $airport->getName().', '.$airport->getCity().', '.$airport->getCountry().' ('.$airport->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
} else {
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
}
} else {
$cookieArray['destinationLabel1'] = '';
}
$ticketsPromoList = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'vuelos-destinos', 'agency' => $agency]);
$ticketsPromosTitle = '';
$ticketsPromosSubtitle = '';
if ('aerolineas' == $description['type']) {
if ('avianca' == $url || 'vivaair' == $url || 'easyfly' == $url || 'satena' == $url || 'latam-airlines' == $url) {
$ticketsPromoListAirline = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'vuelos-airlines', 'agency' => $agency]);
if (null != $ticketsPromoListAirline) {
$ticketsPromosTitle = $ticketsPromoListAirline->getTitle();
$ticketsPromosSubtitle = $ticketsPromoListAirline->getSubtitle();
if ('avianca' == $url || 'vivaair' == $url || 'easyfly' == $url || 'satena' == $url || 'latam-airlines' == $url) {
$ticketsPromos = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['linkSwitch' => $url, 'homePromoList' => $ticketsPromoListAirline]);
} else {
$ticketsPromos = [];
}
} else {
$ticketsPromos = [];
}
$promoType = 'vuelos-airlines';
} else {
if (null != $ticketsPromoList) {
$ticketsPromos = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['content' => $url, 'homePromoList' => $ticketsPromoList], ['date' => 'DESC']);
} else {
$ticketsPromos = [];
}
$promoType = 'vuelos-destinos';
}
} else {
if (null != $ticketsPromoList) {
$ticketsPromos = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findBy(['content' => $url, 'homePromoList' => $ticketsPromoList], ['date' => 'DESC']);
} else {
$ticketsPromos = [];
}
$promoType = 'vuelos-destinos';
}
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]);
} else {
// eg: {"type":"nuevo|general|revista-horizontes|informacion-aviatur","column":"si|no","description":"texto"}
$cookieArray = [];
foreach ($description as $key => $value) {
$cookieArray[$key] = $value;
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray]);
}
} else {
$cookieArray = [];
foreach ($description as $key => $value) {
$cookieArray[$key] = $value;
}
if (isset($cookieArray['origin1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['origin1'])) {
$ori = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['origin1']]);
$cookieArray['originLabel1'] = $ori->getCity().', '.$ori->getCountry().' ('.$ori->getIata().')';
} else {
$cookieArray['originLabel1'] = '';
}
if (isset($cookieArray['destination1']) && preg_match('/^[A-Z]{3}$/', $cookieArray['destination1'])) {
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $cookieArray['destination1']]);
$cookieArray['destinationLabel1'] = $dest->getCity().', '.$dest->getCountry().' ('.$dest->getIata().')';
} else {
$cookieArray['destinationLabel1'] = '';
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray]);
}
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/view.html.twig'), ['articulo' => $articulo[0]]);
} else {
throw $this->createNotFoundException('Contenido no encontrado');
}
}
/*
* Visualiza el articulo seleccionado en ventana sola
*/
public function onlyAction(SessionInterface $session, TwigFolder $twigFolder, $id)
{
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
if (isset($articulo[0]) && (null != $articulo[0])) {
$agencyFolder = $twigFolder->twigFlux();
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Content/Content/only.html.twig'), ['articulo' => $articulo[0]]);
} else {
throw $this->createNotFoundException('Contenido no encontrado');
}
}
/*
* Trae URL de una imagen en el Twig para Open Graph SEO
*/
public function extractUrlAction($separator1 = null, $separator2 = null, $text, $type)
{
switch ($type) {
case 'content':
$titleImage = 'Aviatur';
$article = $text;
$articleText = $article->getText();
$pos = strrpos($articleText, (string) $separator1);
$posSlider = strrpos($articleText, "background-image: url('");
if (false !== $pos) {
$posTitle = strrpos($articleText, 'title="');
if (false !== $posTitle) {
$position = strpos($articleText, 'title="');
$title = substr($articleText, $position + strlen('title="'));
$newPosition = strpos($title, '"');
$titleImage = substr($title, 0, $newPosition);
}
$position = strpos($articleText, (string) $separator1);
$srcImage = substr($articleText, $position + strlen($separator1));
$posImage = strrpos($srcImage, (string) $separator2);
if (false !== $posImage) {
$newPosition = strpos($srcImage, (string) $separator2);
$newSrcImage = substr($srcImage, 0, $newPosition);
$validateImage = strpos($newSrcImage, '.html');
$validateVideo = strpos($newSrcImage, '.mp');
$validateVideoYTB = strpos($newSrcImage, 'youtube.com');
if (false !== $validateImage || false !== $validateVideo || false !== $validateVideoYTB) {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => $titleImage]);
} else {
$validateUrl = strpos($newSrcImage, '.com');
if (false !== $validateUrl) {
$urlImage = $newSrcImage;
} else {
$urlImage = $_SERVER['SERVER_NAME'].$newSrcImage;
}
$url = curl_init($urlImage);
curl_setopt($url, CURLOPT_TIMEOUT, 5);
curl_setopt($url, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($url);
$httpcode = curl_getinfo($url, CURLINFO_HTTP_CODE);
curl_close($url);
if (200 == $httpcode || 301 == $httpcode) {
return $this->json(['img' => $newSrcImage, 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
} else {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
}
}
}
} elseif (false !== $posSlider) {
$separator1 = "background-image: url('";
$separator2 = "');";
$posTitle = strrpos($articleText, 'title="');
if (false !== $posTitle) {
$position = strpos($articleText, 'title="');
$title = substr($articleText, $position + strlen('title="'));
$newPosition = strpos($title, '"');
$titleImage = substr($title, 0, $newPosition);
}
$position = strpos($articleText, $separator1);
$srcImage = substr($articleText, $position + strlen($separator1));
$posImage = strrpos($srcImage, $separator2);
if (false !== $posImage) {
$newPosition = strpos($srcImage, $separator2);
$newSrcImage = substr($srcImage, 0, $newPosition);
$validateImage = strpos($newSrcImage, '.html');
$validateVideo = strpos($newSrcImage, '.mp');
$validateVideoYTB = strpos($newSrcImage, 'youtube.com');
if (false !== $validateImage || false !== $validateVideo || false !== $validateVideoYTB) {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => $titleImage]);
} else {
$validateUrl = strpos($newSrcImage, '.com');
if (false !== $validateUrl) {
$urlImage = $newSrcImage;
} else {
$urlImage = $_SERVER['SERVER_NAME'].$newSrcImage;
}
$url = curl_init($urlImage);
curl_setopt($url, CURLOPT_TIMEOUT, 5);
curl_setopt($url, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($url);
$httpcode = curl_getinfo($url, CURLINFO_HTTP_CODE);
curl_close($url);
if (200 == $httpcode || 301 == $httpcode) {
return $this->json(['img' => $newSrcImage, 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
} else {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
}
}
} else {
$validateImage = strpos($srcImage, '.html');
$validateJs = strpos($srcImage, '.js');
if (false !== $validateImage || false !== $validateJs) {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
} else {
return $this->json(['img' => $srcImage, 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
}
}
} else {
return $this->json(['img' => 'https://aviaturcdndev.z5.web.core.windows.net/contenido/img/aviatur_logo_contenidos.webp', 'title' => html_entity_decode($titleImage, ENT_QUOTES, 'UTF-8')]);
}
break;
case 'availability':
$srcImage = $_SERVER['SERVER_NAME'].'/assets/aviatur_assets/img/places/'.$text.'.jpg';
$url = curl_init($srcImage);
curl_setopt($url, CURLOPT_TIMEOUT, 5);
curl_setopt($url, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
curl_setopt($url, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($url);
$httpcode = curl_getinfo($url, CURLINFO_HTTP_CODE);
curl_close($url);
if (200 == $httpcode || 301 == $httpcode) {
return new Response('/assets/aviatur_assets/img/places/'.$text.'.jpg');
} else {
return new Response('/assets/aviatur_assets/img/header/aviatur_logo.png');
}
break;
}
return new Response('/assets/aviatur_assets/img/header/aviatur_logo.png');
}
public function weatherAction($citySearch)
{
$forecastJson = [];
$em = $this->getDoctrine()->getManager();
$key = 'e211234b154f087975c17e74cb343e0b';
/* $key = "2c573f0ce919bbb3221089f625cf78a4"; key pruebas */
setlocale(LC_ALL, 'es_CO', 'esp');
$countries = ['á', 'é', 'í', 'ó', 'ú', 'Brasil', 'Mexico, Mexico', 'Rusia',
'La Coruña, España', 'España', 'Republica Checa', 'Estados Unidos', 'Republica Irlanda', 'Francia',
'Republica Dominicana', 'Alemania', 'Japon', 'Nueva Zelanda', 'Turquia',
'Tailandia', 'Emiratos Arabes Unidos', 'Curacao, Curaçao', 'Bélgica',
'Aruba, Aruba', 'Paises Bajos', 'Argelia', 'Camboya Riel', 'Congo Brazzaville',
'Costa de Marfil', 'Croacia', 'Dinamarca', 'Eslovaquia', 'Eslovenia', 'Etiopia',
'Filipinas', 'Finlandia', 'Grecia', 'Hungria', 'Laos', 'Lituania', 'Noruega',
'Sudafrica', 'Corea del Norte', 'Corea del Sur (Republica)', 'Republica Camerun',
'Republica Centro-Africana', 'Republica Democratica del Congo', 'Edimburgo, Gran Bretaña',
'Gran Bretaña', 'Italia', 'Venecia, Italy', 'Milan, Italy', 'Roma, Italy',
', Egipto', 'Dakhla Oasis', 'Santa Katarina', 'Taba', 'Alejandria', 'Suiza', 'Marruecos', 'Zimbabue',
'Ucrania', 'Tunez', 'Suecia', 'Siria', 'San Vicente y Las Granadinas', 'Rumania', 'Puerto Carreno',
'Afganistan', 'Arabia Saudi', 'Bielorusia', 'Groenlandia', 'Guadalupe', 'Guayana', 'Guayana Francesa',
'Guinea Conakry', 'Guinea Ecuatorial', 'Islandia', 'Kenia', 'Nueva Caledonia', 'Papua Nueva Guinea',
'Polonia', 'Singapore, Singapore', 'Varsovia', 'Estocolmo', 'Estrasburgo', 'Filadelfia', 'Malasya',
'Luxembourg, Luxemburgo', ];
$replace = ['a', 'e', 'i', 'o', 'u', 'Brazil', 'Distrito Federal, Mexico', 'Russia',
'La Coruña', 'Spain', 'Czech Republic', 'United States of America', 'Ireland', 'France',
'Dominican Republic', 'Germany', 'Japan', 'New Zealand', 'Turkey',
'Thailand', 'United Arab Emirates', 'Willemstad, Curazao', 'Belgium',
'Oranjestad, Aruba', 'Netherlands', 'Algeria', 'Cambodia', 'Congo',
"Cote d'Ivoire", 'Croatia', 'Denmark', 'Slovakia', 'Slovenia', 'Ethiopia',
'Philippines', 'Finland', 'Greece', 'Hungary', "Lao People's Democratic Republic",
'Lithuania', 'Norway', 'South Africa', 'North Korea', 'South Korea', 'Cameroon',
'Central African Republic', 'Democratic Republic of Congo', 'Edimburgo',
'United Kingdom', 'Italy', 'Venecia', 'Milan', 'Roma, Italia', '',
'Dakhla Oasis, Egipto', 'Santa Katarina, Egipto', 'Taba, Egypt', 'Alejandría', 'Switzerland', 'Morocco',
'Zimbabwe', 'Ukraine', 'Tunisia', 'Sweden', 'Syria', 'Saint Vincent and the Grenadines',
'Romania', 'Colombia', 'Afghanistan', 'Saudi Arabia', 'Belarus', 'Greenland', 'Guadeloupe',
'Guyana', 'French Guiana', 'Guinea', 'Equatorial Guinea', 'Iceland', 'Kenya', 'New Caledonia',
'Papua New Guinea', 'Poland', 'Singapore, Singapur', 'Warsaw', 'Stockholm', 'Strasburg', 'Philadelphia',
'Malaysia', 'Luxembourg, Luxembourg', ];
$location = ['Brazil', 'Russia', 'Spain', 'Czech Republic', 'United States of America',
'Ireland', 'France', 'Dominican Republic', 'Germany', 'Japan', 'New Zealand', 'Turkey',
'Thailand', 'United Arab Emirates', 'Willemstad, Países Bajos Antilles', 'Belgica', 'Netherlands', 'Algeria', 'Cambodia',
"Cote d'Ivoire", 'Croatia', 'Denmark', 'Slovakia', 'Slovenia', 'Ethiopia',
'Philippines', 'Finland', 'Greece', 'Hungary', "Lao People's Democratic Republic",
'Lithuania', 'Norway', 'South Africa', 'North Korea', 'South Korea', 'Cameroon',
'Central African Republic', 'Democratic Republic of Congo', 'United Kingdom', 'Reino Unido',
'Italy', 'Itália', 'Egypt', 'Switzerland', 'Morocco', 'Zimbabwe', 'Ukraine', 'Tunisia',
'Sweden', 'Syria', 'Saint Vincent and the Grenadines', 'Romania', 'Afghanistan', 'Saudi Arabia',
'Belarus', 'Greenland', 'Guadeloupe', 'Guyana', 'French Guiana', 'Guinea', 'Equatorial Guinea',
'Iceland', 'Kenya', 'New Caledonia', 'Papua New Guinea', 'Poland', 'Singapore, Singapore', 'Warsaw', 'Stockholm',
'Strasburg', 'Philadelphia', 'Malaysia', 'Luxembourg, Luxembourg', ];
$replaceLocation = ['Brasil', 'Rusia', 'España', 'República Checa', 'Estados Unidos',
'República Irlanda', 'Francia', 'República Dominicana', 'Alemania', 'Japón', 'Nueva Zelanda', 'Turquía',
'Tailandia', 'Emiratos Arabes Unidos', 'Willemstad, Curaçao', 'Bélgica', 'Países Bajos', 'Argelia', 'Camboya Riel',
'Costa de Marfil', 'Croacia', 'Dinamarca', 'Eslovaquia', 'Eslovenia', 'Etiopia',
'Filipinas', 'Finlandia', 'Grecia', 'Hungría', 'Laos', 'Lituania', 'Noruega',
'Sudáfrica', 'Corea del Norte', 'Corea del Sur (República)', 'República Camerun',
'República Centro-Africana', 'República Democratica del Congo', 'Gran Bretaña', 'Gran Bretaña',
'Italia', 'Italia', 'Egipto', 'Suiza', 'Marruecos', 'Zimbabue', 'Ucrania', 'Túnez',
'Suecia', 'Siria', 'San Vicente y Las Granadinas', 'Rumanía', 'Afganistán', 'Arabia Saudí',
'Bielorusia', 'Groenlandia', 'Guadalupe', 'Guayana', 'Guayana Francesa', 'Guinea Conakry', 'Guinea Ecuatorial',
'Islandia', 'Kenia', 'Nueva Caledonia', 'Papua Nueva Guinea', 'Polonia', 'Singapore, Singapur', 'Varsovia', 'Estocolmo',
'Estrasburgo', 'Filadelfia', 'Malasya', 'Luxembourg, Luxemburgo', ];
$findCity = preg_replace("/\((.*?)\)/i", '', $citySearch); /* Quitar parentesis y su contenido */
$searchCity = str_replace($countries, $replace, trim($findCity));
$city = urlencode($searchCity);
$url = "https://api.weatherstack.com/forecast?access_key=$key&language=es&query=$city&forecast_days=7&hourly=1&interval=24";
$searchWeather = $em->getRepository(\Aviatur\GeneralBundle\Entity\Weather::class)->findBy(['location' => trim($findCity)]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$json_output = curl_exec($ch);
$weather = json_decode($json_output);
if (isset($weather->success) && !$weather->success) {
return $this->json('Error API');
} else {
if (!empty($searchWeather)) {
$timeCurrent = new \DateTime(date('Y-m-d H:i:s'));
$timeBD = new \DateTime($searchWeather[0]->getEntrydate()->format('Y-m-d H:i:s'));
$difference = $timeCurrent->diff($timeBD);
$differenceDate = $difference->days;
$differenceHour = $difference->format('%H');
if ('0' == $differenceDate && $differenceHour < '4') { /* Si no ha pasado mas de 4 horas o 1 día no se actualiza el registro en BD */
$forecast = json_decode($searchWeather[0]->getForecast(), true);
$forecastArray = [];
if ($forecast && is_array($forecast)) {
foreach ($forecast as $key => $value) {
$forecastArray[$key] = $value;
}
$weatherInfo = [];
$dateLocale = strtotime($searchWeather[0]->getDay()->format('Y-m-d'));
$dateCurrent = strftime('%B %d', $dateLocale);
$countDays = count($forecastArray) / 5;
for ($i = 0; $i < $countDays; ++$i) {
$dateWeather = new \DateTime($forecastArray['date'.$i]);
$actualDate = new \DateTime($searchWeather[0]->getDay()->format('Y-m-d'));
$difference = $actualDate->diff($dateWeather);
$differenceDates = $difference->format('%r%a');
if ($differenceDates > 0) {
$time = strtotime($forecastArray['date'.$i]);
$date = strftime('%B %d', $time);
$icon = $forecastArray['icon'.$i];
$weatherInfo[$i] = [
'date' => $date,
'icon' => $icon,
'condition' => $forecastArray['condition'.$i],
'maxTemp' => $forecastArray['maxTemp'.$i],
'minTemp' => $forecastArray['minTemp'.$i],
'dateFormat' => $forecastArray['date'.$i],
];
}
}
foreach ($searchWeather as $weather) {
$weatherInfo['current'] = [
'locationName' => $weather->getlocation(),
'background' => '/assets/aviatur_assets/img/weather/background/'.((1 == $weather->getIsday()) ? 'is-day.jpg' : 'is-night.jpg'),
'dateCurrent' => $dateCurrent,
'dateFormat' => $searchWeather[0]->getDay()->format('Y-m-d'),
'temp' => $weather->getTemperature(),
'condition' => $weather->getState(),
'icon' => '/assets/aviatur_assets/img/weather/icons/'.$weather->getIcon(),
];
}
return $this->json($weatherInfo);
} else {
return $this->json('No se encontro la ubicación');
}
} else { /* Si ha pasado mas de 4 horas o 1 día se actualiza el registro en BD */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$json_output = curl_exec($ch);
$weather = json_decode($json_output);
if (isset($weather->location) && isset($weather->forecast)) {
$forecastUpdate = [];
$forecastSearch = [];
foreach ($weather->forecast as $key => $value) {
$forecastSearch[] = $value;
}
$indice = 0;
$dateA = substr($weather->location->localtime, 0, -5);
$dateLocale = strtotime($dateA);
$dateCurrent = strftime('%B %d', $dateLocale);
for ($i = 1; $i < count($forecastSearch); ++$i) {
$time = strtotime($forecastSearch[$i]->date);
setlocale(LC_ALL, 'es_CO', 'esp');
$date = strftime('%B %d', $time);
$icon = explode('_64/', $forecastSearch[$i]->hourly[0]->weather_icons[0]);
$forecastUpdate[$indice] = [
'date' => $date,
'icon' => '/assets/aviatur_assets/img/weather/icons/'.$icon[1],
'condition' => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
'maxTemp' => $forecastSearch[$i]->maxtemp,
'minTemp' => $forecastSearch[$i]->mintemp,
'dateFormat' => $forecastSearch[$i]->date,
];
$forecastJson[$indice] = [
'date'.$indice => $forecastSearch[$i]->date,
'icon'.$indice => '/assets/aviatur_assets/img/weather/icons/'.$icon[1],
'condition'.$indice => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
'maxTemp'.$indice => $forecastSearch[$i]->maxtemp,
'minTemp'.$indice => $forecastSearch[$i]->mintemp,
];
++$indice;
}
$iconCurrent = explode('_64/', $weather->current->weather_icons[0]);
$background = ('yes' == $weather->current->is_day) ? 'is-day.jpg' : 'is-night.jpg';
if ('Puerto Rico' == $weather->location->region) {
$name = $weather->location->name.', '.$weather->location->region;
} else {
$name = $weather->location->name.', '.$weather->location->country;
}
$locationName = str_replace($location, $replaceLocation, $name);
$forecastUpdate['current'] = [
'locationName' => $locationName,
'icon' => '/assets/aviatur_assets/img/weather/icons/'.$iconCurrent[1],
'background' => '/assets/aviatur_assets/img/weather/background/'.$background,
'temp' => $weather->current->temperature,
'condition' => $weather->current->weather_descriptions_es[0],
'dateCurrent' => $dateCurrent,
'dateFormat' => $dateA, ];
$acentos = ['á', 'é', 'í', 'ó', 'ú'];
$replaceAcentos = ['a', 'e', 'i', 'o', 'u'];
$country = explode(', ', trim($findCity));
$countryReplace = str_replace($acentos, $replaceAcentos, $country);
$countrySearch = explode(', ', $locationName);
$countrySearchReplace = str_replace($acentos, $replaceAcentos, $countrySearch);
if ($countryReplace[1] == $countrySearchReplace[1]) {
$forecastW = json_encode($forecastJson);
$forecastJSON = trim($forecastW, '[]');
$forecastJSON = str_replace('},{', ',', $forecastJSON);
$idWeather = $searchWeather[0]->getId();
$Weather = $em->getRepository(\Aviatur\GeneralBundle\Entity\Weather::class)->find($idWeather);
$Weather->setDay(new \DateTime($dateA));
$Weather->setIsday(('yes' == $weather->current->is_day) ? 1 : 0);
$Weather->setTemperature($forecastUpdate['current']['temp']);
$Weather->setState($forecastUpdate['current']['condition']);
$Weather->setIcon($iconCurrent[1]);
$Weather->setForecast($forecastJSON);
$Weather->setEntryDate(new \DateTime());
$em->persist($Weather);
$em->flush();
return $this->json($forecastUpdate);
} else {
return $this->json('No se encontro la ubicación');
}
} else {
return $this->json('No se encontro la ubicación');
}
}
} else { /* Se genera nuevo registro en la BD */
if (isset($weather->location) && isset($weather->forecast)) {
$forecastNew = [];
$indice = 0;
$dateC = substr($weather->location->localtime, 0, -5);
$dateLocale = strtotime($dateC);
$dateCurrent = strftime('%B %d', $dateLocale);
$forecastSearch = [];
$iconCurrent = explode('_64/', $weather->current->weather_icons[0]);
$background = ('yes' == $weather->current->is_day) ? 'is-day.jpg' : 'is-night.jpg';
foreach ($weather->forecast as $key => $value) {
$forecastSearch[] = $value;
}
for ($i = 1; $i < count($forecastSearch); ++$i) {
$dateWeather = new \DateTime($forecastSearch[$i]->date);
$currentDate = new \DateTime($dateC);
$difference = $currentDate->diff($dateWeather);
$differenceDates = $difference->format('%r%a');
if ($differenceDates > 0) {
$time = strtotime($forecastSearch[$i]->date);
setlocale(LC_ALL, 'es_CO', 'esp');
$date = strftime('%B %d', $time);
$icon = $iconCurrent[1];
$forecastNew[$indice] = [
'date' => $date,
'icon' => '/assets/aviatur_assets/img/weather/icons/'.$icon,
'condition' => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
'maxTemp' => $forecastSearch[$i]->maxtemp,
'minTemp' => $forecastSearch[$i]->mintemp,
'dateFormat' => $forecastSearch[$i]->date,
];
$forecastJson[$indice] = [
'date'.$indice => $forecastSearch[$i]->date,
'icon'.$indice => '/assets/aviatur_assets/img/weather/icons/'.$icon,
'condition'.$indice => $forecastSearch[$i]->hourly[0]->weather_descriptions_es[0],
'maxTemp'.$indice => $forecastSearch[$i]->maxtemp,
'minTemp'.$indice => $forecastSearch[$i]->mintemp,
];
++$indice;
}
}
if ('Puerto Rico' == $weather->location->region) {
$name = $weather->location->name.', '.$weather->location->region;
} else {
$name = $weather->location->name.', '.$weather->location->country;
}
$locationName = str_replace($location, $replaceLocation, $name);
$forecastNew['current'] = [
'locationName' => $locationName,
'icon' => '/assets/aviatur_assets/img/weather/icons/'.$iconCurrent[1],
'background' => '/assets/aviatur_assets/img/weather/background/'.$background,
'temp' => $weather->current->temperature,
'condition' => $weather->current->weather_descriptions_es[0],
'dateCurrent' => $dateCurrent,
'dateFormat' => $dateC,
];
$acentos = ['á', 'é', 'í', 'ó', 'ú'];
$replaceAcentos = ['a', 'e', 'i', 'o', 'u'];
$country = explode(', ', trim($findCity));
$countryReplace = str_replace($acentos, $replaceAcentos, $country);
$countrySearch = explode(', ', $locationName);
$countrySearchReplace = str_replace($acentos, $replaceAcentos, $countrySearch);
if ($countryReplace[1] == $countrySearchReplace[1]) {
$jsonForecast = json_encode($forecastJson);
$forecastJSON = trim($jsonForecast, '[]');
$forecastJSON = str_replace('},{', ',', $forecastJSON);
$weatherAdd = new Weather();
$weatherAdd->setLocation(trim($findCity));
$weatherAdd->setDay(new \DateTime($dateC));
$weatherAdd->setIsday(('yes' == $weather->current->is_day) ? 1 : 0);
$weatherAdd->setTemperature($forecastNew['current']['temp']);
$weatherAdd->setState($forecastNew['current']['condition']);
$weatherAdd->setIcon($iconCurrent[1]);
$weatherAdd->setForecast($forecastJSON);
$weatherAdd->setEntrydate(new \DateTime());
$em->persist($weatherAdd);
$em->flush();
return $this->json($forecastNew);
} else {
return $this->json('No se encontro la ubicación');
}
} else {
return $this->json('No se encontro la ubicación');
}
}
}
}
public function promoTicketsAction(SessionInterface $session)
{
$em = $this->getDoctrine()->getManager();
$agencyId = $session->get('agencyId');
$homePromoList = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findBy(['type' => '__tiquetes', 'agency' => $agencyId]);
$promos = [];
$indice = 0;
if (null != $homePromoList) {
$homePromos = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoList);
for ($i = 0; $i < (is_countable($homePromos) ? count($homePromos) : 0); ++$i) {
$city = $homePromos[$i]->getTitle();
$country = $homePromos[$i]->getTitleSwitch();
$pos = strpos($city, '-');
$pos1 = strpos($city, ' a ');
if (false != $pos) {
$cityArray = explode('-', $city);
$city = trim($cityArray[0]);
$dataCity = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city, 'country' => $country]);
} elseif (false != $pos1) {
$cityArray = explode(' a ', $city);
$city = trim($cityArray[1]);
$dataCity = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city, 'country' => $country]);
} else {
$dataCity = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findBy(['city' => $city, 'country' => $country]);
}
if (!empty($dataCity)) {
foreach ($dataCity as $data) {
$iataCode = $data->getIata();
}
} else {
$iataCode = 'null';
}
$promos[$indice] = [
'id' => $homePromos[$i]->getId(),
'city' => $homePromos[$i]->getTitle(),
'country' => $homePromos[$i]->getTitleSwitch(),
'description' => $homePromos[$i]->getContent(),
'price' => $homePromos[$i]->getPrice(),
'url' => $homePromos[$i]->getLink(),
'urlImage' => $homePromos[$i]->getLinkSwitch(),
'date' => $homePromos[$i]->getDate(),
'iata' => $iataCode,
'promoType' => '__tiquetes',
];
++$indice;
}
return $this->json($promos);
} else {
$homePromos = [];
return $this->json($homePromos);
}
}
}