custom/src/EshopBundle/Controller/PageController.php line 113

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (C) eBRANA s.r.o. - All Rights Reserved
  4.  * Unauthorized copying of this file, via any medium is strictly prohibited
  5.  * Proprietary and confidential
  6.  */
  7. namespace EshopBundle\Controller;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use EshopBundle\Entity\MlEmail;
  10. use EshopBundle\Entity\Page;
  11. use EshopBundle\Form\Type\NewsletterRegistrationTypeExtended;
  12. use EshopBundle\Form\Type\NewsletterRegistrationType;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. /**
  16.  * Controller pro staticke stranky
  17.  */
  18. class PageController extends DefaultController
  19. {
  20.     use Traits\PageTrait;
  21.     /**
  22.      * Zobrazeni stranky
  23.      *
  24.      * DS 2022-04-08 V083446 pĹ™evzato z purusmedy
  25.      *
  26.      * @param  int $id - id stranky
  27.      * @param  \Symfony\Component\HttpFoundation\Request $request
  28.      * @return \Symfony\Component\HttpFoundation\Response
  29.      */
  30.     public function indexAction($idRequest $request)
  31.     {
  32.         // nacteni stranky
  33.         /** @var Page $page */
  34.         $page $this
  35.             ->getDoctrine()
  36.             ->getRepository('EshopBundle:Page')
  37.             ->find($id);
  38.         // stranka nenalezena
  39.         if (empty($page)) {
  40.             return $this->forward('EshopBundle:Error:show', [
  41.                 'request' => $request,
  42.                 'exception' => $this->createNotFoundException('Page not found for id ' $id)
  43.             ]);
  44.         }
  45.         if ($this->cacheService->createPageKey(count($page->getQSearchResult()))->cacheExists()) {
  46.             return $this->cacheService->getCacheResponse();
  47.         }
  48.         /** @var \EshopBundle\DependencyInjection\View\VariablesBag $vars */
  49.         $vars $this->get('view.variables');
  50.         $vars->setCanonicalUrl($page->getLink());
  51.         // pripojeni formularu
  52.         $forms $this->appendForms($request'stranky3'$id$page->getLink(), $page->getName());
  53.         $newsletterForm null;
  54.         if($page->getShowNewsletterForm() && !empty($page->getFiles()->getValues())) {
  55.             $mlEmail = new MlEmail();
  56.             $newsletterForm $this->createForm(NewsletterRegistrationTypeExtended::class, $mlEmail, [
  57.                 'action' => $this->generateUrl('newsletter_extended_register', ['pageId' => $page->getId()]),
  58.                 'method' => 'POST',
  59.                 'attr' => ['pageId' => $page->getId()]
  60.             ]);
  61.         }
  62.         if ($forms instanceof Response) {
  63.             return $forms;
  64.         }
  65.         // pripojeni map
  66.         $maps $this->appendGoogleMaps('stranky3'$id);
  67.         $apiKey $partnerConfig $this->get('eshop_config.partner_config')->getGoogleMapApiKey();
  68.         $this->populateCrumbtrail();
  69.         $this->populateSeoFields();
  70.         $google $this->get('marketing.google');
  71.         $google $google->dlOther();
  72.         if($newsletterForm) {
  73.             $form $newsletterForm->createView();
  74.         } else {
  75.             $form null;
  76.         }
  77.         /** @var ArrayCollection $files */
  78.         $files $page->getFiles();
  79.         if(null !== $form) {
  80.             $files->remove(0);
  81.         }
  82.         // renderovani stranky
  83.         $response $this->render('page/index.html.twig', array(
  84.             'page' => $page,
  85.             'maps' => $maps,
  86.             'apiKey' => $apiKey,
  87.             'formViews' => $forms['formViews'],
  88.             'formInstances' => $forms['formInstances'],
  89.             'banners' => $this->get('marketing.banners')->loadForSection('page'$id),
  90.             'qSearch' => $this->getQSearch($page$request),
  91.             'newsletterForm' => $form,
  92.             'files' => $files,
  93.         ));
  94.         $this->cacheService->setCache($response);
  95.         return $response;
  96.     }
  97. }