src/Flexy/FrontBundle/Themes/Lasalle/Controller/Front/HomeController.php line 27

  1. <?php
  2. namespace App\Flexy\FrontBundle\Themes\Lasalle\Controller\Front;
  3. use App\Flexy\FrontBundle\Entity\Page;
  4. use App\Flexy\FrontBundle\Entity\PubBanner;
  5. use App\Flexy\FrontBundle\Repository\CategoryProductFrontRepository;
  6. use App\Flexy\FrontBundle\Repository\MasterSliderRepository;
  7. use App\Flexy\FrontBundle\Repository\PubBannerRepository;
  8. use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
  9. use App\Flexy\FrontBundle\Repository\ProductFrontRepository;
  10. use App\Flexy\FrontBundle\Themes\Lasalle\Form\Customer\ComplaintType;
  11. use App\Flexy\ShopBundle\Entity\Customer\Complaint;
  12. use App\Repository\Flexy\ShopBundle\Entity\Customer\PackRepository;
  13. use Doctrine\Persistence\ManagerRegistry;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\Mercure\HubInterface;
  19. use Symfony\Component\Mercure\Update;
  20. class HomeController extends AbstractController
  21. {
  22.     #[Route('/'name'front_home')]
  23.     public function index(
  24.         ProductFrontRepository $productRepository,
  25.         MasterSliderRepository $masterSliderRepository,
  26.         PubBannerRepository $pubBannerRepository,
  27.         CategoryProductFrontRepository $categoryProductFrontRepository,
  28.         PackRepository $packRepository
  29.         
  30.         ): Response
  31.     {
  32.         return $this->redirectToRoute("admin");
  33.         $deals $productRepository->findDeals();
  34.         
  35.         
  36.         return $this->render('@Flexy/FrontBundle/Themes/Lasalle/templates/front/home/index.html.twig', [
  37.             'products' => $productRepository->findBy(["isPublished"=>true],["id"=>"ASC"],12),
  38.             'subscriptionProducts' => $productRepository->findByProductType(["subscription"]),
  39.             'masterSliders'=> $masterSliderRepository->findBy(["isEnabled"=>true]),
  40.             'pubBanners'=> $pubBannerRepository->findBy(["isEnabled"=>true]),
  41.             'deals'=>$deals,
  42.             'categoriesProduct'=> $categoryProductFrontRepository->findBy(["parentCategory"=>null])
  43.         ]);
  44.     }
  45.     #[Route('/contact'name'contact')]
  46.     public function contact(ProductRepository $productRepository): Response
  47.     {
  48.         return $this->render('@Flexy/FrontBundle/Themes/Lasalle/templates/front/home/contact.html.twig', [
  49.             'products' => $productRepository->findAll(),
  50.         ]);
  51.     }
  52.     #[Route('/banner-block/{id}'name'pubBannerBlock')]
  53.     public function pubBannerBlock(PubBanner $pubBanner): Response
  54.     {
  55.         return $this->render('@Flexy/FrontBundle/Themes/Lasalle/templates/front/include-pubs/_singlePubBanner.html.twig', [
  56.             'singleBanner' => $pubBanner,
  57.         ]);
  58.     }
  59.     
  60.     #[Route('/mercure-send'name'pubBannerBlock')]
  61.     public function publish(HubInterface $hub): Response
  62.     {
  63.         $update = new Update(
  64.             'https://hello.com/books/1',
  65.             json_encode(
  66.                 [
  67.                     'status' => 'success',
  68.                     'entity'=>'Order',
  69.                     'data'=>[],
  70.                 ]
  71.                 )
  72.         );
  73.         $hub->publish($update);
  74.         return new Response('published!');
  75.     }
  76.     #[Route('/sitemap.xml'name'sitemap'defaults:["_format"=>"xml"])]
  77.     public function sitemap(Request $request,ManagerRegistry $doctrine): Response
  78.     {
  79.         $hostname $request->getSchemeAndHttpHost();
  80.         $urls = [];
  81.             // On ajoute les URLs "statiques"
  82.             $urls[] = ['loc' => $this->generateUrl('front_home')];
  83.             $urls[] = ['loc' => $this->generateUrl('login_register')];
  84.             //$urls[] = ['loc' => $this->generateUrl('app_login')];
  85.             // On ajoute les URLs dynamiques des articles dans le tableau
  86.             foreach ($doctrine->getManager()->getRepository(Page::class)->findAll() as $page) {
  87.                 /*
  88.                 $images = [
  89.                     'loc' => '/uploads/images/featured/'.$page->getFeaturedImage(), // URL to image
  90.                     'title' => $page->getName()    // Optional, text describing the image
  91.                 ];
  92.                 */
  93.                 $urls[] = [
  94.                     'loc' => $this->generateUrl('single_page', [
  95.                         'slug' => $page->getSlug(),
  96.                     ]),
  97.                     //'lastmod' => $page->getUpdatedAt()->format('Y-m-d'),
  98.                     //'image' => $images
  99.                 ];
  100.             }
  101.             // Fabrication de la réponse XML
  102.             $response = new Response(
  103.                 $this->renderView('@Flexy/FrontBundle/Themes/'.$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName().'/templates/home/sitemap.html.twig', [
  104.                     'urls' => $urls,
  105.                     'hostname' => $hostname
  106.                 ]),
  107.                 200
  108.             );
  109.             // Ajout des entêtes
  110.             $response->headers->set('Content-Type''text/xml');
  111.             // On envoie la réponse
  112.             return $response;
  113.        
  114.     }
  115.     #[Route('/new-complaint'name'newComplaint')]
  116.     public function newComplaint(Request $request): Response
  117.     {
  118.         $complaint = new Complaint();
  119.         $form $this->createForm(ComplaintType::class,$complaint);
  120.         $form->handleRequest($request);
  121.         if ($form->isSubmitted() && $form->isValid()) {
  122.             
  123.             $this->addFlash("success","Votre réclamation a été transmise au service concerné");
  124.             return $this->redirectToRoute('front_home');
  125.         }
  126.         return $this->render('@Flexy/FrontBundle/Themes/Lasalle/templates/front/complaint/new.html.twig', [
  127.             'form' => $form->createView(),
  128.         ]);
  129.     }
  130. }