src/Controller/DefaultController.php line 38
<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Entity\FAQ;
use App\Entity\NewsletterEmail;
use App\Form\ContactType;
use App\Form\NewsletterType;
use App\Repository\ArticleRepository;
use App\Repository\ContactRepository;
use App\Repository\ProductRepository;
use App\Service\Mail\MailService;
use App\Service\Twig\Strings;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class DefaultController extends AbstractController
{
public function __construct(
private readonly RequestStack $requestStack,
private readonly EntityManagerInterface $em,
private readonly MailService $mailService,
private readonly ArticleRepository $articleRepository,
private readonly ContactRepository $contactRepository,
private readonly TranslatorInterface $translator,
private readonly ProductRepository $productRepository,
private readonly Strings $strings
){}
#[Route("/", name: "web_homepage")]
public function index(): Response
{
$articles = $this->articleRepository->findBy(["isActive" => 1],["published" => "DESC"],3);
return $this->render("index.html.twig", [
"articles" => $articles
]);
}
/**
* @Route({
* "hr": "/hr/aplikacija/",
* "en": "/en/application/",
* "de": "/de/anwendung/",
* "it": "/it/applicazione/",
* "sl": "/sl/aplikacija/"
* }, name="web_app")
*/
public function app(): Response
{
return $this->render("pages/application.html.twig");
}
/**
* @Route({
* "hr": "/hr/znacajke/",
* "en": "/en/features/",
* "de": "/de/anwendung/",
* "it": "/it/caratteristiche/",
* "sl": "/sl/znacilnosti/"
* }, name="web_features")
*/
public function features(): Response
{
return $this->render("pages/features.html.twig");
}
/**
* @Route({
* "hr": "/hr/paketi/",
* "en": "/en/packages/",
* "de": "/de/pakete/",
* "it": "/it/pacchetti/",
* "sl": "/sl/paketi/"
* }, name="web_packages")
*/
public function packages(): Response
{
if($this->getUser()) {
return $this->redirectToRoute('user_packages');
}
return $this->render("pages/products.html.twig", []);
}
/**
* @Route({
* "hr": "/hr/kontakt/",
* "en": "/en/contact/",
* "de": "/de/kontact/",
* "it": "/it/contatto/",
* "sl": "/sl/kontakt/"
* }, name="web_contact")
*/
public function contactPage(): Response
{
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($this->requestStack->getCurrentRequest());
if($form->isSubmitted() && $form->isValid()){
$this->em->persist($contact);
$this->em->flush();
$this->mailService->sendContact($contact);
return $this->redirectToRoute('contact_confirm', ["_locale" => $this->requestStack->getCurrentRequest()->getLocale(), "routeName" => $this->translator->trans("kontakt-potvrda"), "contactId" => $contact->getId()]);
}
return $this->render('pages/contact.html.twig',[
'form' => $form->createView()
]);
}
public function renderPricing($route): Response
{
$products = $this->productRepository->findByShowForNonUsers();
$monthly = [];
$yearly = [];
foreach ($products as $product) {
if($product->getSubscriptionType() == 'monthly') {
$monthly[] = $product;
}
if($product->getSubscriptionType() == 'yearly') {
$yearly[] = $product;
}
}
return $this->render('components/packages/pricing.html.twig',[
"monthly" => $monthly,
"yearly" => $yearly,
"route" => $route
]);
}
/**
* @Route({
* "hr": "/hr/cesto-postavljana-pitanja/",
* "en": "/en/faq/",
* "de": "/de/faq/",
* "it": "/it/faq/",
* "sl": "/sl/faq/"
* }, name="web_faq")
*/
public function faq(): Response
{
$faqs = $this->em->getRepository(FAQ::class)->findBy([],["sequence" => "ASC"]);
return $this->render("pages/faq.html.twig", [
"items" => $faqs
]);
}
/**
* @throws \Doctrine\ORM\NonUniqueResultException
*/
#[Route("/newsletter/form", name: "newsletter_form")]
public function form(): RedirectResponse|Response
{
$newsletter = new NewsletterEmail();
$form = $this->createForm(NewsletterType::class, $newsletter);
$form->handleRequest($this->requestStack->getCurrentRequest());
if($form->isSubmitted() && $form->isValid()){
$ex = $this->em->getRepository(NewsletterEmail::class)->findOneBy(["email" => $newsletter->getEmail()]);
if(!$ex){
$this->em->persist($newsletter);
$this->em->flush();
}
$this->addFlash("success", $this->strings->getTranslationString("success_newsletter_flash_message"));
return $this->redirectToRoute("success_page");
}
return $this->render("components/index/newsletter.html.twig", [
"form" => $form->createView()
]);
}
#[Route("/potvrda", name: "success_page")]
public function successPage(): Response
{
return $this->render("pages/success_page.html.twig");
}
#[Route(
path: '/{_locale}/{routeName}',
name: 'contact_confirm',
requirements: [
'_locale' => 'hr|en|de|it|sl',
'routeName' => 'kontakt-potvrda|contact-confirm|kontakt-bestatigen|contatto-conferma|kontaktno-potrdilo',
],
)]
public function contactConfirm(): Response
{
$contactId = $this->requestStack->getCurrentRequest()->get("contactId");
if(!$contactId){
return $this->redirectToRoute("web_homepage");
}
$contact = $this->contactRepository->find($contactId);
if($contact){
if($contact->isGtagEventExecuted()){
$gtag = true;
}else{
$contact->setGtagEventExecuted(1);
$this->em->persist($contact);
$this->em->flush();
$gtag = false;
}
if(!$contact->isGtagEventExecuted()){
$contact->setGtagEventExecuted(1);
$this->em->persist($contact);
$this->em->flush();
}
}else{
return $this->redirectToRoute("web_homepage");
}
return $this->render("pages/thank_you.html.twig", [
"gtag" => $gtag,
"contact" => $contact
]);
}
}