src/Controller/FrontController.php line 536

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ActualitePage;
  4. use App\Entity\Application;
  5. use App\Entity\ApplicationParagraph;
  6. use App\Entity\ApplicationProduct;
  7. use App\Entity\ApplicationTranslation;
  8. use App\Entity\Category;
  9. use App\Entity\CategoryTranslation;
  10. use App\Entity\Contact;
  11. use App\Entity\Document;
  12. use App\Entity\DocumentCategory;
  13. use App\Entity\DocumentCategoryTranslation;
  14. use App\Entity\FabricationParagraph;
  15. use App\Entity\JobOffer;
  16. use App\Entity\JobOfferParagraph;
  17. use App\Entity\JobOfferTranslation;
  18. use App\Entity\Member;
  19. use App\Entity\Newsletter;
  20. use App\Entity\Page;
  21. use App\Entity\Paragraph;
  22. use App\Entity\Partner;
  23. use App\Entity\Post;
  24. use App\Entity\PostDocument;
  25. use App\Entity\PostMedia;
  26. use App\Entity\PostTranslation;
  27. use App\Entity\PresentationParagraph;
  28. use App\Entity\Product;
  29. use App\Entity\ProductDocument;
  30. use App\Entity\ProductMedia;
  31. use App\Entity\ProductProductTable;
  32. use App\Entity\ProductTranslation;
  33. use App\Entity\RelatedProduct;
  34. use App\Entity\SubCategory;
  35. use App\Entity\SubCategoryTranslation;
  36. use App\Entity\SubSubCategory;
  37. use App\Entity\SubSubCategoryTranslation;
  38. use App\Entity\SubSubSubCategory;
  39. use App\Entity\SubSubSubCategoryTranslation;
  40. use App\Entity\Testimonial;
  41. use App\Form\ContactType;
  42. use App\Form\NewsletterType;
  43. use App\Form\ProductsFilterType;
  44. use App\Repository\ActualitePageRepository;
  45. use App\Repository\DocumentPageRepository;
  46. use App\Repository\FabricationPageRepository;
  47. use App\Repository\PresentationPageRepository;
  48. use App\Service\AppService;
  49. use Doctrine\Persistence\ManagerRegistry;
  50. use Knp\Component\Pager\PaginatorInterface;
  51. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  52. use Symfony\Bridge\Twig\Mime\BodyRenderer;
  53. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  54. use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkApplication;
  55. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  56. use Symfony\Component\Asset\Packages;
  57. use Symfony\Component\Console\Input\ArrayInput;
  58. use Symfony\Component\Console\Output\NullOutput;
  59. use Symfony\Component\HttpFoundation\Request;
  60. use Symfony\Component\HttpFoundation\Response;
  61. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  62. use Symfony\Component\HttpKernel\KernelInterface;
  63. use Symfony\Component\Mailer\Mailer;
  64. use Symfony\Component\Mailer\MailerInterface;
  65. use Symfony\Component\Mailer\Transport;
  66. use Symfony\Component\Mime\Email;
  67. use Symfony\Component\Routing\Annotation\Route;
  68. use Symfony\Contracts\Translation\TranslatorInterface;
  69. use Twig\Environment;
  70. use Twig\Loader\FilesystemLoader;
  71. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  72. use Symfony\Component\Filesystem\Filesystem;
  73. use Symfony\Component\Filesystem\Path;
  74. /**
  75.  * @Route("/{_locale}", requirements={"_locale": "%managed_locales_routing%"})
  76.  */
  77. class FrontController extends AbstractController
  78. {
  79.     /**
  80.      * @Route("/categorie/{path}", name="front_category", requirements={"path": ".+"})
  81.      */
  82.     public function category(string $path): Response
  83.     {
  84.         $segments array_values(array_filter(explode('/'$path), fn($s) => $s !== '0' && $s !== ''));
  85.         $cleanPath implode('/'$segments);
  86.         if (!$cleanPath) {
  87.             return $this->redirectToRoute('front_products', [], 301);
  88.         }
  89.         return $this->redirect($this->generateUrl('front_catalog', ['path' => $cleanPath]), 301);
  90.     }
  91.     /**
  92.      * @Route("/changer-la-langue/{locale}/{routeName}/{routeParams}", name="front_change_language", requirements={"routeParams"=".+"})
  93.      */
  94.     public function changeLanguage(Request $requestSessionInterface $session$locale$routeName$routeParams null)
  95.     {
  96.         $routeParams array_merge(["_locale" => $locale], $_GET);
  97.         return $this->redirectToRoute($routeName$routeParams);
  98.     }
  99.     /**
  100.      * @Route("/presentation", name="front_presentation")
  101.      */
  102.     public function presentation(ManagerRegistry $managerRegistryRequest $requestPresentationPageRepository $presentationPageRepository)
  103.     {
  104.         $repoPresentationParagraph $managerRegistry->getRepository(PresentationParagraph::class);
  105.         $bandeau $presentationPageRepository->findAll()[0];
  106.         $presentationParagraphs $repoPresentationParagraph->findBy([], ["position" => "asc"]);
  107.         return $this->render('front/presentation.html.twig', array(
  108.             "presentationParagraphs" => $presentationParagraphs,
  109.             'bandeau' => $bandeau
  110.         ));
  111.     }
  112.     /**
  113.      * @Route("/fabrication-sur-mesure", name="front_fabrication")
  114.      */
  115.     public function fabrication(ManagerRegistry $managerRegistryRequest $requestFabricationPageRepository $fabricationPageRepository)
  116.     {
  117.         $repoFabricationParagraph $managerRegistry->getRepository(FabricationParagraph::class);
  118.         $page $fabricationPageRepository->findAll()[0];
  119.         $fabricationParagraphs $repoFabricationParagraph->findBy([], ["position" => "asc"]);
  120.         $repoProduct $managerRegistry->getRepository(Product::class);
  121.         $products $repoProduct->findBy(["isCustom" => true], ["position" => "asc"]);
  122.         return $this->render('front/fabrication.html.twig', array(
  123.             "fabricationParagraphs" => $fabricationParagraphs,
  124.             "products" => $products,
  125.             'bandeau' => $page
  126.         ));
  127.     }
  128.     /**
  129.      * @Route("/produits/{path}", name="front_products_legacy", requirements={"path": ".+"})
  130.      */
  131.     public function productsLegacy(string $path): Response
  132.     {
  133.         $parts explode('/'$path);
  134.         $filtered array_values(array_filter($parts, fn($s) => $s !== '0' && $s !== ''));
  135.         $listView null;
  136.         if (!empty($filtered) && $filtered[count($filtered) - 1] === '1') {
  137.             array_pop($filtered);
  138.             $listView true;
  139.         }
  140.         $cleanPath implode('/'$filtered);
  141.         if (!$cleanPath) {
  142.             return $this->redirectToRoute('front_products', [], 301);
  143.         }
  144.         $url $this->generateUrl('front_catalog', ['path' => $cleanPath]);
  145.         if ($listView) {
  146.             $url .= '?listView=1';
  147.         }
  148.         return $this->redirect($url301);
  149.     }
  150.     /**
  151.      * @Route("/produits", name="front_products")
  152.      */
  153.     public function products(ManagerRegistry $managerRegistryRequest $request): Response
  154.     {
  155.         $data = ["limit" => 12"hideBaseProduct" => false];
  156.         $data["searchProducts"] = ["categories" => [], "subCategories" => [], "subSubCategories" => [], "subSubSubCategories" => []];
  157.         $data["orderBys"] = ["a.position" => "asc"];
  158.         $productsFilterForm $this->createForm(ProductsFilterType::class);
  159.         $productsFilterForm->handleRequest($request);
  160.         if ($productsFilterForm->isSubmitted() && $productsFilterForm->isValid()) {
  161.             $data["searchProducts"]["offset"] = $productsFilterForm["offset"]->getData();
  162.         }
  163.         $repoProduct $managerRegistry->getRepository(Product::class);
  164.         $products $repoProduct->search($data);
  165.         $products = (is_array($products) ? $products : ($products ? [$products] : []));
  166.         return $this->render('front/products.html.twig', [
  167.             "catalogPath" => null,
  168.             "listView" => $request->query->get('listView'),
  169.             'productsFilterForm' => $productsFilterForm->createView(),
  170.             "products" => $products,
  171.             "categoryActive" => null,
  172.             "subCategoryActive" => null,
  173.             "subSubCategoryActive" => null,
  174.             "subSubSubCategoryActive" => null,
  175.             "value" => null,
  176.             "limit" => $data["limit"],
  177.         ]);
  178.     }
  179.     /**
  180.      * @Route("/produit/{path}", name="front_product", requirements={"path": ".+"})
  181.      */
  182.     public function product(string $path): Response
  183.     {
  184.         $segments array_values(array_filter(explode('/'$path), fn($s) => $s !== '0' && $s !== ''));
  185.         $cleanPath implode('/'$segments);
  186.         return $this->redirect($this->generateUrl('front_catalog', ['path' => $cleanPath]), 301);
  187.     }
  188.     /**
  189.      * @Route("/a-propos", name="front_privacy_policy")
  190.      */
  191.     public function privacyPolicy(ManagerRegistry $managerRegistryRequest $request)
  192.     {
  193.         return $this->render('front/privacyPolicy.html.twig', array());
  194.     }
  195.     /**
  196.      * @Route("/confidentialite", name="front_confidentiality")
  197.      */
  198.     public function confidentiality(ManagerRegistry $managerRegistryRequest $request)
  199.     {
  200.         return $this->render('front/confidentiality.html.twig', array());
  201.     }
  202.     /**
  203.      * @Route("/", name="front_landing")
  204.      */
  205.     public function landing(Request $requestManagerRegistry $managerRegistry): Response
  206.     {
  207.         $repoPartner $managerRegistry->getRepository(Partner::class);
  208.         $partners $repoPartner->findBy([], ["position" => "asc"]);
  209.         $repoPost $managerRegistry->getRepository(Post::class);
  210.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  211.         $data["orderBy"] = ["a.date""desc"];
  212.         $data["isPublished"] = true;
  213.         $data["limit"] = 3;
  214.         $posts $repoPost->search($data);
  215.         $repoTestimonial $managerRegistry->getRepository(Testimonial::class);
  216.         $testimonials $repoTestimonial->findBy([], ["position" => "asc"]);
  217.         $repoProduct $managerRegistry->getRepository(Product::class);
  218.         $products $repoProduct->findBy(["displayOnLanding" => true], ["position" => "asc"]);
  219.         $repoApplication $managerRegistry->getRepository(Application::class);
  220.         $applications $repoApplication->findBy(["displayOnLanding" => true], ["position" => "asc"]);
  221.         return $this->render('front/landing.html.twig', [
  222.             "posts" => $posts,
  223.             "applications" => $applications,
  224.             "partners" => $partners,
  225.             "testimonials" => $testimonials,
  226.             "products" => $products,
  227.         ]);
  228.     }
  229.     /**
  230.      * @Route("/application/{slug}", name="front_application")
  231.      */
  232.     public function application(ManagerRegistry $managerRegistryRequest $requestApplicationTranslation $applicationTranslation)
  233.     {
  234.         $application $applicationTranslation->getTranslatable();
  235.         $repoApplicationParagraph $managerRegistry->getRepository(ApplicationParagraph::class);
  236.         $applicationParagraphs $repoApplicationParagraph->findBy(["application" => $application], ["position" => "asc"]);
  237.         $repoApplicationProduct $managerRegistry->getRepository(ApplicationProduct::class);
  238.         $applicationProducts $repoApplicationProduct->findBy(["application" => $application], ["position" => "asc"]);
  239.         return $this->render('front/application.html.twig', array(
  240.             "application" => $application,
  241.             "applicationProducts" => $applicationProducts,
  242.             "applicationParagraphs" => $applicationParagraphs
  243.         ));
  244.     }
  245.     /**
  246.      * @Route("/offres-d-emploi", name="front_job_offers")
  247.      */
  248.     public function jobOffers(ManagerRegistry $managerRegistryRequest $request)
  249.     {
  250.         $repoJobOffer $managerRegistry->getRepository(JobOffer::class);
  251.         $jobOffers $repoJobOffer->findBy([], ["position" => "asc"]);
  252.         return $this->render('front/jobOffers.html.twig', array(
  253.             "jobOffers" => $jobOffers
  254.         ));
  255.     }
  256.     /**
  257.      * @Route("/offre-d-emploi/{slug}", name="front_job_offer")
  258.      */
  259.     public function jobOffer(ManagerRegistry $managerRegistryRequest $requestJobOfferTranslation $jobOfferTranslation)
  260.     {
  261.         $jobOffer $jobOfferTranslation->getTranslatable();
  262.         $repoJobOfferParagraph $managerRegistry->getRepository(JobOfferParagraph::class);
  263.         $jobOfferParagraphs $repoJobOfferParagraph->findBy(["jobOffer" => $jobOffer], ["position" => "asc"]);
  264.         return $this->render('front/jobOffer.html.twig', array(
  265.             "jobOffer" => $jobOffer,
  266.             "jobOfferParagraphs" => $jobOfferParagraphs,
  267.         ));
  268.     }
  269.     public function sitemap(Request $requestPackages $packages)
  270.     {
  271.         $repoPage $this->getDoctrine()->getRepository(Page::class);
  272.         $page $repoPage->search(["notNull" => ["a.sitemapFileName"], "limit" => 1]);
  273.         if ($page and $page->getSitemapFileName()) {
  274.             return $this->redirect($packages->getUrl('upload/sitemap/' $page->getSitemapFileName()));
  275.         } else {
  276.             return $this->redirectToRoute('front_landing');
  277.         }
  278.     }
  279.     /**
  280.      * @Route({
  281.      *     "fr": "/contactez-nous/{slug}/{productSlug}/{fabrication}",
  282.      *     "en": "/contact-us/{slug}/{productSlug}/{fabrication}",
  283.      * }, name="front_contact", defaults={"slug":null,"productSlug":null})
  284.      */
  285.     public function contact(Request $requestManagerRegistry $managerRegistryTranslatorInterface $translatorApplicationTranslation $applicationTranslation null$productSlug null$fabrication null)
  286.     {
  287.         $repoProductTranslation $managerRegistry->getRepository(ProductTranslation::class);
  288.         $productTranslation $repoProductTranslation->findOneBy(["slug" => $productSlug]);
  289.         $product $productTranslation $productTranslation->getTranslatable() : null;
  290.         $application $applicationTranslation $applicationTranslation->getTranslatable() : null;
  291.         $contact = new Contact();
  292.         $contactForm $this->createForm(ContactType::class, $contact, [
  293.             "application" => $application,
  294.             "fabrication" => $fabrication,
  295.             "product" => $product
  296.         ]);
  297.         $contactForm->handleRequest($request);
  298.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  299.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  300.             $isRecaptchaValid false;
  301.             if ($recaptchaResponse) {
  302.                 $paramsArr = array(
  303.                     "response" => $recaptchaResponse,
  304.                     "secret" => $this->getParameter('recaptchaSecret')
  305.                 );
  306.                 $ch curl_init();
  307.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  308.                 curl_setopt($chCURLOPT_POST1);
  309.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  310.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  311.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  312.             }
  313.             if (!$isRecaptchaValid) {
  314.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  315.             } else {
  316.                 $em $managerRegistry->getManager();
  317.                 $em->persist($contact);
  318.                 $em->flush();
  319.                 $this->addFlash("success""Message envoyé.");
  320.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  321.                 $mailer = new Mailer($transport);
  322.                 $email = (new TemplatedEmail())
  323.                     ->from($this->getParameter('mailer_user'))
  324.                     ->to($translator->trans("customer_email"))
  325.                     ->subject("Nouveau message")
  326.                     // path of the Twig template to render
  327.                     ->htmlTemplate('mail/contact.html.twig')
  328.                     // pass variables (name => value) to the template
  329.                     ->context(["contact" => $contact]);
  330.                 if ($contact->getEmail()) {
  331.                     $email
  332.                         ->replyTo($contact->getEmail());
  333.                 }
  334.                 foreach ($contact->getCustomFiles() as $key => $customFile) {
  335.                     $email->attachFromPath(("upload/customFile/" $customFile->getCustomFileFileName()));
  336.                 }
  337.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  338.                 $twigEnv = new Environment($loader);
  339.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  340.                 $twigBodyRenderer->render($email);
  341.                 $mailer->send($email);
  342.                 return $this->redirectToRoute('front_contact');
  343.             }
  344.         }
  345.         return $this->render('front/contact.html.twig', array(
  346.             'contactForm' => $contactForm->createView(),
  347.         ));
  348.     }
  349.     /**
  350.      * @Route("/plan-du-site", name="front_sitemap_links")
  351.      */
  352.     public function sitemapLinks(ManagerRegistry $managerRegistryRequest $request)
  353.     {
  354.         return $this->render('front/sitemapLinks.html.twig', array());
  355.     }
  356.     /**
  357.      * @Route("/notre-equipe", name="front_members")
  358.      */
  359.     public function members(ManagerRegistry $managerRegistryRequest $request)
  360.     {
  361.         $repoMember $managerRegistry->getRepository(Member::class);
  362.         $members $repoMember->findBy([], ["position" => "asc"]);
  363.         return $this->render('front/members.html.twig', array(
  364.             "members" => $members
  365.         ));
  366.     }
  367.     /**
  368.      * @Route("/actualites", name="front_posts")
  369.      */
  370.     public function posts(Request $requestPaginatorInterface $paginatorManagerRegistry $managerRegistryActualitePageRepository $actualitePageRepository)
  371.     {
  372.         $repoPost $managerRegistry->getRepository(Post::class);
  373.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  374.         $data["orderBy"] = ["a.date""desc"];
  375.         $data["isPublished"] = true;
  376.         $posts $paginator->paginate(
  377.             $repoPost->search($data), $request->query->getInt('page'1)/* page number */12/* limit per page */
  378.         );
  379.         $bandeau $actualitePageRepository->findAll()[0];
  380.         return $this->render('front/posts.html.twig', array(
  381.             "posts" => $posts,
  382.             'bandeau' => $bandeau
  383.         ));
  384.     }
  385.     /**
  386.      * @Route("/navbar-search", name="front_navbar_search")
  387.      */
  388.     public function navbarSearch(ManagerRegistry $managerRegistryRequest $request)
  389.     {
  390.         $query $request->query->get('nav-search');
  391.         $repoPost $managerRegistry->getRepository(Post::class);
  392.         $data["search"] = $query;
  393.         $data["isPublished"] = true;
  394.         $data["orderBy"] = ["a.date""asc"];
  395.         $posts $repoPost->search($data);
  396.         $repoProduct $managerRegistry->getRepository(Product::class);
  397.         $products $repoProduct->search(["search" => $query"orderBys" => ["a.position" => "asc"]]);
  398.         return $this->render('front/navbarSearch.html.twig', array(
  399.             "posts" => $posts,
  400.             "products" => $products,
  401.             "navSearchQuery" => $query
  402.         ));
  403.     }
  404.     /**
  405.      * @Route("/telechargements/{slug}", name="front_documents", defaults={"slug":null})
  406.      */
  407.     public function documents(ManagerRegistry $managerRegistryRequest $requestDocumentCategoryTranslation $documentCategoryTranslation nullDocumentPageRepository $documentPageRepository)
  408.     {
  409.         $documentCategory $documentCategoryTranslation $documentCategoryTranslation->getTranslatable() : null;
  410.         $repoDocument $managerRegistry->getRepository(Document::class);
  411.         $data = [];
  412.         $repoDocumentCategory $managerRegistry->getRepository(DocumentCategory::class);
  413.         $documentCategories $repoDocumentCategory->findBy([], ["position" => "asc"]);
  414.         $documentCategory $documentCategory ?? ($documentCategories reset($documentCategories) : null);
  415.         if ($documentCategory) {
  416.             $data["documentCategory"] = $documentCategory;
  417.         }
  418.         $documents $repoDocument->findBy($data, ["position" => "asc"]);
  419.         $bandeau $documentPageRepository->findAll()[0];
  420.         return $this->render('front/documents.html.twig', array(
  421.             "documents" => $documents,
  422.             "activeCategory" => $documentCategory,
  423.             "documentCategories" => $documentCategories,
  424.             'bandeau' => $bandeau
  425.         ));
  426.     }
  427.     /**
  428.      * @Route("/actualite/{slug}", name="front_post")
  429.      */
  430.     public function post(Request $requestManagerRegistry $managerRegistrystring $slug)
  431.     {
  432.         $repoPostTranslation $managerRegistry->getRepository(PostTranslation::class);
  433.         $postTranslation $repoPostTranslation->findOneBy(["slug" => $slug]);
  434.         if ($postTranslation and $post $postTranslation->getTranslatable()) {
  435.             if ($post->getIsPublished() or $this->isGranted("ROLE_ADMIN")) {
  436.                 $repoParagraph $managerRegistry->getRepository(Paragraph::class);
  437.                 $paragraphs $repoParagraph->findBy(["post" => $post], ["position" => "asc"]);
  438.                 $repoPostMedia $managerRegistry->getRepository(PostMedia::class);
  439.                 $postMedias $repoPostMedia->findBy(["post" => $post], ["position" => "asc"]);
  440.                 $repoPostDocument $managerRegistry->getRepository(PostDocument::class);
  441.                 $postDocuments $repoPostDocument->findBy(["post" => $post], ["position" => "asc"]);
  442.                 $repoPost $managerRegistry->getRepository(Post::class);
  443.                 $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  444.                 $data["orderBy"] = ["a.date""desc"];
  445.                 $data["isPublished"] = true;
  446.                 $data["limit"] = 2;
  447.                 $data["different"] = ["a.id" => $post->getId()];
  448.                 $posts $repoPost->search($data);
  449.                 return $this->render('front/post.html.twig', array(
  450.                     "post" => $post,
  451.                     "posts" => $posts,
  452.                     "postDocuments" => $postDocuments,
  453.                     "paragraphs" => $paragraphs,
  454.                     "postMedias" => $postMedias,
  455.                 ));
  456.             } else {
  457.                 $this->addFlash("danger""flash.not_allowed_post");
  458.                 return $this->redirectToRoute('front_posts');
  459.             }
  460.         } else {
  461.             $this->addFlash("danger""flash.post_not_found");
  462.             return $this->redirectToRoute('front_posts');
  463.         }
  464.     }
  465.     /**
  466.      * @Route("/inscription-newsletter", name="front_subscribe_newsletter")
  467.      */
  468.     public function subscribeNewsletter(ManagerRegistry $managerRegistryRequest $requestAppService $appService)
  469.     {
  470.         $newsletter = new Newsletter();
  471.         $newsletterForm $this->createForm(NewsletterType::class, $newsletter);
  472.         $newsletterForm->handleRequest($request);
  473.         $em $managerRegistry->getManager();
  474.         if ($newsletterForm->isSubmitted() && $newsletterForm->isValid()) {
  475.             $appService->suscribeToList($newsletter->getEmail());
  476.             $em->persist($newsletter);
  477.             $em->flush();
  478.             $this->addFlash("success""flash.newsletter.success");
  479.             return $this->redirectToRoute('front_landing');
  480.         }
  481.         return $this->render('form/newsletterForm.html.twig', array(
  482.             'newsletterForm' => $newsletterForm->createView(),
  483.         ));
  484.     }
  485.     /**
  486.      * @Route("/admin/fsdhj78Hjkdfsb0920dfjdfhq87djhaoppsnv720", name="front_clear_cache")
  487.      */
  488.     public function clearCache(Request $requestKernelInterface $kernel)
  489.     {
  490.         $application = new FrameworkApplication($kernel);
  491.         $application->setAutoExit(false);
  492.         $input = new ArrayInput([
  493.             'command' => 'cache:clear',
  494.         ]);
  495.         $output = new NullOutput();
  496.         $application->run($input$output);
  497.         $this->addFlash("success""Le cache a bien été nettoyé, les traductions sont à jour !");
  498.         return $this->redirectToRoute('front_landing');
  499.     }
  500.     /**
  501.      * @Route("/{path}", name="front_catalog", requirements={"path": ".+"})
  502.      */
  503.     public function catalog(
  504.         string $path,
  505.         ManagerRegistry $managerRegistry,
  506.         PaginatorInterface $paginator,
  507.         Request $request
  508.     ): Response {
  509.         $segments array_values(array_filter(explode('/'$path)));
  510.         $count count($segments);
  511.         if ($count === 0) {
  512.             throw $this->createNotFoundException();
  513.         }
  514.         $repoCategoryTranslation $managerRegistry->getRepository(CategoryTranslation::class);
  515.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  516.         $repoSubSubCategory $managerRegistry->getRepository(SubSubCategory::class);
  517.         $repoSubSubSubCategory $managerRegistry->getRepository(SubSubSubCategory::class);
  518.         $repoProductTranslation $managerRegistry->getRepository(ProductTranslation::class);
  519.         $repoProduct $managerRegistry->getRepository(Product::class);
  520.         $categoryTranslation $repoCategoryTranslation->findOneBy(['slug' => $segments[0]]);
  521.         if (!$categoryTranslation) {
  522.             throw $this->createNotFoundException();
  523.         }
  524.         $category $categoryTranslation->getTranslatable();
  525.         $productTranslation null;
  526.         $subCategory null;
  527.         $subSubCategory null;
  528.         $subSubSubCategory null;
  529.         if ($count === 5) {
  530.             $subCategory $repoSubCategory->search(['slug' => $segments[1], 'limit' => 1]);
  531.             $subSubCategory $repoSubSubCategory->search(['slug' => $segments[2], 'limit' => 1]);
  532.             $subSubSubCategory $repoSubSubSubCategory->search(['slug' => $segments[3], 'limit' => 1]);
  533.             $productTranslation $repoProductTranslation->findOneBy(['slug' => $segments[4]]);
  534.             if (!$productTranslation) {
  535.                 throw $this->createNotFoundException();
  536.             }
  537.         } elseif ($count === 4) {
  538.             $subCategory $repoSubCategory->search(['slug' => $segments[1], 'limit' => 1]);
  539.             $subSubCategory $repoSubSubCategory->search(['slug' => $segments[2], 'limit' => 1]);
  540.             $subSubSubCategory $repoSubSubSubCategory->search(['slug' => $segments[3], 'limit' => 1]);
  541.             if (!$subSubSubCategory) {
  542.                 $productTranslation $repoProductTranslation->findOneBy(['slug' => $segments[3]]);
  543.                 if (!$productTranslation) {
  544.                     throw $this->createNotFoundException();
  545.                 }
  546.             }
  547.         } elseif ($count === 3) {
  548.             $subCategory $repoSubCategory->search(['slug' => $segments[1], 'limit' => 1]);
  549.             $subSubCatCandidate $repoSubSubCategory->search(['slug' => $segments[2], 'limit' => 1]);
  550.             if ($subSubCatCandidate) {
  551.                 $subSubCategory $subSubCatCandidate;
  552.             } else {
  553.                 $productTranslation $repoProductTranslation->findOneBy(['slug' => $segments[2]]);
  554.                 if (!$productTranslation) {
  555.                     throw $this->createNotFoundException();
  556.                 }
  557.             }
  558.         } elseif ($count === 2) {
  559.             $subCatCandidate $repoSubCategory->search(['slug' => $segments[1], 'limit' => 1]);
  560.             if ($subCatCandidate) {
  561.                 $subCategory $subCatCandidate;
  562.             } else {
  563.                 $productTranslation $repoProductTranslation->findOneBy(['slug' => $segments[1]]);
  564.                 if (!$productTranslation) {
  565.                     throw $this->createNotFoundException();
  566.                 }
  567.             }
  568.         }
  569.         // --- PAGE PRODUIT ---
  570.         if ($productTranslation) {
  571.             $product $productTranslation->getTranslatable();
  572.             $repoProductMedia $managerRegistry->getRepository(ProductMedia::class);
  573.             $productPhotos $repoProductMedia->findBy(["isSchema" => false"product" => $product], ["position" => "asc"]);
  574.             $productSchemas $repoProductMedia->findBy(["isSchema" => true"product" => $product], ["position" => "asc"]);
  575.             $repoProductDocument $managerRegistry->getRepository(ProductDocument::class);
  576.             $productDocuments $repoProductDocument->findBy(["product" => $product], ["position" => "asc"]);
  577.             $repoProductProductTable $managerRegistry->getRepository(ProductProductTable::class);
  578.             $productProductTables $repoProductProductTable->findBy(["product" => $product], ["position" => "asc"]);
  579.             $repoRelatedProduct $managerRegistry->getRepository(RelatedProduct::class);
  580.             $relatedProducts $repoRelatedProduct->findBy(["product" => $product], ["position" => "asc"]);
  581.             return $this->render('front/product.html.twig', [
  582.                 "product" => $product,
  583.                 "relatedProducts" => $relatedProducts,
  584.                 "productDocuments" => $productDocuments,
  585.                 "productSchemas" => $productSchemas,
  586.                 "productPhotos" => $productPhotos,
  587.                 "productProductTables" => $productProductTables,
  588.             ]);
  589.         }
  590.         // --- CATÉGORIE / LISTE DE PRODUITS ---
  591.         $value $subSubSubCategory ?? ($subSubCategory ?? ($subCategory ?? $category));
  592.         $showProductsList false;
  593.         if ($subSubSubCategory) {
  594.             $showProductsList true;
  595.         } elseif ($subSubCategory) {
  596.             $showProductsList $subSubCategory->getSubSubSubCategories()->isEmpty();
  597.         } elseif ($subCategory) {
  598.             $showProductsList $subCategory->getSubSubCategories()->isEmpty();
  599.         } else {
  600.             $showProductsList $category->getSubCategories()->isEmpty();
  601.         }
  602.         if ($showProductsList) {
  603.             $data = ["limit" => 12"hideBaseProduct" => false];
  604.             $data["searchProducts"] = ["categories" => [], "subCategories" => [], "subSubCategories" => [], "subSubSubCategories" => []];
  605.             if ($subSubSubCategory) {
  606.                 $data["searchProducts"]["subSubSubCategories"][] = $subSubSubCategory;
  607.             }
  608.             if ($subSubCategory) {
  609.                 $data["searchProducts"]["subSubCategories"][] = $subSubCategory;
  610.             }
  611.             if ($subCategory) {
  612.                 $data["searchProducts"]["subCategories"][] = $subCategory;
  613.             }
  614.             if ($category) {
  615.                 $data["searchProducts"]["categories"][] = $category;
  616.             }
  617.             $data["orderBys"] = ["a.position" => "asc"];
  618.             $productsFilterForm $this->createForm(ProductsFilterType::class);
  619.             $productsFilterForm->handleRequest($request);
  620.             if ($productsFilterForm->isSubmitted() && $productsFilterForm->isValid()) {
  621.                 $data["searchProducts"]["offset"] = $productsFilterForm["offset"]->getData();
  622.                 $data["orderBys"] = ["a.position" => "asc"];
  623.             }
  624.             $products $repoProduct->search($data);
  625.             $products = (is_array($products) ? $products : ($products ? [$products] : []));
  626.             return $this->render('front/products.html.twig', [
  627.                 "catalogPath" => $path,
  628.                 "listView" => $request->query->get('listView'),
  629.                 'productsFilterForm' => $productsFilterForm->createView(),
  630.                 "products" => $products,
  631.                 "categoryActive" => $category,
  632.                 "subCategoryActive" => $subCategory,
  633.                 "subSubCategoryActive" => $subSubCategory,
  634.                 "subSubSubCategoryActive" => $subSubSubCategory,
  635.                 "value" => $value,
  636.                 "limit" => $data["limit"],
  637.             ]);
  638.         }
  639.         return $this->render('front/category.html.twig', [
  640.             "category" => $category,
  641.             "subCategory" => $subCategory,
  642.             "subSubCategory" => $subSubCategory,
  643.             "value" => $value,
  644.         ]);
  645.     }
  646. }