src/Flexy/FrontBundle/Themes/IlaveU/Controller/HomeController.php line 35

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