src/Controller/web/DefaultController.php line 158

Open in your IDE?
  1. <?php
  2. namespace App\Controller\web;
  3. use App\Entity\Contact;
  4. use App\Entity\Product;
  5. use App\Entity\WeddingCalculator;
  6. use App\Form\web\ContactType;
  7. use App\Form\web\WeddingCalculatorType2;
  8. use App\Repository\ArticleRepository;
  9. use App\Repository\CategoryRepository;
  10. use App\Repository\InfoTableRepository;
  11. use App\Repository\PhotoAlbumRepository;
  12. use App\Repository\ProductRepository;
  13. use App\Repository\VideoRepository;
  14. use App\Service\AdminUtils;
  15. use App\Service\MailingService;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Knp\Component\Pager\PaginatorInterface;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\RequestStack;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class DefaultController extends AbstractController
  23. {
  24.     private $categoryRepo;
  25.     private $productRepo;
  26.     private $infoRepo;
  27.     private $requestStack;
  28.     private $mailer;
  29.     private $mailing;
  30.     private $em;
  31.     private $articleRepo;
  32.     private $paginator;
  33.     private $photoAlbumRepo;
  34.     private $adminUtils;
  35.     private $videoRepo;
  36.     public function __construct(
  37.         CategoryRepository $categoryRepository,
  38.         ProductRepository $productRepository,
  39.         InfoTableRepository $infoRepo,
  40.         RequestStack $requestStack,
  41.         \Swift_Mailer $mailer,
  42.         MailingService $mailing,
  43.         EntityManagerInterface $em,
  44.         ArticleRepository $articleRepository,
  45.         PaginatorInterface $paginator,
  46.         PhotoAlbumRepository $photoAlbumRepository,
  47.         AdminUtils $adminUtils,
  48.         VideoRepository $videoRepository
  49.     )
  50.     {
  51.         $this->infoRepo $infoRepo;
  52.         $this->categoryRepo $categoryRepository;
  53.         $this->productRepo $productRepository;
  54.         $this->requestStack $requestStack;
  55.         $this->mailer $mailer;
  56.         $this->mailing $mailing;
  57.         $this->em $em;
  58.         $this->articleRepo $articleRepository;
  59.         $this->paginator $paginator;
  60.         $this->photoAlbumRepo $photoAlbumRepository;
  61.         $this->adminUtils $adminUtils;
  62.         $this->videoRepo $videoRepository;
  63.     }
  64.     /**
  65.      * @Route("/", name="web_home")
  66.      * @return \Symfony\Component\HttpFoundation\Response
  67.      */
  68.     public function indexPage(){
  69.         return $this->render('web/index.html.twig', [
  70.             "category" => $this->categoryRepo->findBy(["isActive" => true]),
  71.             "promoted" => $this->productRepo->findBy(["isActive" => true"promoted" => true]),
  72.             "latestVideos" => $this->videoRepo->findBy(["isActive" => true], ["createdAt" => "DESC"], 3),
  73.         ]);
  74.     }
  75.     /**
  76.      * @Route("/info/{slug}", name="web_info")
  77.      * @return \Symfony\Component\HttpFoundation\Response
  78.      */
  79.     public function infoPage($slug){
  80.         $info $this->infoRepo->findOneBy(["slug" => $slug"isActive" => true]);
  81.         if(!$info) {
  82.             return $this->redirectToRoute("web_home");
  83.         }
  84.         return $this->render('web/info.html.twig', [
  85.             "info" => $info
  86.         ]);
  87.     }
  88.     /**
  89.      * @Route("/proizvodi", name="web_products")
  90.      * @return \Symfony\Component\HttpFoundation\Response
  91.      */
  92.     public function productsPage(){
  93.         return $this->render('web/products.html.twig', [
  94.             "category" => $this->categoryRepo->findBy(["isActive" => true]),
  95.         ]);
  96.     }
  97.     /**
  98.      * @Route("/proizvod/{slug}/{id}", name="web_product_single")
  99.      * @return \Symfony\Component\HttpFoundation\Response
  100.      */
  101.     public function productSinglePage($slugProduct $id){
  102.         $categoryProducts $this->productRepo->findBy(["category" => $id->getCategory(), "isActive" => 1]);
  103.         if(!$id->getIsActive()){
  104.             return $this->redirectToRoute("web_home");
  105.         }
  106.         return $this->render('web/product-details.html.twig', [
  107.             "product" => $id,
  108.             "related" => $categoryProducts
  109.         ]);
  110.     }
  111.     /**
  112.      * @Route("/usluge", name="web_services")
  113.      * @return \Symfony\Component\HttpFoundation\Response
  114.      */
  115.     public function servicesPage(){
  116.         return $this->render('web/services.html.twig');
  117.     }
  118.     /**
  119.      * @Route("/novosti", name="web_blog")
  120.      * @return \Symfony\Component\HttpFoundation\Response
  121.      */
  122.     public function blogPage(Request $request){
  123.         $qb $this->articleRepo->findActiveQueryBuilder();
  124.         $pagination $this->paginator->paginate(
  125.             $qb,
  126.             $request->query->getInt('page'1),
  127.             6
  128.         );
  129.         return $this->render('web/blog.html.twig', [
  130.             'articles' => $pagination,
  131.         ]);
  132.     }
  133.     /**
  134.      * @Route("/novosti/{slug}", name="web_article")
  135.      * @return \Symfony\Component\HttpFoundation\Response
  136.      */
  137.     public function articlePage(string $slug){
  138.         $article $this->articleRepo->findBySlug($slug);
  139.         if (!$article) {
  140.             return $this->redirectToRoute('web_blog');
  141.         }
  142.         return $this->render('web/blog-detail.html.twig', [
  143.             'article' => $article,
  144.         ]);
  145.     }
  146.     /**
  147.      * @Route("/videoteka", name="web_videos")
  148.      */
  149.     public function videosPage()
  150.     {
  151.         $videos $this->videoRepo->findBy(['isActive' => true], ['sortOrder' => 'ASC''createdAt' => 'DESC']);
  152.         return $this->render('web/videos.html.twig', [
  153.             'videos' => $videos,
  154.         ]);
  155.     }
  156.     /**
  157.      * @Route("/pitaj-sladanu", name="web_chatbot_page")
  158.      */
  159.     public function chatbotPage()
  160.     {
  161.         return $this->render('web/chatbot-page.html.twig');
  162.     }
  163.     /**
  164.      * @Route("/galerija", name="web_gallery")
  165.      */
  166.     public function galleryPage()
  167.     {
  168.         $albums $this->photoAlbumRepo->findBy(['isActive' => true], ['sortOrder' => 'ASC''createdAt' => 'DESC']);
  169.         return $this->render('web/gallery.html.twig', [
  170.             'albums' => $albums,
  171.         ]);
  172.     }
  173.     /**
  174.      * @Route("/galerija/{slug}", name="web_gallery_album")
  175.      */
  176.     public function galleryAlbumPage(string $slug)
  177.     {
  178.         $album $this->photoAlbumRepo->findOneBy(['slug' => $slug'isActive' => true]);
  179.         if (!$album) {
  180.             return $this->redirectToRoute('web_gallery');
  181.         }
  182.         return $this->render('web/gallery-detail.html.twig', [
  183.             'album' => $album,
  184.         ]);
  185.     }
  186.     /**
  187.      * @Route("/kontakt", name="web_contact")
  188.      * @return \Symfony\Component\HttpFoundation\Response
  189.      */
  190.     public function contactPage(){
  191.         $contact = new Contact();
  192.         $form $this->createForm(ContactType::class, $contact);
  193.         $request $this->requestStack->getCurrentRequest();
  194.         $form->handleRequest($request);
  195.         if($form->isSubmitted() && $form->isValid() && $this->mailing->verifyRecaptcha($request->get('g-recaptcha-response'))){
  196.             $contact->setType('contact');
  197.             $uploadedFiles $request->files->get('contact_photos', []);
  198.             if ($uploadedFiles) {
  199.                 $paths $this->adminUtils->handleInquiryPhotos(is_array($uploadedFiles) ? $uploadedFiles : [$uploadedFiles]);
  200.                 if ($paths) {
  201.                     $contact->setPhotos($paths);
  202.                 }
  203.             }
  204.             $this->em->persist($contact);
  205.             $this->em->flush();
  206.             $this->mailing->sendContact($contact);
  207.             $this->addFlash('success''Vaša poruka je poslana!');
  208.             return $this->redirectToRoute('web_contact');
  209.         }elseif($form->isSubmitted() &&  $form->isValid() && !$this->mailing->verifyRecaptcha($request->get('g-recaptcha-response'))){
  210.             $this->addFlash(
  211.                 'error_rec',
  212.                 'Potvrdite da niste robot!'
  213.             );
  214.         }
  215.         return $this->render('web/contact.html.twig', [
  216.             'form' => $form->createView()
  217.         ]);
  218.     }
  219.     /**
  220.      * @Route("/svadbeni-kalkulator", name="web_calculator")
  221.      * @return \Symfony\Component\HttpFoundation\Response
  222.      */
  223.     public function calculatorPage2(){
  224.         $weddingCalculator = new WeddingCalculator();
  225.         $form $this->createForm(WeddingCalculatorType2::class, $weddingCalculator);
  226.         $form->handleRequest($this->requestStack->getCurrentRequest());
  227.         if($form->isSubmitted() && $form->isValid() && $this->mailing->verifyRecaptcha($this->requestStack->getCurrentRequest()->get('g-recaptcha-response'))){
  228.             $weddingCalculator->setAdditionalCake(null);
  229.             if($form->get('eventDate')->getData()){
  230.                 $eventTime strtotime($form->get('eventDate')->getData());
  231.                 $eventDate date('Y-m-d H:i:s',$eventTime);
  232.                 $weddingCalculator->setEventDate(new \DateTime($eventDate));
  233.             }
  234.             $this->em->persist($weddingCalculator);
  235.             $this->em->flush();
  236.             $this->mailing->sendCalculator($weddingCalculator);
  237.             $this->addFlash('success''Vaša zahtjev je poslan!');
  238.             return $this->redirectToRoute('web_calculator');
  239.         }elseif($form->isSubmitted() &&  $form->isValid() && !$this->mailing->verifyRecaptcha($this->requestStack->getCurrentRequest()->get('g-recaptcha-response'))){
  240.             $this->addFlash(
  241.                 'error_rec',
  242.                 'Potvrdite da niste robot!'
  243.             );
  244.         }
  245.         return $this->render('web/calculator-2.html.twig', [
  246.             'form' => $form->createView()
  247.         ]);
  248.     }
  249. }