src/Flexy/FrontBundle/Themes/CoWorking/Controller/HomeController.php line 48

  1. <?php
  2. namespace App\Flexy\FrontBundle\Themes\CoWorking\Controller;
  3. use App\Flexy\FrontBundle\Entity\Page;
  4. use App\Flexy\FrontBundle\Entity\PubBanner;
  5. use App\Flexy\FrontBundle\Entity\Newshome;
  6. use App\Flexy\ShopBundle\Entity\Order\Contacts;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use App\Flexy\FrontBundle\Repository\NewshomeRepository;
  9. use App\Flexy\FrontBundle\Repository\CategoryProductFrontRepository;
  10. use App\Flexy\FrontBundle\Repository\MasterSliderRepository;
  11. use App\Flexy\FrontBundle\Repository\PubBannerRepository;
  12. use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
  13. use App\Flexy\ShopBundle\Repository\CategoryProductRepository;
  14. use App\Flexy\FrontBundle\Repository\ProductFrontRepository;
  15. use App\Flexy\FrontBundle\Themes\CoWorking\Form\Customer\ComplaintType;
  16. use App\Flexy\ShopBundle\Entity\Customer\Complaint;
  17. use App\Flexy\ShopBundle\Repository\Order\HomePageRepository ;
  18. use App\Repository\Flexy\ShopBundle\Entity\Customer\PackRepository;
  19. use Doctrine\Persistence\ManagerRegistry;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\Mercure\HubInterface;
  25. use Symfony\Component\Mercure\Update;
  26. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  27. use Doctrine\ORM\EntityManagerInterface;
  28. use Symfony\Component\HttpFoundation\RedirectResponse;
  29. use Symfony\Component\Mailer\MailerInterface;
  30. use Symfony\Component\Mime\Email;
  31. class HomeController extends AbstractController
  32. {
  33.      private $paginator;
  34.      
  35.     public function __construct(PaginatorInterface $paginator)
  36.     {
  37.          
  38.         $this->paginator $paginator;
  39.   
  40.     }
  41.         
  42.     #[Route('/'name'front_home')]
  43.     public function index(
  44.         ProductFrontRepository $productRepository,
  45.         MasterSliderRepository $masterSliderRepository,
  46.         PubBannerRepository $pubBannerRepository,
  47.         CategoryProductFrontRepository $categoryProductFrontRepository,
  48.         PackRepository $packRepository,
  49.           HomePageRepository $homeRepo,
  50.         NewshomeRepository $newshomeRepository
  51.         
  52.         ): Response
  53.     {
  54.         $deals $productRepository->findDeals();
  55.         $contentPageHome $homeRepo->findOneBy(array('id' => 1));
  56.         
  57.         
  58.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/home/index.html.twig', [
  59.             'products' => $productRepository->findBy(["isPublished"=>true],["id"=>"ASC"],12),
  60.             'subscriptionProducts' => $productRepository->findByProductType(["subscription"]),
  61.             'masterSliders'=> $masterSliderRepository->findBy(["isEnabled"=>true]),
  62.             'pubBanners'=> $pubBannerRepository->findBy(["isEnabled"=>true]),
  63.             'deals'=>$deals,
  64.             'newsAnnonce'=>$newshomeRepository->findBy(["type"=>"Annonce"]),
  65.             'reference'=>$newshomeRepository->findBy(["type"=>null]),
  66.             'categoriesProduct'=> $categoryProductFrontRepository->findBy(["parentCategory"=>null]),
  67.             'contentPageHome'=>$contentPageHome
  68.         ]);
  69.     }
  70.        #[Route(' /actualite/{id}'name:'actualite',methods:['POST',"GET"])]
  71.     public function article(Request $reques,Newshome $newshomeNewshomeRepository $newshomeRepository): Response{
  72.         
  73.           
  74.             return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/article.html.twig', [
  75.             'singleArticle'=>$newshomeRepository->findBy(["id"=>$newshome->getId()])
  76.             
  77.         ]);
  78.     }
  79.     
  80.     
  81.        #[Route('/sendEmailFromPageContact'name'sendEmailFromPageContact')]
  82.     public function sendEmailFromPageContact(
  83.          EntityManagerInterface $entityManager,
  84.           Request $request,
  85.           MailerInterface $mailer
  86.          ): Response
  87.     {
  88.        
  89.        
  90.          
  91.         $fullName $request->request->get("fullName");
  92.         $phone $request->request->get("phone");
  93.         $email $request->request->get("email");
  94.         $message $request->request->get("message");
  95.         
  96.         
  97.        
  98.      
  99.         $recipient 'contact@coworklive.ma';
  100.         //$recipient = 'simobelkhdar1996@gmail.com';
  101.         
  102.         $subject 'Coworklive';
  103.         $emailContent $this->renderView('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/email-admin-contact.html.twig',[
  104.             
  105.             'fullName'=>$fullName,
  106.             'phone'=>$phone,
  107.             'email'=>$email,
  108.             'message'=>$message
  109.             
  110.             ]);
  111.             
  112.             $emailContentClient $this->renderView('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/email-client-contact.html.twig',[
  113.             
  114.          
  115.             
  116.             ]);
  117.         $emailAdmin = (new Email())
  118.             ->from('contact@coworklive.ma')
  119.             ->to($recipient)
  120.             ->subject($subject)
  121.             ->html($emailContent);
  122.         // Send the email using the mailer service
  123.         $mailer->send($emailAdmin);
  124.         
  125.         
  126.         
  127.          $emailClient = (new Email())
  128.             ->from('contact@coworklive.ma')
  129.             ->to($email)
  130.             ->subject($subject)
  131.             ->html($emailContentClient);
  132.         // Send the email using the mailer service
  133.         $mailer->send($emailClient);
  134.         
  135.         
  136.      
  137.         $this->addFlash('success''Votre message a bien été envoyé, votre demande sera traitée dans les plus brefs délais.');
  138.         
  139.         $url 'https://coworklive.ma#contactezNous'
  140.         return new RedirectResponse($url);
  141.         
  142.         
  143.     }
  144.          
  145.     #[Route(' /actualites',  name'news',methods:['POST',"GET"]) ]
  146.     
  147.     public function news(Request $requestNewshomeRepository $newshomeRepository): Response
  148.     {   
  149.         //dd($newshomeRepository->findBy(["type"=>"Annonce"]));
  150.         $queryBuilder $newshomeRepository->findBy(["type"=>"Annonce"],["id" => "DESC"]);
  151.         $newshomePaginated $this->paginator->paginate(
  152.             $queryBuilder,
  153.             $request->query->getInt('page'1),
  154.             7
  155.         );
  156.    
  157.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/actualites.html.twig', [
  158.             'newshome'=>$newshomePaginated
  159.            
  160.         ]);
  161.        
  162.     }
  163.     
  164.      #[Route('/sendEmailFromNewLead'name'sendEmailFromNewLead')]
  165.     public function sendEmailFromNewLead(
  166.          EntityManagerInterface $entityManager,
  167.           Request $request
  168.          ): Response
  169.     {
  170.         $contact = new Contacts();
  171.         $nom $request->request->get("nom");
  172.         $email $request->request->get("email");
  173.         $tel $request->request->get("tel");
  174.         $message $request->request->get("message");
  175.         
  176.         $contact->setFullName($nom);
  177.         $contact->setEmail($email);
  178.         $contact->setPhone($tel);
  179.         $contact->setMessage($message);
  180.         $contact->setIsNewLead(true);
  181.         
  182.         $entityManager->persist($contact);
  183.         $entityManager->flush();
  184.          
  185.         $this->addFlash("successOrder","Votre message a bien été envoyé, votre demande sera traitée dans les plus brefs délais.");
  186.         return $this->redirectToRoute('front_home');
  187.         
  188.     }
  189.     
  190.     
  191.     #[Route('/sort-data'name'app_sort_data'methods:['POST',"GET"])]
  192.     public function sortData(Request $requestNewshomeRepository $newshomeRepository): Response
  193.     {
  194.         $sortOrder $request->query->get('sortOrder'1);  // Valeur par défaut: récentes
  195.         $page $request->query->getInt('page'1);
  196.        
  197.         if ($sortOrder == 1) {
  198.             $results =  $newshomeRepository->findAnnonceDesc();
  199.         } else {
  200.             $results =  $newshomeRepository->findAnnonceAsc();
  201.         }
  202.         $newshomePaginated $this->paginator->paginate(
  203.             $results,
  204.             $request->query->getInt('page'1),
  205.             10
  206.         );
  207.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/_sorted_results.html.twig', [
  208.             'news' => $newshomePaginated
  209.         ]);
  210.     }
  211.     #[Route(' /offres',  name'offres',methods:['POST',"GET"]) ]
  212.     
  213.     public function offres(Request $requestNewshomeRepository $newshomeRepository): Response
  214.     {   
  215.         //dd($newshomeRepository->findBy(["type"=>"Annonce"]));
  216.         $queryBuilder $newshomeRepository->findBy(["type"=>"Offre"],["id" => "DESC"]);
  217.         $newshomePaginated $this->paginator->paginate(
  218.             $queryBuilder,
  219.             $request->query->getInt('page'1),
  220.             7
  221.         );
  222.    
  223.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/offres.html.twig', [
  224.             'newshome'=>$newshomePaginated
  225.            
  226.         ]);
  227.        
  228.     }
  229.     #[Route('/reservation-bureaux'name'reservationbureaux')]
  230.     public function reservationBureaux(ProductRepository $productRepositorySessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response
  231.     {
  232.          
  233.         $session->remove('cart_items');
  234.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/reservation-offices.html.twig', [
  235.             'products' => $productRepository->findByParentCategory([1]),
  236.         ]);
  237.     }
  238.   
  239.     #[Route('/reservation-salle-reunion'name'reservationsallereuninon')]
  240.     public function reservationSalleReunion(ProductRepository $productRepositorySessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response
  241.     {
  242.         
  243.          $session->remove('cart_items');
  244.         $products $productRepository->findBy([
  245.             'productType' => 'variable',
  246.             'parentCategory' => 4,
  247.             'isPublished' =>1
  248.         ]);
  249.         
  250.         // Sort products by valueReduction in descending order
  251.                usort($products, function ($a$b) {
  252.             return $b->getValueReduction() <=> $a->getValueReduction();
  253.         });
  254.         
  255.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/meeting-room.html.twig', [
  256.             'products' => $products,
  257.             'subcategories' => $categoryProductFrontRepository->findAll(),
  258.         ]);
  259.     }
  260.     
  261.     #[Route('/freework'name'reservationfreework')]
  262.     public function freework(ProductRepository $productRepository,SessionInterface $session,CategoryProductFrontRepository $categoryProductFrontRepository): Response
  263.     {
  264.          
  265.               
  266.         $session->remove('cart_items');
  267.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/pages/freework.html.twig', [
  268.             'products' => $productRepository->findByParentCategory([5]),
  269.             'subcategories'=> $categoryProductFrontRepository->findAll(),
  270.         ]);
  271.     }
  272.     #[Route('/confirmation-reservation-bureaux'name'confirmation_reservation_bureaux')]
  273.     public function confirmationReservationBureaux(): Response
  274.     {
  275.          
  276.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/reservation/confirmation-reservation-bureaux.html.twig');
  277.     } 
  278.    
  279.    
  280.     
  281.     #[Route('/contact'name'contact')]
  282.     public function contact(ProductRepository $productRepository): Response
  283.     {
  284.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/home/contact.html.twig', [
  285.             'products' => $productRepository->findAll(),
  286.         ]);
  287.     }
  288.     #[Route('/banner-block/{id}'name'pubBannerBlock')]
  289.     public function pubBannerBlock(PubBanner $pubBanner): Response
  290.     {
  291.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/include-pubs/_singlePubBanner.html.twig', [
  292.             'singleBanner' => $pubBanner,
  293.         ]);
  294.     }
  295.     
  296.     #[Route('/mercure-send'name'pubBannerBlock')]
  297.     public function publish(HubInterface $hub): Response
  298.     {
  299.         $update = new Update(
  300.             'https://hello.com/books/1',
  301.             json_encode(
  302.                 [
  303.                     'status' => 'success',
  304.                     'entity'=>'Order',
  305.                     'data'=>[],
  306.                 ]
  307.                 )
  308.         );
  309.         $hub->publish($update);
  310.         return new Response('published!');
  311.     }
  312.     #[Route('/sitemap.xml'name'sitemap'defaults:["_format"=>"xml"])]
  313.     public function sitemap(Request $request,ManagerRegistry $doctrine): Response
  314.     {
  315.         $hostname $request->getSchemeAndHttpHost();
  316.         $urls = [];
  317.             // On ajoute les URLs "statiques"
  318.             $urls[] = ['loc' => $this->generateUrl('front_home')];
  319.             $urls[] = ['loc' => $this->generateUrl('login_register')];
  320.             //$urls[] = ['loc' => $this->generateUrl('app_login')];
  321.             // On ajoute les URLs dynamiques des articles dans le tableau
  322.             foreach ($doctrine->getManager()->getRepository(Page::class)->findAll() as $page) {
  323.                 /*
  324.                 $images = [
  325.                     'loc' => '/uploads/images/featured/'.$page->getFeaturedImage(), // URL to image
  326.                     'title' => $page->getName()    // Optional, text describing the image
  327.                 ];
  328.                 */
  329.                 $urls[] = [
  330.                     'loc' => $this->generateUrl('single_page', [
  331.                         'slug' => $page->getSlug(),
  332.                     ]),
  333.                     //'lastmod' => $page->getUpdatedAt()->format('Y-m-d'),
  334.                     //'image' => $images
  335.                 ];
  336.             }
  337.             // Fabrication de la réponse XML
  338.             $response = new Response(
  339.                 $this->renderView('@Flexy/FrontBundle/Themes/'.$this->container->get('twig')->getGlobals()["settings"]->get()->getAssetFolderName().'/templates/home/sitemap.html.twig', [
  340.                     'urls' => $urls,
  341.                     'hostname' => $hostname
  342.                 ]),
  343.                 200
  344.             );
  345.             // Ajout des entêtes
  346.             $response->headers->set('Content-Type''text/xml');
  347.             // On envoie la réponse
  348.             return $response;
  349.        
  350.     }
  351.     #[Route('/new-complaint'name'newComplaint')]
  352.     public function newComplaint(Request $request): Response
  353.     {
  354.         $complaint = new Complaint();
  355.         $form $this->createForm(ComplaintType::class,$complaint);
  356.         $form->handleRequest($request);
  357.         if ($form->isSubmitted() && $form->isValid()) {
  358.             
  359.             $this->addFlash("success","Votre réclamation a été transmise au service concerné");
  360.             return $this->redirectToRoute('front_home');
  361.         }
  362.         return $this->render('@Flexy/FrontBundle/Themes/CoWorking/templates/complaint/new.html.twig', [
  363.             'form' => $form->createView(),
  364.         ]);
  365.     }
  366. }