src/Controller/DefaultController.php line 121

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Entity\FAQ;
  5. use App\Entity\NewsletterEmail;
  6. use App\Form\ContactType;
  7. use App\Form\NewsletterType;
  8. use App\Repository\ArticleRepository;
  9. use App\Repository\ContactRepository;
  10. use App\Repository\ProductRepository;
  11. use App\Service\Mail\MailService;
  12. use App\Service\Twig\Strings;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class DefaultController extends AbstractController
  21. {
  22.     public function __construct(
  23.         private readonly RequestStack $requestStack,
  24.         private readonly EntityManagerInterface $em,
  25.         private readonly MailService $mailService,
  26.         private readonly ArticleRepository $articleRepository,
  27.         private readonly ContactRepository $contactRepository,
  28.         private readonly TranslatorInterface $translator,
  29.         private readonly ProductRepository $productRepository,
  30.         private readonly Strings $strings
  31.     ){}
  32.     #[Route("/"name"web_homepage")]
  33.     public function index(): Response
  34.     {
  35.         $articles $this->articleRepository->findBy(["isActive" => 1],["published" => "DESC"],3);
  36.         return $this->render("index.html.twig", [
  37.             "articles" => $articles
  38.         ]);
  39.     }
  40.     /**
  41.      * @Route({
  42.      *     "hr": "/hr/aplikacija/",
  43.      *     "en": "/en/application/",
  44.      *     "de": "/de/anwendung/",
  45.      *     "it": "/it/applicazione/",
  46.      *     "sl": "/sl/aplikacija/"
  47.      * }, name="web_app")
  48.      */
  49.     public function app(): Response
  50.     {
  51.         return $this->render("pages/application.html.twig");
  52.     }
  53.     /**
  54.      * @Route({
  55.      *     "hr": "/hr/znacajke/",
  56.      *     "en": "/en/features/",
  57.      *     "de": "/de/anwendung/",
  58.      *     "it": "/it/caratteristiche/",
  59.      *     "sl": "/sl/znacilnosti/"
  60.      * }, name="web_features")
  61.      */
  62.     public function features(): Response
  63.     {
  64.         return $this->render("pages/features.html.twig");
  65.     }
  66.     /**
  67.      * @Route({
  68.      *     "hr": "/hr/paketi/",
  69.      *     "en": "/en/packages/",
  70.      *     "de": "/de/pakete/",
  71.      *     "it": "/it/pacchetti/",
  72.      *     "sl": "/sl/paketi/"
  73.      * }, name="web_packages")
  74.      */
  75.     public function packages(): Response
  76.     {
  77.         if($this->getUser()) {
  78.             return $this->redirectToRoute('user_packages');
  79.         }
  80.         return $this->render("pages/products.html.twig", []);
  81.     }
  82.     /**
  83.      * @Route({
  84.      *     "hr": "/hr/kontakt/",
  85.      *     "en": "/en/contact/",
  86.      *     "de": "/de/kontact/",
  87.      *     "it": "/it/contatto/",
  88.      *     "sl": "/sl/kontakt/"
  89.      * }, name="web_contact")
  90.      */
  91.     public function contactPage(): Response
  92.     {
  93.         $contact = new Contact();
  94.         $form $this->createForm(ContactType::class, $contact);
  95.         $form->handleRequest($this->requestStack->getCurrentRequest());
  96.         if($form->isSubmitted() && $form->isValid()){
  97.             $this->em->persist($contact);
  98.             $this->em->flush();
  99.             $this->mailService->sendContact($contact);
  100.             return $this->redirectToRoute('contact_confirm', ["_locale" => $this->requestStack->getCurrentRequest()->getLocale(), "routeName" => $this->translator->trans("kontakt-potvrda"), "contactId" => $contact->getId()]);
  101.         }
  102.         return $this->render('pages/contact.html.twig',[
  103.             'form' => $form->createView()
  104.         ]);
  105.     }
  106.     public function renderPricing($route): Response
  107.     {
  108.         $products $this->productRepository->findByShowForNonUsers();
  109.         $monthly = [];
  110.         $yearly = [];
  111.         foreach ($products as $product) {
  112.             if($product->getSubscriptionType() == 'monthly') {
  113.                 $monthly[] = $product;
  114.             }
  115.             if($product->getSubscriptionType() == 'yearly') {
  116.                 $yearly[] = $product;
  117.             }
  118.         }
  119.         return $this->render('components/packages/pricing.html.twig',[
  120.             "monthly" => $monthly,
  121.             "yearly" => $yearly,
  122.             "route" => $route
  123.         ]);
  124.     }
  125.     /**
  126.      * @Route({
  127.      *     "hr": "/hr/cesto-postavljana-pitanja/",
  128.      *     "en": "/en/faq/",
  129.      *     "de": "/de/faq/",
  130.      *     "it": "/it/faq/",
  131.      *     "sl": "/sl/faq/"
  132.      * }, name="web_faq")
  133.      */
  134.     public function faq(): Response
  135.     {
  136.         $faqs $this->em->getRepository(FAQ::class)->findBy([],["sequence" => "ASC"]);
  137.         return $this->render("pages/faq.html.twig", [
  138.             "items" => $faqs
  139.         ]);
  140.     }
  141.     /**
  142.      * @throws \Doctrine\ORM\NonUniqueResultException
  143.      */
  144.     #[Route("/newsletter/form"name"newsletter_form")]
  145.     public function form(): RedirectResponse|Response
  146.     {
  147.         $newsletter = new NewsletterEmail();
  148.         $form $this->createForm(NewsletterType::class, $newsletter);
  149.         $form->handleRequest($this->requestStack->getCurrentRequest());
  150.         if($form->isSubmitted() && $form->isValid()){
  151.             $ex $this->em->getRepository(NewsletterEmail::class)->findOneBy(["email" => $newsletter->getEmail()]);
  152.             if(!$ex){
  153.                 $this->em->persist($newsletter);
  154.                 $this->em->flush();
  155.             }
  156.             $this->addFlash("success"$this->strings->getTranslationString("success_newsletter_flash_message"));
  157.             return $this->redirectToRoute("success_page");
  158.         }
  159.         return $this->render("components/index/newsletter.html.twig", [
  160.             "form" => $form->createView()
  161.         ]);
  162.     }
  163.     #[Route("/potvrda"name"success_page")]
  164.     public function successPage(): Response
  165.     {
  166.         return $this->render("pages/success_page.html.twig");
  167.     }
  168.     #[Route(
  169.         path'/{_locale}/{routeName}',
  170.         name'contact_confirm',
  171.         requirements: [
  172.             '_locale' => 'hr|en|de|it|sl',
  173.             'routeName' => 'kontakt-potvrda|contact-confirm|kontakt-bestatigen|contatto-conferma|kontaktno-potrdilo',
  174.         ],
  175.     )]
  176.     public function contactConfirm(): Response
  177.     {
  178.         $contactId $this->requestStack->getCurrentRequest()->get("contactId");
  179.         if(!$contactId){
  180.             return $this->redirectToRoute("web_homepage");
  181.         }
  182.         $contact $this->contactRepository->find($contactId);
  183.         if($contact){
  184.             if($contact->isGtagEventExecuted()){
  185.                 $gtag true;
  186.             }else{
  187.                 $contact->setGtagEventExecuted(1);
  188.                 $this->em->persist($contact);
  189.                 $this->em->flush();
  190.                 $gtag false;
  191.             }
  192.             if(!$contact->isGtagEventExecuted()){
  193.                 $contact->setGtagEventExecuted(1);
  194.                 $this->em->persist($contact);
  195.                 $this->em->flush();
  196.             }
  197.         }else{
  198.             return $this->redirectToRoute("web_homepage");
  199.         }
  200.         return $this->render("pages/thank_you.html.twig", [
  201.             "gtag" => $gtag,
  202.             "contact" => $contact
  203.         ]);
  204.     }
  205. }