src/Controller/FrontController.php line 407

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