src/Flexy/FrontBundle/Themes/IlaveU/Controller/HomeController.php line 35
<?php
namespace App\Flexy\FrontBundle\Themes\IlaveU\Controller;
use App\Flexy\FrontBundle\Entity\Page;
use App\Flexy\FrontBundle\Entity\PubBanner;
use App\Flexy\FrontBundle\Repository\CategoryProductFrontRepository;
use App\Flexy\FrontBundle\Repository\MasterSliderRepository;
use App\Flexy\FrontBundle\Repository\PubBannerRepository;
use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
use App\Flexy\FrontBundle\Repository\ProductFrontRepository;
use App\Flexy\FrontBundle\Themes\IlaveU\Form\Customer\ComplaintType;
use App\Flexy\ShopBundle\Entity\Customer\Complaint;
use App\Repository\Flexy\ShopBundle\Entity\Customer\PackRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
class HomeController extends AbstractController
{
#[Route('/')]
public function indexNoLocale(Request $request): Response
{
return $this->redirectToRoute('front_home', [
'_locale' => $request->getLocale(),
]);
}
#[Route('/{_locale}', name: 'front_home')]
public function index(
ProductFrontRepository $productRepository,
MasterSliderRepository $masterSliderRepository,
PubBannerRepository $pubBannerRepository,
CategoryProductFrontRepository $categoryProductFrontRepository,
PackRepository $packRepository
): Response
{
$deals = $productRepository->findDeals();
return $this->render('@Flexy/FrontBundle/Themes/IlaveU/templates/home/index.html.twig', [
'products' => $productRepository->findBy(["isPublished"=>true],["id"=>"ASC"],12),
'subscriptionProducts' => $productRepository->findByProductType(["subscription"]),
'masterSliders'=> $masterSliderRepository->findBy(["isEnabled"=>true]),
'pubBanners'=> $pubBannerRepository->findBy(["isEnabled"=>true]),
'deals'=>$deals,
'categoriesProduct'=> $categoryProductFrontRepository->findBy(["parentCategory"=>null])
]);
}
#[Route('/contact', name: 'contact')]
public function contact(ProductRepository $productRepository): Response
{
return $this->render('@Flexy/FrontBundle/Themes/IlaveU/templates/home/contact.html.twig', [
'products' => $productRepository->findAll(),
]);
}
#[Route('/banner-block/{id}', name: 'pubBannerBlock')]
public function pubBannerBlock(PubBanner $pubBanner): Response
{
return $this->render('@Flexy/FrontBundle/Themes/IlaveU/templates/include-pubs/_singlePubBanner.html.twig', [
'singleBanner' => $pubBanner,
]);
}
#[Route('/mercure-send', name: 'pubBannerBlock')]
public function publish(HubInterface $hub): Response
{
$update = new Update(
'https://hello.com/books/1',
json_encode(
[
'status' => 'success',
'entity'=>'Order',
'data'=>[],
]
)
);
$hub->publish($update);
return new Response('published!');
}
#[Route('/sitemap.xml', name: 'sitemap', defaults:["_format"=>"xml"])]
public function sitemap(Request $request,ManagerRegistry $doctrine): Response
{
$hostname = $request->getSchemeAndHttpHost();
$urls = [];
// On ajoute les URLs "statiques"
$urls[] = ['loc' => $this->generateUrl('front_home')];
$urls[] = ['loc' => $this->generateUrl('login_register')];
//$urls[] = ['loc' => $this->generateUrl('app_login')];
// On ajoute les URLs dynamiques des articles dans le tableau
foreach ($doctrine->getManager()->getRepository(Page::class)->findAll() as $page) {
/*
$images = [
'loc' => '/uploads/images/featured/'.$page->getFeaturedImage(), // URL to image
'title' => $page->getName() // Optional, text describing the image
];
*/
$urls[] = [
'loc' => $this->generateUrl('single_page', [
'slug' => $page->getSlug(),
]),
//'lastmod' => $page->getUpdatedAt()->format('Y-m-d'),
//'image' => $images
];
}
// Fabrication de la réponse XML
$response = new Response(
$this->renderView('@Flexy/FrontBundle/Themes/'.$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName().'/templates/home/sitemap.html.twig', [
'urls' => $urls,
'hostname' => $hostname
]),
200
);
// Ajout des entêtes
$response->headers->set('Content-Type', 'text/xml');
// On envoie la réponse
return $response;
}
#[Route('/new-complaint', name: 'newComplaint')]
public function newComplaint(Request $request): Response
{
$complaint = new Complaint();
$form = $this->createForm(ComplaintType::class,$complaint);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->addFlash("success","Votre réclamation a été transmise au service concerné");
return $this->redirectToRoute('front_home');
}
return $this->render('@Flexy/FrontBundle/Themes/IlaveU/templates/complaint/new.html.twig', [
'form' => $form->createView(),
]);
}
}