src/Flexy/FrontBundle/Themes/CoWorking/Controller/HomeController.php line 258
<?phpnamespace App\Flexy\FrontBundle\Themes\CoWorking\Controller;use App\Flexy\FrontBundle\Entity\Page;use App\Flexy\FrontBundle\Entity\PubBanner;use App\Flexy\FrontBundle\Entity\Newshome;use App\Flexy\ShopBundle\Entity\Order\Contacts;use Knp\Component\Pager\PaginatorInterface;use App\Flexy\FrontBundle\Repository\NewshomeRepository;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\ShopBundle\Repository\CategoryProductRepository;use App\Flexy\FrontBundle\Repository\ProductFrontRepository;use App\Flexy\FrontBundle\Themes\CoWorking\Form\Customer\ComplaintType;use App\Flexy\ShopBundle\Entity\Customer\Complaint;use App\Flexy\ShopBundle\Repository\Order\HomePageRepository ;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;use Symfony\Component\HttpFoundation\Session\SessionInterface;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\Mime\Email;class HomeController extends AbstractController{private $paginator;public function __construct(PaginatorInterface $paginator){$this->paginator = $paginator;}#[Route('/', name: 'front_home')]public function index(ProductFrontRepository $productRepository,MasterSliderRepository $masterSliderRepository,PubBannerRepository $pubBannerRepository,CategoryProductFrontRepository $categoryProductFrontRepository,PackRepository $packRepository,HomePageRepository $homeRepo,NewshomeRepository $newshomeRepository): Response{$deals = $productRepository->findDeals();$contentPageHome = $homeRepo->findOneBy(array('id' => 1));return $this->render('@Flexy/FrontBundle/Themes/CoWorking/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,'newsAnnonce'=>$newshomeRepository->findBy(["type"=>"Annonce"]),'reference'=>$newshomeRepository->findBy(["type"=>null]),'categoriesProduct'=> $categoryProductFrontRepository->findBy(["parentCategory"=>null]),'contentPageHome'=>$contentPageHome]);}#[Route(' /actualite/{id}', name:'actualite',methods:['POST',"GET"])]public function article(Request $reques,Newshome $newshome, NewshomeRepository $newshomeRepository): Response{return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/article.html.twig', ['singleArticle'=>$newshomeRepository->findBy(["id"=>$newshome->getId()])]);}#[Route('/sendEmailFromPageContact', name: 'sendEmailFromPageContact')]public function sendEmailFromPageContact(EntityManagerInterface $entityManager,Request $request,MailerInterface $mailer): Response{$fullName = $request->request->get("fullName");$phone = $request->request->get("phone");$email = $request->request->get("email");$message = $request->request->get("message");$recipient = 'contact@coworklive.ma';//$recipient = 'simobelkhdar1996@gmail.com';$subject = 'Coworklive';$emailContent = $this->renderView('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/email-admin-contact.html.twig',['fullName'=>$fullName,'phone'=>$phone,'email'=>$email,'message'=>$message]);$emailContentClient = $this->renderView('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/email-client-contact.html.twig',[]);$emailAdmin = (new Email())->from('contact@coworklive.ma')->to($recipient)->subject($subject)->html($emailContent);// Send the email using the mailer service$mailer->send($emailAdmin);$emailClient = (new Email())->from('contact@coworklive.ma')->to($email)->subject($subject)->html($emailContentClient);// Send the email using the mailer service$mailer->send($emailClient);$this->addFlash('success', 'Votre message a bien été envoyé, votre demande sera traitée dans les plus brefs délais.');$url = 'https://coworklive.ma#contactezNous';return new RedirectResponse($url);}#[Route(' /actualites', name: 'news',methods:['POST',"GET"]) ]public function news(Request $request, NewshomeRepository $newshomeRepository): Response{//dd($newshomeRepository->findBy(["type"=>"Annonce"]));$queryBuilder = $newshomeRepository->findBy(["type"=>"Annonce"],["id" => "DESC"]);$newshomePaginated = $this->paginator->paginate($queryBuilder,$request->query->getInt('page', 1),7);return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/actualites.html.twig', ['newshome'=>$newshomePaginated]);}#[Route('/sendEmailFromNewLead', name: 'sendEmailFromNewLead')]public function sendEmailFromNewLead(EntityManagerInterface $entityManager,Request $request): Response{$contact = new Contacts();$nom = $request->request->get("nom");$email = $request->request->get("email");$tel = $request->request->get("tel");$message = $request->request->get("message");$contact->setFullName($nom);$contact->setEmail($email);$contact->setPhone($tel);$contact->setMessage($message);$contact->setIsNewLead(true);$entityManager->persist($contact);$entityManager->flush();$this->addFlash("successOrder","Votre message a bien été envoyé, votre demande sera traitée dans les plus brefs délais.");return $this->redirectToRoute('front_home');}#[Route('/sort-data', name: 'app_sort_data', methods:['POST',"GET"])]public function sortData(Request $request, NewshomeRepository $newshomeRepository): Response{$sortOrder = $request->query->get('sortOrder', 1); // Valeur par défaut: récentes$page = $request->query->getInt('page', 1);if ($sortOrder == 1) {$results = $newshomeRepository->findAnnonceDesc();} else {$results = $newshomeRepository->findAnnonceAsc();}$newshomePaginated = $this->paginator->paginate($results,$request->query->getInt('page', 1),10);return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/_sorted_results.html.twig', ['news' => $newshomePaginated]);}#[Route(' /offres', name: 'offres',methods:['POST',"GET"]) ]public function offres(Request $request, NewshomeRepository $newshomeRepository): Response{//dd($newshomeRepository->findBy(["type"=>"Annonce"]));$queryBuilder = $newshomeRepository->findBy(["type"=>"Offre"],["id" => "DESC"]);$newshomePaginated = $this->paginator->paginate($queryBuilder,$request->query->getInt('page', 1),7);return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/offres.html.twig', ['newshome'=>$newshomePaginated]);}#[Route('/reservation-bureaux', name: 'reservationbureaux')]public function reservationBureaux(ProductRepository $productRepository, SessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response{$session->remove('cart_items');return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/reservation-offices.html.twig', ['products' => $productRepository->findByParentCategory([1]),]);}#[Route('/reservation-salle-reunion', name: 'reservationsallereuninon')]public function reservationSalleReunion(ProductRepository $productRepository, SessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response{$session->remove('cart_items');$products = $productRepository->findBy(['productType' => 'variable','parentCategory' => 4,'isPublished' =>1]);// Sort products by valueReduction in descending orderusort($products, function ($a, $b) {return $b->getValueReduction() <=> $a->getValueReduction();});return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/meeting-room.html.twig', ['products' => $products,'subcategories' => $categoryProductFrontRepository->findAll(),]);}#[Route('/freework', name: 'reservationfreework')]public function freework(ProductRepository $productRepository,SessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response{$session->remove('cart_items');return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/freework.html.twig', ['products' => $productRepository->findByParentCategory([5]),'subcategories'=> $categoryProductFrontRepository->findAll(),]);}#[Route('/confirmation-reservation-bureaux', name: 'confirmation_reservation_bureaux')]public function confirmationReservationBureaux(): Response{return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/reservation/confirmation-reservation-bureaux.html.twig');}#[Route('/contact', name: 'contact')]public function contact(ProductRepository $productRepository): Response{return $this->render('@Flexy/FrontBundle/Themes/CoWorking/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/CoWorking/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 tableauforeach ($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éponsereturn $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/CoWorking/templates/complaint/new.html.twig', ['form' => $form->createView(),]);}}