<?php
namespace Aviatur\BlogBundle\Controller;
use Aviatur\FormBundle\Entity\Newsletter;
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\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class DefaultController extends AbstractController
{
public function indexAction(Request $request, SessionInterface $session, TwigFolder $twigFolder, AuthorizationCheckerInterface $authorizationChecker, AviaturErrorHandler $errorHandler, PaginatorInterface $paginator, $page, $active)
{
$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();
$homePromoList = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'slider', 'agency' => $agency]);
$homePromos = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoList, ['date' => 'DESC']);
$homePromoListMain = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromoList::class)->findOneBy(['type' => 'main_slider', 'agency' => $agency]);
$homePromosMain = $em->getRepository(\Aviatur\EditionBundle\Entity\HomePromo::class)->findByHomePromoList($homePromoListMain);
$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 ('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'));
}
}
$actualArticles = [];
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description) && 'general' == $description['type']) {
$actualArticles[] = $articulo;
}
}
if (empty($actualArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cantdatos = count($actualArticles);
$cantRegis = 6;
$totalRegi = ceil($cantdatos / $cantRegis);
$pagination = $paginator->paginate($actualArticles, $fullRequest->query->get('page', $page), $cantRegis);
$blog = new Newsletter();
$blogForm = $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/index.html.twig'), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalRegi, 'ajaxUrl' => $requestUrl, 'slider' => $homePromos, 'contenidos' => $homePromosMain, 'blog_form' => $blogForm->createView()]);
}
public function indexDestinosAction(Request $request, SessionInterface $session, TwigFolder $twigFolder)
{
$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();
$blog = new Newsletter();
$blogForm = $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/destinos.html.twig'), ['blog_form' => $blogForm->createView()]);
}
public function listAction(Request $request, SessionInterface $session, TwigFolder $twigFolder, AviaturErrorHandler $errorHandler, 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();
$blog = new Newsletter();
$blogForm = $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
if ($fullRequest->isXmlHttpRequest()) {
$query = $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.publicationenddate DESC');
$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.publicationenddate DESC');
$queryIn = $queryIn->setParameter('agency', $agency);
if (isset($routeParams['content'])) {
$path = '/Blog/Default/Ajaxindex_destinos.html.twig';
} else {
$path = '/Blog/Default/Ajaxindex_contenidos.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
$colombia = [];
$america = [];
$oceania = [];
$europa = [];
$africa = [];
$asia = [];
$tipsArticles = [];
$gastronomiaArticles = [];
$experienciasArticles = [];
$actualArticles = [];
$cantRegis = 9;
if ('activo' == $active) {
$articulos = $query->getResult();
}
if (isset($routeParams['content'])) {
if ('general' == $type) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('destinos-blog' == $description['type']) {
$actualArticles[] = $articulo;
}
}
}
if (empty($actualArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cantDestinos = count($actualArticles);
$totalDestinos = ceil($cantDestinos / $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' => $totalDestinos, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('destinos-blog' == $description['type'] && 'colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'america' == $description['type2']) {
$america[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'asia' == $description['type2']) {
$asia[] = $articulo;
}
}
}
if (empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
/* Redireccion articulos destinos y aerolineas */
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('ciudades-mundialistas' == $type) {
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/ciudades_mundialistas.html.twig'), ['agencyId' => $agencyId, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
if ('tips' == $description['categoria']) {
$tipsArticles[] = $articulo;
}
if ('sostenibilidad' == $description['categoria']) {
$tipsArticles[] = $articulo;
}
if ('gastronomia' == $description['categoria']) {
$gastronomiaArticles[] = $articulo;
}
if ('experiencias' == $description['categoria']) {
$experienciasArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
/* Redireccion articulos contenido general, revista e información */
if ('contenidos' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/division_contenidos.html.twig'), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('sostenibilidad' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('tips' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('gastronomia' == $type) {
$cantRevista = count($gastronomiaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($gastronomiaArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('experiencias' == $type) {
$cantInformacion = count($experienciasArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($experienciasArticles, $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, 'blog_form' => $blogForm->createView()]);
}
}
} else {
$query = $em->createQuery('SELECT a FROM AviaturContentBundle:Content a WHERE a.isactive = 1 AND (a.agency = :agency OR a.agency IS NULL) ORDER BY a.publicationenddate DESC');
$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.publicationenddate DESC');
$queryIn = $queryIn->setParameter('agency', $agency);
if (isset($routeParams['content'])) {
$path = '/Blog/Default/index_destinos.html.twig';
} else {
$path = '/Blog/Default/index_contenidos.html.twig';
}
$urlReturn = '@AviaturTwig/'.$agencyFolder.$path;
$colombia = [];
$america = [];
$oceania = [];
$europa = [];
$africa = [];
$asia = [];
$tipsArticles = [];
$gastronomiaArticles = [];
$experienciasArticles = [];
$actualArticles = [];
$cantRegis = 9;
if ('activo' == $active) {
$articulos = $query->getResult();
}
if (isset($routeParams['content'])) {
if ('general' == $type) {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('destinos-blog' == $description['type']) {
$actualArticles[] = $articulo;
}
}
}
if (empty($actualArticles)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
$cantDestinos = count($actualArticles);
$totalDestinos = ceil($cantDestinos / $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' => $totalDestinos, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if ('destinos-blog' == $description['type'] && 'colombia' == $description['type2']) {
$colombia[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'america' == $description['type2']) {
$america[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'oceania' == $description['type2']) {
$oceania[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'europa' == $description['type2']) {
$europa[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'africa' == $description['type2']) {
$africa[] = $articulo;
}
if ('destinos-blog' == $description['type'] && 'asia' == $description['type2']) {
$asia[] = $articulo;
}
}
}
if (empty($colombia) && empty($america) && empty($oceania) && empty($europa) && empty($africa) && empty($asia)) {
return $this->redirect($errorHandler->errorRedirectNoEmail('/', '', 'No existen contenidos para esta agencia.'));
}
/* Redireccion articulos destinos y aerolineas */
if ('colombia' == $type) {
$cantDestinosC = count($colombia);
$totalDestinosC = ceil($cantDestinosC / $cantRegis);
$pagination = $paginator->paginate($colombia, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosC, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('america' == $type) {
$cantDestinosA = count($america);
$totalDestinosA = ceil($cantDestinosA / $cantRegis);
$pagination = $paginator->paginate($america, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosA, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('oceania' == $type) {
$cantDestinosO = count($oceania);
$totalDestinosO = ceil($cantDestinosO / $cantRegis);
$pagination = $paginator->paginate($oceania, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosO, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('europa' == $type) {
$cantDestinosE = count($europa);
$totalDestinosE = ceil($cantDestinosE / $cantRegis);
$pagination = $paginator->paginate($europa, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosE, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('africa' == $type) {
$cantDestinosAF = count($africa);
$totalDestinosAF = ceil($cantDestinosAF / $cantRegis);
$pagination = $paginator->paginate($africa, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAF, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('asia' == $type) {
$cantDestinosAS = count($asia);
$totalDestinosAS = ceil($cantDestinosAS / $cantRegis);
$pagination = $paginator->paginate($asia, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists($urlReturn), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalDestinosAS, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('ciudades-mundialistas' == $type) {
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/ciudades_mundialistas.html.twig'), ['agencyId' => $agencyId, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
}
} else {
foreach ($articulos as $articulo) {
$description = json_decode($articulo->getDescription(), true);
if ($description && is_array($description)) {
if (isset($description['type'])) {
if ('general' == $description['type']) {
if ('tips' == $description['categoria']) {
$tipsArticles[] = $articulo;
}
if ('sostenibilidad' == $description['categoria']) {
$tipsArticles[] = $articulo;
}
if ('gastronomia' == $description['categoria']) {
$gastronomiaArticles[] = $articulo;
}
if ('experiencias' == $description['categoria']) {
$experienciasArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
} else {
$actualArticles[] = $articulo;
}
}
}
/* Redireccion articulos contenido general, revista e información */
if ('contenidos' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $fullRequest->query->get('page', $page), $cantRegis);
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/division_contenidos.html.twig'), ['agencyId' => $agencyId, 'articulo' => $pagination, 'page' => $page, 'active' => $active, 'totalRegi' => $totalGeneral, 'ajaxUrl' => $requestUrl, 'typeArticle' => $type, 'params' => $routeParams, 'blog_form' => $blogForm->createView()]);
}
if ('tips' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('sostenibilidad' == $type) {
$cantGeneral = count($tipsArticles);
$totalGeneral = ceil($cantGeneral / $cantRegis);
$pagination = $paginator->paginate($tipsArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('gastronomia' == $type) {
$cantRevista = count($gastronomiaArticles);
$totalRevista = ceil($cantRevista / $cantRegis);
$pagination = $paginator->paginate($gastronomiaArticles, $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, 'blog_form' => $blogForm->createView()]);
}
if ('experiencias' == $type) {
$cantInformacion = count($experienciasArticles);
$totalInformacion = ceil($cantInformacion / $cantRegis);
$pagination = $paginator->paginate($experienciasArticles, $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, 'blog_form' => $blogForm->createView()]);
}
}
}
}
public function extractDescriptionAction($text)
{
$article = $text;
$separator1 = '<p style="text-align: justify;">';
$separator2 = '</p>';
$articleText = $article->getText();
$pos = strrpos($articleText, $separator1);
if (false !== $pos) {
$position = strpos($articleText, $separator1);
$pText = substr($articleText, $position + strlen($separator1));
$posText = strrpos($pText, $separator2);
if (false !== $posText) {
$newPosition = strpos($pText, $separator2);
$description = substr($pText, 0, $newPosition);
$descriptionArticle = preg_replace('/<.+?>/', '', $description);
$descriptionArticle = html_entity_decode($descriptionArticle, ENT_QUOTES, 'UTF-8');
return new Response($descriptionArticle);
}
}
return new Response('vacio');
}
public function nameCityBlogAction($iata)
{
$em = $this->getDoctrine()->getManager();
$dest = $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneBy(['iata' => $iata]);
if (!empty($dest)) {
$cityName = $dest->getCity();
$cities = ['Paris', 'Mexico', 'Cancun', 'Panama City', 'Puerto Asis', 'Amsterdam', 'Iguazu', 'Zurich', 'Moscow', 'Dublin', 'Kazan', 'Monte Carlo', 'Malaga', 'Rio de Janeiro', 'Cordoba', 'Dubai', 'Seul'];
$citiesCorrection = ['París', 'Ciudad de México', 'Cancún', 'Panamá', 'Puerto Asís', 'Ámsterdam', 'Iguazú', 'Zúrich', 'Moscú', 'Dublín', 'Kazán', 'Mónaco', 'Málaga', 'Río de Janeiro', 'Córdoba', 'Dubái', 'Seúl'];
$city = str_replace($cities, $citiesCorrection, $cityName);
} else {
$city = 'vacio';
}
return new Response($city);
}
/*
* Visualiza el articulo seleccionado
*/
public function viewAction(SessionInterface $session, TwigFolder $twigFolder, $id)
{
$em = $this->getDoctrine()->getManager();
$articulo = $em->getRepository(\Aviatur\ContentBundle\Entity\Content::class)->findByAgencyNull($session->get('agencyId'), $id);
// $validateExplore = ((null === $em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]) ? 0 : count($em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]))) > 0) ? true : false;
$validateExplore=false;
$aviaturSearchExploreEntity=$em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]);
if (! is_null($aviaturSearchExploreEntity)) {
$aviaturSearchExploreEntity = $em->getRepository(\Aviatur\GeneralBundle\Entity\Parameter::class)->findOneBy(['name' => 'aviatur_search_explore', 'value' => 1]);
if (is_countable($aviaturSearchExploreEntity) ) {
if (count($aviaturSearchExploreEntity) > 0) {
$validateExplore=true;
}
}
}
if (isset($articulo[0]) && (null != $articulo[0])) {
$agencyFolder = $twigFolder->twigFlux();
$description = json_decode($articulo[0]->getDescription(), true);
$blog = new Newsletter();
$blogForm = $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $blog);
// determine content type based on eventual json encoded description
if ($description && is_array($description)) {
$pos = strpos($agencyFolder, 'aviatur');
if (false !== $pos) {
if ('destinos' == $description['type'] || 'destinos-blog' == $description['type']) {
$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().')';
$cookieArray['destinationIata'] = $dest->getIata();
} else {
$cookieArray['destinationLabel1'] = '';
$cookieArray['destinationIata'] = '';
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray, 'validateExplore' => $validateExplore, 'blog_form' => $blogForm->createView()]);
} else {
// eg: {"categoria":"tips|gastronomia|experiencias"}
$cookieArray = [];
foreach ($description as $key => $value) {
$cookieArray[$key] = $value;
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view_contenidos.html.twig'), ['articulo' => $articulo[0], 'cookieLastSearch' => $cookieArray, 'validateExplore' => $validateExplore, 'blog_form' => $blogForm->createView()]);
}
}
}
return $this->render($twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Blog/Default/view.html.twig'), ['articulo' => $articulo[0]]);
} else {
throw $this->createNotFoundException('Contenido no encontrado');
}
}
public function subscriptionAction(Request $request, SessionInterface $session)
{
$resgisterBlog = new Newsletter();
$em = $this->getDoctrine()->getManager();
$agency = $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($session->get('agencyId'));
$form = $this->createForm(\Aviatur\FormBundle\Form\BlogType::class, $resgisterBlog);
$form->handleRequest($request);
if ($form->isSubmitted()) {
$post = $request->request->get('blog_form');
if ($form->isValid()) {
if ($request->isXmlHttpRequest()) {
$resgisterBlog->setFirstname(ucwords(mb_strtolower($post['firstname'])));
$resgisterBlog->setLastname(ucwords(mb_strtolower($post['lastname'])));
$resgisterBlog->setEmail($post['email']);
$typeBlog = '{"newsletter":"no","blog":"si"}';
$resgisterBlog->setType($typeBlog);
$resgisterBlog->setAgency($agency);
$resgisterBlog->setPublicationDate(new \DateTime());
$em->persist($resgisterBlog);
$em->flush();
$response = new Response();
$output = ['success' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
} else {
$response = new Response();
$output = ['error' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
}
} else {
$emailRegister = $em->getRepository(\Aviatur\FormBundle\Entity\Newsletter::class)->findByEmail($post['email']);
if ($emailRegister) {
$type = json_decode($emailRegister[0]->getType(), true);
if ('no' == $type['blog']) {
$typeBlog = '{"newsletter":"si","blog":"si"}';
$emailRegister[0]->setType($typeBlog);
$em->persist($emailRegister[0]);
$em->flush();
$response = new Response();
$output = ['success' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
} else {
$response = new Response();
$output = ['email' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
}
} else {
$response = new Response();
$output = ['error' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
}
}
} else {
$response = new Response();
$output = ['error' => true];
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($output));
return $response;
}
}
}