src/Controller/FrontendShop/StaticPageController.php line 167

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontendShop;
  3. use App\Entity\Gos\Category;
  4. use App\Entity\Gos\PortalSettings;
  5. use App\Entity\Gos\ProductAssociation;
  6. use App\Entity\Gos\Tmpl\Template as TemplateEntity;
  7. use App\Entity\Gos\Tmpl\TemplateType;
  8. use App\Utils\Eforum\ProductFeed;
  9. use App\Utils\Encryption;
  10. use App\Utils\MailerUtils;
  11. use App\Utils\TemplateView;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class StaticPageController extends AbstractController
  18. {
  19.     private EntityManagerInterface $em;
  20.     private TemplateView $templateView;
  21.     public function __construct(EntityManagerInterface $emTemplateView $templateView)
  22.     {
  23.         $this->em $em;
  24.         $this->templateView $templateView;
  25.     }
  26.     /**
  27.      * @Route("/send-contact-email", name="efSendContactEmail", methods={"POST"})
  28.      */
  29.     public function contactEmailAction(Request $requestEncryption $encryptionMailerUtils $mailerUtils): Response
  30.     {
  31.         $data $request->request->all();
  32.         if (isset($data['encryptedEmail']) && isset($data['publicToken']))
  33.         {
  34.             $topic 'kontakt z wydawcÄ…';
  35.             $from $encryption->decrypt($data['encryptedEmail'], $data['publicToken']);
  36.         }
  37.         else
  38.         {
  39.             $topic 'pytanie od klienta';
  40.             $from $_ENV['EFORUM_CONTACT_EMAIL_FROM'];
  41.         }
  42.         $html $this->render('frontend-eforum/email/contact.html.twig', [
  43.             'data' => $data
  44.         ]);
  45.         $isSent $mailerUtils->sendSimpleMail(
  46.             'e-forum.pl ' $topic,
  47.             $from,
  48.             $_ENV['EFORUM_CONTACT_EMAIL_TO'],
  49.             $html
  50.         );
  51.         return new Response($isSent);
  52.     }
  53.     /**
  54.      * @Route("/sitemap.xml", defaults={"_format"="xml"}, name="efSitemap")
  55.      */
  56.     public function sitemapAction(): Response
  57.     {
  58.         $urls = [];
  59.         $efPortalHash $this->getParameter('ef_portal_settings');
  60.         $efPortalSettings $this->em->getRepository(PortalSettings::class)->findOneByHash($efPortalHash);
  61.         $staticPages $this->em->getRepository(TemplateType::class)->findBy(['enabledToLink' => true]);
  62.         foreach ($staticPages as $staticPage)
  63.         {
  64.             /** @var TemplateType $staticPage */
  65.             if (in_array($staticPage->getName(), ['rejestracja-sukces']))
  66.             {
  67.                 continue;
  68.             }
  69.             $urls[] = $this->generateUrl('efShowDynamicTemplate', ['dynamicType' => $staticPage->getName()], false);
  70.         }
  71.         $categories $this->em->getRepository(Category::class)->findByPortalSettings($efPortalSettings);
  72.         foreach ($categories as $category)
  73.         {
  74.             /** @var Category $category */
  75.             $urls[] = $this->generateUrl('category_show', ['category' => $category->getCategorySlug()], false);
  76.             foreach ($category->getProductAssociations() as $productAssociation)
  77.             {
  78.                 /** @var ProductAssociation $productAssociation */
  79.                 if ($productAssociation->getProductMainType() !== null)
  80.                 {
  81.                     $urls[] = $this->generateUrl('category_show', [
  82.                         'category'      => $category->getCategorySlug(),
  83.                         'productType'   => $productAssociation->getProductMainType()->getSlug()
  84.                     ], false);
  85.                     if ($category->getParent() !== null)
  86.                     {
  87.                         $urls[] = $this->generateUrl('category_show', [
  88.                             'category'      => $category->getParent()->getCategorySlug(),
  89.                             'productType'   => $productAssociation->getProductMainType()->getSlug()
  90.                         ], false);
  91.                     }
  92.                 }
  93.             }
  94.         }
  95.         $products $this->em->getRepository(ProductAssociation::class)->findAll();
  96.         foreach ($products as $product)
  97.         {
  98.             if ($product->getIsHidden() === false)
  99.             {
  100.                 /** @var ProductAssociation $product */
  101.                 $urls[] = $this->generateUrl('efShowProduct', [
  102.                     'categorySlug'              => $product->getParentCategorySlug(),
  103.                     'categoryChildSlug'         => $product->getCategorySlug(),
  104.                     'productAssociationSlug'    => $product->getSlug()
  105.                 ], false);
  106.             }
  107.         }
  108.         foreach ($urls as $url)
  109.         {
  110.             $httpsUrls[] = str_replace('http://''https://'$url);
  111.         }
  112.         return $this->render('/frontend-eforum/sitemap.xml.twig', ['urls' => $httpsUrls]);
  113.     }
  114.     /**
  115.      * @Route("/feed.xml", defaults={"_format"="xml"}, name="efProductFeed")
  116.      * @Route("/feed-eforum.xml", defaults={"_format"="xml"}, name="efProductEforumFeed")
  117.      */
  118.     public function productFeedAction(ProductFeed $productFeedUtil,Request $request): Response
  119.     {
  120.         $isEforumFeed $request->get('_route') === 'efProductEforumFeed';
  121.         return new Response($productFeedUtil->generateXMLProductFeed($isEforumFeed)->asXML());
  122.     }
  123.     /**
  124.      * @Route("/rejestracja-sukces", name="efRegisterSuccess")
  125.      */
  126.     public function registerSuccessAction(Request $request): Response
  127.     {
  128.         $userEmail $request->getSession()->get('email');
  129.         $eventRegisterEF $request->getSession()->get('eventRegisterEF');
  130.         if (!is_null($eventRegisterEF)) $request->getSession()->set('eventRegisterEF'null);
  131.         $request->getSession()->getFlashBag()->clear();
  132.         return $this->render('frontend-eforum/security/registerSuccess.html.twig', [
  133.             'userEmail' => $userEmail,
  134.             'sentAgain' => $request->query->get('sentAgain'),
  135.             'eventRegisterEF' => $eventRegisterEF
  136.         ]);
  137.     }
  138.     /**
  139.      * @Route("/{dynamicType}", name="efShowDynamicTemplate",
  140.      *     requirements={"dynamicType"="^(?!(logowanie|login_check|logout|rejestracja|reset|wydarzenia|voucher)\/?(\/.+)?$).+$"})
  141.      */
  142.     public function dynamicTypeAction($dynamicType 'strona-glowna'): Response
  143.     {
  144.         $parameters $this->templateData($dynamicType);
  145.         if ($dynamicType !== 'strona-glowna')
  146.         {
  147.             $parameters['breadcrumbs'][] = array(
  148.                 'name' => ucwords(str_replace('-'' '$dynamicType))
  149.             );
  150.         }
  151.         return $this->render('/frontend-eforum/template-base.html.twig'$parameters);
  152.     }
  153.     private function templateData(string $templateType)
  154.     {
  155.         $template $this->em->getRepository(TemplateEntity::class)->findForStaticPage($templateType);
  156.         if ($template === null)
  157.         {
  158.             throw $this->createNotFoundException();
  159.         }
  160.         $modules $this->templateView->getView($template);
  161.         if ($modules === null)
  162.         {
  163.             return new Response('Template for ' $templateType ' is empty');
  164.         }
  165.         $parameters                   $this->templateView->getExtraParameters($template);
  166.         $parameters['modules']        = $modules['all'];
  167.         $parameters['footerModules']  = $modules['footerInjected'];
  168.         $parameters['templateEntity'] = $template;
  169.         return $parameters;
  170.     }
  171. }