src/Uniski/CMSBundle/Controller/PageController.php line 194

Open in your IDE?
  1. <?php
  2. namespace Uniski\CMSBundle\Controller;
  3. // IvoryGoogleMapBundle eliminado en migración Sf4 — mapa renderizado con JS directo
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Uniski\CMSBundle\Entity\Offer;
  9. use Uniski\CMSBundle\Entity\Page;
  10. use Uniski\CMSBundle\Form\WebForm\InfoFormType;
  11. use Uniski\CMSBundle\Form\WebForm\InfoSchoolGroupsFormType;
  12. use Uniski\ConfigBundle\Entity\Category;
  13. use Uniski\ConfigBundle\Factory\ConfigurationFactory;
  14. use Uniski\ResourceBundle\Controller\BaseController;
  15. use Uniski\ResourceBundle\Entity\Hotel;
  16. use Uniski\ResourceBundle\Entity\Product;
  17. class PageController extends BaseController
  18. {
  19.   /**
  20.    * @Route("/", name="homepage")
  21.    */
  22.   public function indexAction()
  23.   {
  24.     $offerManager $this->get('app.offer_manager');
  25.     $offers $offerManager->getOffers(['frontpage' => 'all']);
  26.     $topPosts $this->getRepository(\Uniski\CMSBundle\Entity\Post::class)->findByStick(true, ['created' => 'DESC']);
  27.     $posts $this->getRepository(\Uniski\CMSBundle\Entity\Post::class)->findByStick(false, ['created' => 'DESC'], 8);
  28.     $config $this->get('app.config_manager')
  29.                    ->get(ConfigurationFactory::HOMEPAGE)
  30.                    ->getSettings();
  31.     $sections = [
  32.       [
  33.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_1),
  34.         'title'   => $config['section_1']['title']
  35.       ],
  36.       [
  37.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_2),
  38.         'title'   => $config['section_2']['title']
  39.       ],
  40.       [
  41.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_3),
  42.         'title'   => $config['section_3']['title']
  43.       ],
  44.     ];
  45.     $response $this->render("page/home.html.twig", [
  46.         'sliderOffers'    => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SLIDER),
  47.         'sections'        => $sections,
  48.         'topPosts'        => $topPosts,
  49.         'posts'           => $posts,
  50.         'menu'            => 'homepage',
  51.         'search'          => $this->get('app.search_manager')->createSearch(),
  52.         'config'          => $config
  53.       ]);
  54.       $response->setSharedMaxAge(86400);
  55.       $response->headers->addCacheControlDirective('must-revalidate'true);
  56.       return $response;
  57.   }
  58.   /**
  59.    * @Route("hoteles", name="hotels_page")
  60.    */
  61.   public function hotelsAction(Request $request)
  62.   {
  63.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  64.         'target' => 'hotels',
  65.         'request' => $request
  66.       ]);
  67.   }
  68.   /**
  69.    * @Route("destinos", name="destinations_page")
  70.    */
  71.   public function destinationsAction(Request $request)
  72.   {
  73.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  74.         'target' => 'destinations',
  75.         'request' => $request
  76.       ]);
  77.   }
  78.   /**
  79.    * @Route("hotel/{slug}", name="hotel_show")
  80.    */
  81.   public function hotelShowAction(Hotel $hotelRequest $request)
  82.   {
  83.     $productPriceService $this->get('app.product_price_service');
  84.     $offerManager        $this->get('app.offer_manager');
  85.     $searchManager       $this->get('app.search_manager');
  86.     $search              $searchManager->createSearch();
  87.     $map                 null;
  88.     $products            = [];
  89.     $search['entity']['value'] = $hotel->getId();
  90.     
  91.     $allProducts $this->getRepository(\Uniski\ResourceBundle\Entity\Product::class)->findByZone($hotel->getZone());
  92.     foreach ($allProducts as $product) {
  93.       
  94.       $products[] = [
  95.         'product' => $product,
  96.         'minPrice'    => $offerManager->calculateMinPrice($product)
  97.       ];
  98.     }
  99.     if ($hotel->getAddress() &&
  100.         $hotel->getAddress()->hasCoordinates()) {
  101.       $map = [
  102.         'latitude' => $hotel->getAddress()->getLatitude(),
  103.         'longitude' => $hotel->getAddress()->getLongitude(),
  104.         'zoom' => 15,
  105.       ];
  106.     }
  107.     return $this->render('hotel/show.html.twig',[
  108.         'hotel'    => $hotel,
  109.         'map'      => $map,
  110.         'search'   => $search,
  111.         'products' => $products
  112.       ]);
  113.   }
  114.   /**
  115.    * @Route("/ofertas/ski/{slug}")
  116.    */
  117.   public function destinationsByZoneAction(Category $zoneRequest $request)
  118.   {
  119.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  120.         'target' => $zone,
  121.         'request' => $request
  122.       ]);
  123.   }
  124.   /**
  125.    * @Route("/contacto", name="contact_page")
  126.    */
  127.   public function contactAction(Request $request)
  128.   {
  129.     $form $this->get('app.webform_manager')->submitWebForm($request);
  130.     return $this->render('page/contact.html.twig', [
  131.         'form' => $form->createView(),
  132.         'menu' => 'contact'
  133.       ]);
  134.   }
  135.   /**
  136.    * @Route("/aviso-legal", name="legal_notice_page")
  137.    */
  138.   public function legalNoticeAction()
  139.   {
  140.     return $this->render('page/legal_notice.html.twig', []);
  141.   }
  142.   public function footerMenuAction($region)
  143.   {
  144.     $menus $this->getRepository(\Uniski\CMSBundle\Entity\Menu::class)->findAll();
  145.     $menu $menus[$region];
  146.     return $this->render("page/footer-menu.html.twig", [
  147.         'menu' => $menu
  148.       ]);
  149.   }
  150.   /**
  151.    * @Route("/politica-cookies", name="cookies_policy_page")
  152.    */
  153.   public function cookiesPolicyAction()
  154.   {
  155.     return $this->render('page/cookies_policy.html.twig', []);
  156.   }
  157.   public function backgroundAction()
  158.   {
  159.     $background null;
  160.     $imageRepo  $this->getRepository(\Uniski\ResourceBundle\Entity\Image::class);
  161.     $config     $this->get('app.config_manager')
  162.                        ->get(ConfigurationFactory::HOMEPAGE)
  163.                        ->getSettings();
  164.     if (!empty($config['background'])) {
  165.       $background $imageRepo->find($config['background']);
  166.     }
  167.     return $this->render('default/background.html.twig', [
  168.         'background' => $background
  169.       ]);
  170.   }
  171.   /**
  172.    * @Route("/{prefix}/{slug}", name="show_page",)
  173.    * @Route("/{slug}")
  174.    */
  175.   public function showPageAction(Page $pageRequest $request)
  176.   {
  177.     //Avoid duplicated pages
  178.     if ($request->get('_route') != 'show_page' && $page->getPrefix()) {
  179.       return $this->redirectToRoute("show_page", [
  180.         'prefix' => $page->getPrefix(),
  181.         'slug'   => $page->getSlug()
  182.       ], 301);
  183.     }
  184.     $webformService $this->get('app.webform_manager');
  185.     $form           null;
  186.     $template       null;
  187.     if ($page->getWebForm()) {
  188.       $form $webformService->submitWebForm($request$page->getWebForm(), [
  189.           'page' => $page
  190.         ]);
  191.       $template $this->getTemplateFromForm($page->getWebForm());
  192.     }
  193.     $offerManager $this->get('app.offer_manager');
  194.     $offers $offerManager->getOffers(['page' => $page]);
  195.     $response $this->render('page/show.html.twig', [
  196.       'page' => $page,
  197.       'offers' => $offers,
  198.       'menu' => $page->getSlug(),
  199.       'form' => $form $form->createView() : null,
  200.       'webformTemplate' => $template,
  201.       'search' => $this->get('app.search_manager')->createSearch(),
  202.     ]);
  203.     $response->setSharedMaxAge(86400);
  204.     $response->headers->addCacheControlDirective('must-revalidate'true);
  205.     return $response;
  206.     
  207.   }
  208.   /**
  209.    *
  210.    *
  211.    *    DO NOT ADD MORE ROUTES AFTER THIS LINES!!!!!
  212.    *
  213.    * 
  214.    */
  215.   private function getTemplateFromForm($webform)
  216.   {
  217.     switch ($webform) {
  218.       case InfoFormType::class:
  219.         return 'webform/info.html.twig';
  220.       case InfoSchoolGroupsFormType::class:
  221.         return 'webform/school_groups.html.twig';
  222.     }
  223.   }
  224. }