src/Controller/FrontController.php line 254

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/{slug}/{subCatSlug}/{subSubCatSlug}", name="front_category")
  81.      */
  82.     public function category(ManagerRegistry $managerRegistryAppService $appServiceRequest $requestCategoryTranslation $categoryTranslation$subCatSlug null$subSubCatSlug null)
  83.     {
  84.         $category $categoryTranslation->getTranslatable();
  85.         $repoSubSubCategory $managerRegistry->getRepository(SubSubCategory::class);
  86.         $subSubCategory $repoSubSubCategory->search(["slug" => $subSubCatSlug"limit" => 1]);
  87.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  88.         $subCategory $subSubCategory $subSubCategory->getSubCategory() : $repoSubCategory->search(["slug" => $subCatSlug"limit" => 1]);
  89.         $value $subSubSubCategory ?? ($subSubCategory ?? ($subCategory ?? $category));
  90.         if ($subSubCategory && $subSubCategory->getSubSubSubCategories()->isEmpty()) {
  91.             return $this->redirectToRoute('front_products', [
  92.                 "slug" => $category->getSlug(),
  93.                 "subCatSlug" => $subSubCategory->getSubCategory()->getSlug(),
  94.                 "subSubCatSlug" => $subSubCategory->getSlug(),
  95.                 "subSubSubCatSlug" => null,
  96.                 "listView" => null
  97.             ]);
  98.         } elseif ($subCategory && $subCategory->getSubSubCategories()->isEmpty()) {
  99.             return $this->redirectToRoute('front_products', [
  100.                 "slug" => $category->getSlug(),
  101.                 "subCatSlug" => $subCategory->getSlug(),
  102.                 "subSubCatSlug" => null,
  103.                 "subSubSubCatSlug" => null,
  104.                 "listView" => null
  105.             ]);
  106.         }
  107.         return $this->render('front/category.html.twig', array(
  108.             "category" => $category,
  109.             "subCategory" => $subCategory,
  110.             "subSubCategory" => $subSubCategory,
  111.             "value" => $value
  112.         ));
  113.     }
  114.     /**
  115.      * @Route("/changer-la-langue/{locale}/{routeName}/{routeParams}", name="front_change_language", requirements={"routeParams"=".+"})
  116.      */
  117.     public function changeLanguage(Request $requestSessionInterface $session$locale$routeName$routeParams null)
  118.     {
  119.         $routeParams array_merge(["_locale" => $locale], $_GET);
  120.         return $this->redirectToRoute($routeName$routeParams);
  121.     }
  122.     /**
  123.      * @Route("/presentation", name="front_presentation")
  124.      */
  125.     public function presentation(ManagerRegistry $managerRegistryRequest $requestPresentationPageRepository $presentationPageRepository)
  126.     {
  127.         $repoPresentationParagraph $managerRegistry->getRepository(PresentationParagraph::class);
  128.         $bandeau $presentationPageRepository->findAll()[0];
  129.         $presentationParagraphs $repoPresentationParagraph->findBy([], ["position" => "asc"]);
  130.         return $this->render('front/presentation.html.twig', array(
  131.             "presentationParagraphs" => $presentationParagraphs,
  132.             'bandeau' => $bandeau
  133.         ));
  134.     }
  135.     /**
  136.      * @Route("/fabrication-sur-mesure", name="front_fabrication")
  137.      */
  138.     public function fabrication(ManagerRegistry $managerRegistryRequest $requestFabricationPageRepository $fabricationPageRepository)
  139.     {
  140.         $repoFabricationParagraph $managerRegistry->getRepository(FabricationParagraph::class);
  141.         $page $fabricationPageRepository->findAll()[0];
  142.         $fabricationParagraphs $repoFabricationParagraph->findBy([], ["position" => "asc"]);
  143.         $repoProduct $managerRegistry->getRepository(Product::class);
  144.         $products $repoProduct->findBy(["isCustom" => true], ["position" => "asc"]);
  145.         return $this->render('front/fabrication.html.twig', array(
  146.             "fabricationParagraphs" => $fabricationParagraphs,
  147.             "products" => $products,
  148.             'bandeau' => $page
  149.         ));
  150.     }
  151.     /**
  152.      * @Route("/produits/{slug}/{subCatSlug}/{subSubCatSlug}/{subSubSubCatSlug}/{listView}", name="front_products", defaults={"slug":null})
  153.      */
  154.     public function products(ManagerRegistry $managerRegistryPaginatorInterface $paginatorRequest $requestCategoryTranslation $categoryTranslation null$subCatSlug null$subSubCatSlug null$subSubSubCatSlug null$listView null)
  155.     {
  156.         $category $categoryTranslation $categoryTranslation->getTranslatable() : null;
  157.         $repoSubSubSubCategory $managerRegistry->getRepository(SubSubSubCategory::class);
  158.         $subSubSubCategory $repoSubSubSubCategory->search(["slug" => $subSubSubCatSlug"limit" => 1]);
  159.         $repoSubSubCategory $managerRegistry->getRepository(SubSubCategory::class);
  160.         $subSubCategory $subSubSubCategory $subSubSubCategory->getSubSubCategory() : $repoSubSubCategory->search(["slug" => $subSubCatSlug"limit" => 1]);
  161.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  162.         $subCategory $subSubCategory $subSubCategory->getSubCategory() : $repoSubCategory->search(["slug" => $subCatSlug"limit" => 1]);
  163.         $data["limit"] = 12;
  164.         $data["hideBaseProduct"] = false;
  165.         $data["searchProducts"] = ["categories" => [], "subCategories" => [], "subSubCategories" => [], "subSubSubCategories" => []];
  166.         // Appliquer les filtres de catégorie depuis l'URL (même pour les requêtes AJAX)
  167.         if ($subSubSubCategory) {
  168.             $data["searchProducts"]["subSubSubCategories"][] = $subSubSubCategory;
  169.         }
  170.         if ($subSubCategory) {
  171.             $data["searchProducts"]["subSubCategories"][] = $subSubCategory;
  172.         }
  173.         if ($subCategory) {
  174.             $data["searchProducts"]["subCategories"][] = $subCategory;
  175.         }
  176.         if ($category) {
  177.             $data["searchProducts"]["categories"][] = $category;
  178.         }
  179.         $data["orderBys"] = ["a.position" => "asc"];
  180.         $productsFilterForm $this->createForm(ProductsFilterType::class);
  181.         $productsFilterForm->handleRequest($request);
  182.         if ($productsFilterForm->isSubmitted() && $productsFilterForm->isValid()) {
  183.             $data["searchProducts"]["offset"] = $productsFilterForm["offset"]->getData();
  184.             $data["orderBys"] = ["a.position" => "asc"];
  185.         }
  186.         $repoProduct $managerRegistry->getRepository(Product::class);
  187.         $products $repoProduct->search($data);
  188.         $products = (is_array($products) ? $products : ($products ? [$products] : []));
  189.         return $this->render('front/products.html.twig', array(
  190.             "slug" => $categoryTranslation $categoryTranslation->getSlug() : "0",
  191.             "subCatSlug" => $subCatSlug ?? "0",
  192.             "subSubCatSlug" => $subSubCatSlug ?? "0",
  193.             "subSubSubCatSlug" => $subSubSubCatSlug ?? "0",
  194.             "listView" => $listView,
  195.             'productsFilterForm' => $productsFilterForm->createView(),
  196.             "products" => $products,
  197.             "categoryActive" => $category,
  198.             "subCategoryActive" => $subCategory,
  199.             "subSubCategoryActive" => $subSubCategory,
  200.             "subSubSubCategoryActive" => $subSubSubCategory,
  201.             "value" => ($subSubSubCategory ?? $subSubCategory ?? $subCategory ?? $category),
  202.             "limit" => $data["limit"]
  203.         ));
  204.     }
  205.     /**
  206.      * @Route("/produit/{catSlug}/{subCatSlug}/{subSubCatSlug}/{subSubSubCatSlug}/{slug}", name="front_product")
  207.      */
  208.     public function product(ManagerRegistry $managerRegistryRequest $request$catSlug$subCatSlug$subSubCatSlug$subSubSubCatSlugProductTranslation $productTranslation)
  209.     {
  210.         $product $productTranslation->getTranslatable();
  211.         $repoProductMedia $managerRegistry->getRepository(ProductMedia::class);
  212.         $productPhotos $repoProductMedia->findBy(["isSchema" => false"product" => $product], ["position" => "asc"]);
  213.         $productSchemas $repoProductMedia->findBy(["isSchema" => true"product" => $product], ["position" => "asc"]);
  214.         $repoProductDocument $managerRegistry->getRepository(ProductDocument::class);
  215.         $productDocuments $repoProductDocument->findBy(["product" => $product], ["position" => "asc"]);
  216.         $repoProductProductTable $managerRegistry->getRepository(ProductProductTable::class);
  217.         $productProductTables $repoProductProductTable->findBy(["product" => $product], ["position" => "asc"]);
  218.         $repoRelatedProduct $managerRegistry->getRepository(RelatedProduct::class);
  219.         $relatedProducts $repoRelatedProduct->findBy(["product" => $product], ["position" => "asc"]);
  220.         return $this->render('front/product.html.twig', array(
  221.             "product" => $product,
  222.             "relatedProducts" => $relatedProducts,
  223.             "productDocuments" => $productDocuments,
  224.             "productSchemas" => $productSchemas,
  225.             "productPhotos" => $productPhotos
  226.         ));
  227.     }
  228.     /**
  229.      * @Route("/a-propos", name="front_privacy_policy")
  230.      */
  231.     public function privacyPolicy(ManagerRegistry $managerRegistryRequest $request)
  232.     {
  233.         return $this->render('front/privacyPolicy.html.twig', array());
  234.     }
  235.     /**
  236.      * @Route("/", name="front_landing")
  237.      */
  238.     public function landing(Request $requestManagerRegistry $managerRegistry): Response
  239.     {
  240.         $repoPartner $managerRegistry->getRepository(Partner::class);
  241.         $partners $repoPartner->findBy([], ["position" => "asc"]);
  242.         $repoPost $managerRegistry->getRepository(Post::class);
  243.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  244.         $data["orderBy"] = ["a.date""desc"];
  245.         $data["isPublished"] = true;
  246.         $data["limit"] = 3;
  247.         $posts $repoPost->search($data);
  248.         $repoTestimonial $managerRegistry->getRepository(Testimonial::class);
  249.         $testimonials $repoTestimonial->findBy([], ["position" => "asc"]);
  250.         $repoProduct $managerRegistry->getRepository(Product::class);
  251.         $products $repoProduct->findBy(["displayOnLanding" => true], ["position" => "asc"]);
  252.         $repoApplication $managerRegistry->getRepository(Application::class);
  253.         $applications $repoApplication->findBy(["displayOnLanding" => true], ["position" => "asc"]);
  254.         return $this->render('front/landing.html.twig', [
  255.             "posts" => $posts,
  256.             "applications" => $applications,
  257.             "partners" => $partners,
  258.             "testimonials" => $testimonials,
  259.             "products" => $products,
  260.         ]);
  261.     }
  262.     /**
  263.      * @Route("/application/{slug}", name="front_application")
  264.      */
  265.     public function application(ManagerRegistry $managerRegistryRequest $requestApplicationTranslation $applicationTranslation)
  266.     {
  267.         $application $applicationTranslation->getTranslatable();
  268.         $repoApplicationParagraph $managerRegistry->getRepository(ApplicationParagraph::class);
  269.         $applicationParagraphs $repoApplicationParagraph->findBy(["application" => $application], ["position" => "asc"]);
  270.         $repoApplicationProduct $managerRegistry->getRepository(ApplicationProduct::class);
  271.         $applicationProducts $repoApplicationProduct->findBy(["application" => $application], ["position" => "asc"]);
  272.         return $this->render('front/application.html.twig', array(
  273.             "application" => $application,
  274.             "applicationProducts" => $applicationProducts,
  275.             "applicationParagraphs" => $applicationParagraphs
  276.         ));
  277.     }
  278.     /**
  279.      * @Route("/offres-d-emploi", name="front_job_offers")
  280.      */
  281.     public function jobOffers(ManagerRegistry $managerRegistryRequest $request)
  282.     {
  283.         $repoJobOffer $managerRegistry->getRepository(JobOffer::class);
  284.         $jobOffers $repoJobOffer->findBy([], ["position" => "asc"]);
  285.         return $this->render('front/jobOffers.html.twig', array(
  286.             "jobOffers" => $jobOffers
  287.         ));
  288.     }
  289.     /**
  290.      * @Route("/offre-d-emploi/{slug}", name="front_job_offer")
  291.      */
  292.     public function jobOffer(ManagerRegistry $managerRegistryRequest $requestJobOfferTranslation $jobOfferTranslation)
  293.     {
  294.         $jobOffer $jobOfferTranslation->getTranslatable();
  295.         $repoJobOfferParagraph $managerRegistry->getRepository(JobOfferParagraph::class);
  296.         $jobOfferParagraphs $repoJobOfferParagraph->findBy(["jobOffer" => $jobOffer], ["position" => "asc"]);
  297.         return $this->render('front/jobOffer.html.twig', array(
  298.             "jobOffer" => $jobOffer,
  299.             "jobOfferParagraphs" => $jobOfferParagraphs,
  300.         ));
  301.     }
  302.     public function sitemap(Request $requestPackages $packages)
  303.     {
  304.         $repoPage $this->getDoctrine()->getRepository(Page::class);
  305.         $page $repoPage->search(["notNull" => ["a.sitemapFileName"], "limit" => 1]);
  306.         if ($page and $page->getSitemapFileName()) {
  307.             return $this->redirect($packages->getUrl('upload/sitemap/' $page->getSitemapFileName()));
  308.         } else {
  309.             return $this->redirectToRoute('front_landing');
  310.         }
  311.     }
  312.     /**
  313.      * @Route({
  314.      *     "fr": "/contactez-nous/{slug}/{productSlug}/{fabrication}",
  315.      *     "en": "/contact-us/{slug}/{productSlug}/{fabrication}",
  316.      * }, name="front_contact", defaults={"slug":null,"productSlug":null})
  317.      */
  318.     public function contact(Request $requestManagerRegistry $managerRegistryTranslatorInterface $translatorApplicationTranslation $applicationTranslation null$productSlug null$fabrication null)
  319.     {
  320.         $repoProductTranslation $managerRegistry->getRepository(ProductTranslation::class);
  321.         $productTranslation $repoProductTranslation->findOneBy(["slug" => $productSlug]);
  322.         $product $productTranslation $productTranslation->getTranslatable() : null;
  323.         $application $applicationTranslation $applicationTranslation->getTranslatable() : null;
  324.         $contact = new Contact();
  325.         $contactForm $this->createForm(ContactType::class, $contact, [
  326.             "application" => $application,
  327.             "fabrication" => $fabrication,
  328.             "product" => $product
  329.         ]);
  330.         $contactForm->handleRequest($request);
  331.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  332.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  333.             $isRecaptchaValid false;
  334.             if ($recaptchaResponse) {
  335.                 $paramsArr = array(
  336.                     "response" => $recaptchaResponse,
  337.                     "secret" => $this->getParameter('recaptchaSecret')
  338.                 );
  339.                 $ch curl_init();
  340.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  341.                 curl_setopt($chCURLOPT_POST1);
  342.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  343.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  344.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  345.             }
  346.             if (!$isRecaptchaValid) {
  347.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  348.             } else {
  349.                 $em $managerRegistry->getManager();
  350.                 $em->persist($contact);
  351.                 $em->flush();
  352.                 $this->addFlash("success""Message envoyé.");
  353.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  354.                 $mailer = new Mailer($transport);
  355.                 $email = (new TemplatedEmail())
  356.                     ->from($this->getParameter('mailer_user'))
  357.                     ->to($translator->trans("customer_email"))
  358.                     ->subject("Nouveau message")
  359.                     // path of the Twig template to render
  360.                     ->htmlTemplate('mail/contact.html.twig')
  361.                     // pass variables (name => value) to the template
  362.                     ->context(["contact" => $contact]);
  363.                 if ($contact->getEmail()) {
  364.                     $email
  365.                         ->replyTo($contact->getEmail());
  366.                 }
  367.                 foreach ($contact->getCustomFiles() as $key => $customFile) {
  368.                     $email->attachFromPath(("upload/customFile/" $customFile->getCustomFileFileName()));
  369.                 }
  370.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  371.                 $twigEnv = new Environment($loader);
  372.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  373.                 $twigBodyRenderer->render($email);
  374.                 $mailer->send($email);
  375.                 return $this->redirectToRoute('front_contact');
  376.             }
  377.         }
  378.         return $this->render('front/contact.html.twig', array(
  379.             'contactForm' => $contactForm->createView(),
  380.         ));
  381.     }
  382.     /**
  383.      * @Route("/plan-du-site", name="front_sitemap_links")
  384.      */
  385.     public function sitemapLinks(ManagerRegistry $managerRegistryRequest $request)
  386.     {
  387.         return $this->render('front/sitemapLinks.html.twig', array());
  388.     }
  389.     /**
  390.      * @Route("/notre-equipe", name="front_members")
  391.      */
  392.     public function members(ManagerRegistry $managerRegistryRequest $request)
  393.     {
  394.         $repoMember $managerRegistry->getRepository(Member::class);
  395.         $members $repoMember->findBy([], ["position" => "asc"]);
  396.         return $this->render('front/members.html.twig', array(
  397.             "members" => $members
  398.         ));
  399.     }
  400.     /**
  401.      * @Route("/actualites", name="front_posts")
  402.      */
  403.     public function posts(Request $requestPaginatorInterface $paginatorManagerRegistry $managerRegistryActualitePageRepository $actualitePageRepository)
  404.     {
  405.         $repoPost $managerRegistry->getRepository(Post::class);
  406.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  407.         $data["orderBy"] = ["a.date""desc"];
  408.         $data["isPublished"] = true;
  409.         $posts $paginator->paginate(
  410.             $repoPost->search($data), $request->query->getInt('page'1)/* page number */12/* limit per page */
  411.         );
  412.         $bandeau $actualitePageRepository->findAll()[0];
  413.         return $this->render('front/posts.html.twig', array(
  414.             "posts" => $posts,
  415.             'bandeau' => $bandeau
  416.         ));
  417.     }
  418.     /**
  419.      * @Route("/navbar-search", name="front_navbar_search")
  420.      */
  421.     public function navbarSearch(ManagerRegistry $managerRegistryRequest $request)
  422.     {
  423.         $query $request->query->get('nav-search');
  424.         $repoPost $managerRegistry->getRepository(Post::class);
  425.         $data["search"] = $query;
  426.         $data["isPublished"] = true;
  427.         $data["orderBy"] = ["a.date""asc"];
  428.         $posts $repoPost->search($data);
  429.         $repoProduct $managerRegistry->getRepository(Product::class);
  430.         $products $repoProduct->search(["search" => $query"orderBys" => ["a.position" => "asc"]]);
  431.         return $this->render('front/navbarSearch.html.twig', array(
  432.             "posts" => $posts,
  433.             "products" => $products,
  434.             "navSearchQuery" => $query
  435.         ));
  436.     }
  437.     /**
  438.      * @Route("/telechargements/{slug}", name="front_documents", defaults={"slug":null})
  439.      */
  440.     public function documents(ManagerRegistry $managerRegistryRequest $requestDocumentCategoryTranslation $documentCategoryTranslation nullDocumentPageRepository $documentPageRepository)
  441.     {
  442.         $documentCategory $documentCategoryTranslation $documentCategoryTranslation->getTranslatable() : null;
  443.         $repoDocument $managerRegistry->getRepository(Document::class);
  444.         $data = [];
  445.         $repoDocumentCategory $managerRegistry->getRepository(DocumentCategory::class);
  446.         $documentCategories $repoDocumentCategory->findBy([], ["position" => "asc"]);
  447.         $documentCategory $documentCategory ?? ($documentCategories reset($documentCategories) : null);
  448.         if ($documentCategory) {
  449.             $data["documentCategory"] = $documentCategory;
  450.         }
  451.         $documents $repoDocument->findBy($data, ["position" => "asc"]);
  452.         $bandeau $documentPageRepository->findAll()[0];
  453.         return $this->render('front/documents.html.twig', array(
  454.             "documents" => $documents,
  455.             "activeCategory" => $documentCategory,
  456.             "documentCategories" => $documentCategories,
  457.             'bandeau' => $bandeau
  458.         ));
  459.     }
  460.     /**
  461.      * @Route("/actualite/{slug}", name="front_post")
  462.      */
  463.     public function post(Request $requestManagerRegistry $managerRegistrystring $slug)
  464.     {
  465.         $repoPostTranslation $managerRegistry->getRepository(PostTranslation::class);
  466.         $postTranslation $repoPostTranslation->findOneBy(["slug" => $slug]);
  467.         if ($postTranslation and $post $postTranslation->getTranslatable()) {
  468.             if ($post->getIsPublished() or $this->isGranted("ROLE_ADMIN")) {
  469.                 $repoParagraph $managerRegistry->getRepository(Paragraph::class);
  470.                 $paragraphs $repoParagraph->findBy(["post" => $post], ["position" => "asc"]);
  471.                 $repoPostMedia $managerRegistry->getRepository(PostMedia::class);
  472.                 $postMedias $repoPostMedia->findBy(["post" => $post], ["position" => "asc"]);
  473.                 $repoPostDocument $managerRegistry->getRepository(PostDocument::class);
  474.                 $postDocuments $repoPostDocument->findBy(["post" => $post], ["position" => "asc"]);
  475.                 $repoPost $managerRegistry->getRepository(Post::class);
  476.                 $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  477.                 $data["orderBy"] = ["a.date""desc"];
  478.                 $data["isPublished"] = true;
  479.                 $data["limit"] = 2;
  480.                 $data["different"] = ["a.id" => $post->getId()];
  481.                 $posts $repoPost->search($data);
  482.                 return $this->render('front/post.html.twig', array(
  483.                     "post" => $post,
  484.                     "posts" => $posts,
  485.                     "postDocuments" => $postDocuments,
  486.                     "paragraphs" => $paragraphs,
  487.                     "postMedias" => $postMedias,
  488.                 ));
  489.             } else {
  490.                 $this->addFlash("danger""flash.not_allowed_post");
  491.                 return $this->redirectToRoute('front_posts');
  492.             }
  493.         } else {
  494.             $this->addFlash("danger""flash.post_not_found");
  495.             return $this->redirectToRoute('front_posts');
  496.         }
  497.     }
  498.     /**
  499.      * @Route("/inscription-newsletter", name="front_subscribe_newsletter")
  500.      */
  501.     public function subscribeNewsletter(ManagerRegistry $managerRegistryRequest $requestAppService $appService)
  502.     {
  503.         $newsletter = new Newsletter();
  504.         $newsletterForm $this->createForm(NewsletterType::class, $newsletter);
  505.         $newsletterForm->handleRequest($request);
  506.         $em $managerRegistry->getManager();
  507.         if ($newsletterForm->isSubmitted() && $newsletterForm->isValid()) {
  508.             $appService->suscribeToList($newsletter->getEmail());
  509.             $em->persist($newsletter);
  510.             $em->flush();
  511.             $this->addFlash("success""flash.newsletter.success");
  512.             return $this->redirectToRoute('front_landing');
  513.         }
  514.         return $this->render('form/newsletterForm.html.twig', array(
  515.             'newsletterForm' => $newsletterForm->createView(),
  516.         ));
  517.     }
  518.     /**
  519.      * @Route("/admin/fsdhj78Hjkdfsb0920dfjdfhq87djhaoppsnv720", name="front_clear_cache")
  520.      */
  521.     public function clearCache(Request $requestKernelInterface $kernel)
  522.     {
  523.         $application = new FrameworkApplication($kernel);
  524.         $application->setAutoExit(false);
  525.         $input = new ArrayInput([
  526.             'command' => 'cache:clear',
  527.         ]);
  528.         // You can use NullOutput() if you don't need the output
  529.         $output = new NullOutput();
  530.         $application->run($input$output);
  531.         $this->addFlash("success""Le cache a bien été nettoyé, les traductions sont à jour !");
  532.         return $this->redirectToRoute('front_landing');
  533.     }
  534. }