src/Controller/FrontController.php line 367

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Catalog;
  4. use App\Entity\Category;
  5. use App\Entity\CategoryTranslation;
  6. use App\Entity\Contact;
  7. use App\Entity\JobOffer;
  8. use App\Entity\JobOfferParagraph;
  9. use App\Entity\JobOfferTranslation;
  10. use App\Entity\LandingContact;
  11. use App\Entity\LandingPage;
  12. use App\Entity\LandingPageTranslation;
  13. use App\Entity\Member;
  14. use App\Entity\Newsletter;
  15. use App\Entity\Page;
  16. use App\Entity\Paragraph;
  17. use App\Entity\Partner;
  18. use App\Entity\PhaseEvolutionTranslation;
  19. use App\Entity\Post;
  20. use App\Entity\PostMedia;
  21. use App\Entity\PostTranslation;
  22. use App\Entity\Presentation;
  23. use App\Entity\PresentationParagraph;
  24. use App\Entity\PresentationValue;
  25. use App\Entity\Product;
  26. use App\Entity\ProductPublication;
  27. use App\Entity\ProductTranslation;
  28. use App\Entity\Publication;
  29. use App\Entity\PublicationCategory;
  30. use App\Entity\PublicationCategoryTranslation;
  31. use App\Entity\PublicationTranslation;
  32. use App\Entity\Setting;
  33. use App\Entity\SubCategory;
  34. use App\Entity\SubCategoryTranslation;
  35. use App\Entity\Support;
  36. use App\Entity\Testimonial;
  37. use App\Form\ContactType;
  38. use App\Form\LandingContactType;
  39. use App\Form\NewsletterType;
  40. use App\Form\PostsFilterType;
  41. use App\Form\ProductsFilterType;
  42. use App\Form\PublicationsFilterType;
  43. use App\Form\SupportType;
  44. use App\Service\AppService;
  45. use App\Twig\AppExtension;
  46. use Doctrine\Persistence\ManagerRegistry;
  47. use Knp\Component\Pager\PaginatorInterface;
  48. use Mailjet\Resources;
  49. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  50. use Symfony\Bridge\Twig\Mime\BodyRenderer;
  51. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  52. use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkApplication;
  53. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  54. use Symfony\Component\Asset\Packages;
  55. use Symfony\Component\Console\Input\ArrayInput;
  56. use Symfony\Component\Console\Output\NullOutput;
  57. use Symfony\Component\HttpFoundation\Request;
  58. use Symfony\Component\HttpFoundation\Response;
  59. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  60. use Symfony\Component\HttpKernel\KernelInterface;
  61. use Symfony\Component\Mailer\Mailer;
  62. use Symfony\Component\Mailer\MailerInterface;
  63. use Symfony\Component\Mailer\Transport;
  64. use Symfony\Component\Mime\Email;
  65. use Symfony\Component\Routing\Annotation\Route;
  66. use Symfony\Contracts\Translation\TranslatorInterface;
  67. use Twig\Environment;
  68. use Twig\Loader\FilesystemLoader;
  69. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  70. use Symfony\Component\Filesystem\Filesystem;
  71. use Symfony\Component\Filesystem\Path;
  72. class FrontController extends AbstractController
  73. {
  74.     /**
  75.      * @Route("/changer-la-langue/{locale}/{redirectUrl}", name="front_change_language", requirements={"redirectUrl"=".+"})
  76.      */
  77.     public function changeLanguage(Request $requestSessionInterface $session$locale$redirectUrl null)
  78.     {
  79.         $session->set('_locale'$locale);
  80.         return ($redirectUrl $this->redirect($redirectUrl) : $this->redirectToRoute('front_landing'));
  81.     }
  82.     /**
  83.      * @Route("/admin/HJSD876326Hjfdhkljlk98hdfjfnb63569", name="admin_import_publications")
  84.      */
  85.     public function adminImportPublications(ManagerRegistry $managerRegistryRequest $request)
  86.     {
  87.         $row 1;
  88.         $em $managerRegistry->getManager();
  89.         $repoCategory $managerRegistry->getRepository(Category::class);
  90.         $repoPhaseEvolutionTranslation $managerRegistry->getRepository(PhaseEvolutionTranslation::class);
  91.         $repoPublicationCategoryTranslation $managerRegistry->getRepository(PublicationCategoryTranslation::class);
  92.         if (($handle fopen("publications_en.csv""r")) !== FALSE) {
  93.             while (($data fgetcsv($handle0",")) !== FALSE) {
  94.                 if ($row and $data[5]) {
  95.                     $publication = new Publication();
  96.                     $em->persist($publication);
  97.                     $categoryTitle trim($data[0]);
  98.                     $category $repoCategory->search(["title" => $categoryTitle'limit' => 1]);
  99.                     $publication->setCategory($category);
  100.                     $publicationCategoryTitle trim($data[1]);
  101.                     $publicationCategoryTranslation $repoPublicationCategoryTranslation->findOneBy(["title" => $publicationCategoryTitle]);
  102.                     if (!$publicationCategoryTranslation) {
  103.                         $publicationCategory = new PublicationCategory();
  104.                         $em->persist($publicationCategory);
  105.                         $publicationCategoryTranslation = new PublicationCategoryTranslation();
  106.                         $em->persist($publicationCategoryTranslation);
  107.                         $publicationCategoryTranslation->setTitle($publicationCategoryTitle);
  108.                         $publicationCategoryTranslation->setLocale("en");
  109.                         $publicationCategoryTranslation->setTranslatable($publicationCategory);
  110.                     } else {
  111.                         $publicationCategory $publicationCategoryTranslation->getTranslatable();
  112.                     }
  113.                     $publication->setPublicationCategory($publicationCategory);
  114.                     foreach (explode(","$data[2]) as $key => $phaseEvolutionTitle) {
  115.                         $phaseEvolutionTitle trim($phaseEvolutionTitle);
  116.                         $phaseEvolutionTranslation $repoPhaseEvolutionTranslation->findOneBy(["title" => $phaseEvolutionTitle]);
  117.                         if ($phaseEvolutionTranslation) {
  118.                             $phaseEvolution $phaseEvolutionTranslation->getTranslatable();
  119.                             $publication->addPhaseEvolution($phaseEvolution);
  120.                         }
  121.                     }
  122.                     $year trim($data[4]);
  123.                     $year str_replace("("""$year);
  124.                     $year str_replace(")"""$year);
  125.                     $publication->setDate($year);
  126.                     $publicationTranslation = new PublicationTranslation();
  127.                     $publicationTranslation->setTranslatable($publication);
  128.                     $publicationTranslation->setLocale("en");
  129.                     $publicationTranslation->setAuthor(trim($data[3]));
  130.                     $publicationTranslation->setTitle(trim($data[5]));
  131.                     $publication->setLink(trim($data[6]));
  132.                     $publicationTranslation->setRevue(trim($data[7]));
  133.                     $repoProductTranslation $managerRegistry->getRepository(ProductTranslation::class);
  134.                     foreach (explode(","$data[8]) as $key => $productTitle) {
  135.                         $productTitle trim($productTitle);
  136.                         $productTranslation $repoProductTranslation->findOneBy(["title" => $productTitle]);
  137.                         if ($productTranslation) {
  138.                             $product $productTranslation->getTranslatable();
  139.                             $productPublication = new ProductPublication();
  140.                             $productPublication->setProduct($product);
  141.                             $productPublication->setPublication($publication);
  142.                             $em->persist($productPublication);
  143.                         }
  144.                     }
  145.                     $em->persist($publicationTranslation);
  146.                     $em->flush();
  147.                 }
  148.                 $row++;
  149.             }
  150.             fclose($handle);
  151.         }
  152.         exit;
  153.     }
  154.     /**
  155.      * @Route("/about-us", name="front_presentation")
  156.      */
  157.     public function presentation(ManagerRegistry $managerRegistryRequest $requestPaginatorInterface $paginator)
  158.     {
  159.         $repoPresentation $managerRegistry->getRepository(Presentation::class);
  160.         $pres $repoPresentation->findAll();
  161.         if (count($pres) > 0) {
  162.             $pres $pres[0];
  163.         }
  164.         $repoPresentationParagraph $managerRegistry->getRepository(PresentationParagraph::class);
  165.         $presentationParagraphs $repoPresentationParagraph->findBy([], ["position" => "asc"]);
  166.         $repoMember $managerRegistry->getRepository(Member::class);
  167.         $members $paginator->paginate(
  168.             $repoMember->findBy([], ["position" => "asc"]), $request->query->getInt('page'1)/* page number */10/* limit per page */
  169.         );
  170.         $repoPartner $managerRegistry->getRepository(Partner::class);
  171.         $distributors $repoPartner->findBy(["type" => "Distributor"], ["position" => "asc"]);
  172.         $partners $repoPartner->findBy(["type" => "Partner"], ["position" => "asc"]);
  173.         $repoSetting $managerRegistry->getRepository(Setting::class);
  174.         $setting $repoSetting->findOneBy([]);
  175.         $repoCategory $managerRegistry->getRepository(Category::class);
  176.         $categories $repoCategory->findBy([], ["position" => "asc"]);
  177.         $repoPresentationValue $managerRegistry->getRepository(PresentationValue::class);
  178.         $presentationValues $repoPresentationValue->findBy([], ["position" => "asc"]);
  179.         return $this->render('front/presentation.html.twig', array(
  180.             "presentation" => $pres,
  181.             "presentationParagraphs" => $presentationParagraphs,
  182.             "members" => $members,
  183.             "partners" => $partners,
  184.             "distributors" => $distributors,
  185.             'setting' => $setting,
  186.             "categories" => $categories,
  187.             "presentationValues" => $presentationValues,
  188.         ));
  189.     }
  190.     /**
  191.      * @Route("/products/{catSlug}/{subCatSlug}", name="front_products")
  192.      */
  193.     public function products(ManagerRegistry $managerRegistryTranslatorInterface $translatorPaginatorInterface $paginatorRequest $request$catSlug null$subCatSlug null)
  194.     {
  195.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  196.         $subCategory $repoSubCategory->search(["slug" => $subCatSlug"limit" => 1]);
  197.         $repoCategory $managerRegistry->getRepository(Category::class);
  198.         $category $subCategory $subCategory->getCategory() : $repoCategory->search(["slug" => $catSlug"limit" => 1]);
  199.         $category $category ?? $repoCategory->findOneBy([], ["position" => "asc"]);
  200.         if (!$category) {
  201.             return $this->redirectToRoute('front_landing');
  202.         }
  203.         $data["orderBy"] = ["a.position""asc"];
  204.         $data["hide"] = false;
  205.         $limit 9;
  206.         $data["searchProducts"] = ["categories" => [], "subCategories" => []];
  207.         if (!$request->isXmlHttpRequest()) {
  208.             if ($subCategory) {
  209.                 $data["searchProducts"]["subCategories"][] = $subCategory;
  210.             }
  211.             if ($category) {
  212.                 $data["searchProducts"]["categories"][] = $category;
  213.             }
  214.         }
  215.         $productsFilterForm $this->createForm(ProductsFilterType::class, null, [
  216.             "category" => $category
  217.         ]);
  218.         $productsFilterForm->handleRequest($request);
  219.         if ($productsFilterForm->isSubmitted() && $productsFilterForm->isValid()) {
  220.             $data["searchProducts"] = $productsFilterForm->getData();
  221.         }
  222.         $repoProduct $managerRegistry->getRepository(Product::class);
  223.         $products $repoProduct->search(array_merge($data, ["limit" => $limit]));
  224.         $products = (is_array($products) ? $products : ($products ? [$products] : []));
  225.         $totalProducts count($repoProduct->search($data));
  226.         $contact = new Contact();
  227.         $contactForm $this->createForm(ContactType::class, $contact, [
  228.             "noSubject" => true
  229.         ]);
  230.         $contactForm->handleRequest($request);
  231.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  232.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  233.             $isRecaptchaValid false;
  234.             if ($recaptchaResponse) {
  235.                 $paramsArr = array(
  236.                     "response" => $recaptchaResponse,
  237.                     "secret" => $this->getParameter('recaptchaSecret')
  238.                 );
  239.                 $ch curl_init();
  240.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  241.                 curl_setopt($chCURLOPT_POST1);
  242.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  243.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  244.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  245.             }
  246.             if (!$isRecaptchaValid) {
  247.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  248.             } else {
  249.                 $em $managerRegistry->getManager();
  250.                 $em->persist($contact);
  251.                 $em->flush();
  252.                 $this->addFlash("success""Message envoyé.");
  253.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  254.                 $mailer = new Mailer($transport);
  255.                 $email = (new TemplatedEmail())
  256.                     ->from($this->getParameter('mailer_user'))
  257.                     ->to($translator->trans("customer_email"))
  258.                     ->subject("Nouveau message")
  259.                     // path of the Twig template to render
  260.                     ->htmlTemplate('mail/contact.html.twig')
  261.                     // pass variables (name => value) to the template
  262.                     ->context(["contact" => $contact]);
  263.                 foreach ($contact->getCustomFiles() as $key => $customFile) {
  264.                     $email->attachFromPath(("upload/customFile/" $customFile->getCustomFileFileName()));
  265.                 }
  266.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  267.                 $twigEnv = new Environment($loader);
  268.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  269.                 $twigBodyRenderer->render($email);
  270.                 $mailer->send($email);
  271.                 return $this->redirectToRoute('front_products');
  272.             }
  273.         }
  274.         return $this->render('front/products.html.twig', array(
  275.             'contactForm' => $contactForm->createView(),
  276.             'productsFilterForm' => $productsFilterForm->createView(),
  277.             "products" => $products,
  278.             "categoryActive" => $category,
  279.             "subCategoryActive" => $subCategory,
  280.             "limit" => $limit,
  281.             "totalProducts" => $totalProducts
  282.         ));
  283.     }
  284.     /**
  285.      * @Route("/product/{catSlug}/{subCatSlug}/{slug}", name="front_product")
  286.      */
  287.     public function product(ManagerRegistry $managerRegistryRequest $request$catSlug$subCatSlugProductTranslation $productTranslation)
  288.     {
  289.         $product $productTranslation->getTranslatable();
  290.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  291.         $subCategory $repoSubCategory->search(["slug" => $subCatSlug"limit" => 1]);
  292.         return $this->render('front/product.html.twig', array(
  293.             "product" => $product,
  294.             "subCategory" => $subCategory,
  295.         ));
  296.     }
  297.     /**
  298.      * @Route("/application/{slug}", name="front_sub_category")
  299.      */
  300.     public function subCategory(ManagerRegistry $managerRegistryRequest $requestSubCategoryTranslation $subCategoryTranslation)
  301.     {
  302.         $subCategory $subCategoryTranslation->getTranslatable();
  303.         return $this->render('front/subCategory.html.twig', array(
  304.             "subCategory" => $subCategory
  305.         ));
  306.     }
  307.     /**
  308.      * @Route("/legal-notice", name="front_privacy_policy")
  309.      */
  310.     public function privacyPolicy(ManagerRegistry $managerRegistryRequest $request)
  311.     {
  312.         return $this->render('front/privacyPolicy.html.twig', array());
  313.     }
  314.     /**
  315.      * @Route("/publications/{slug}", name="front_publications")
  316.      */
  317.     public function publications(ManagerRegistry $managerRegistryRequest $requestCategoryTranslation $categoryTranslation)
  318.     {
  319.         $category $categoryTranslation->getTranslatable();
  320.         $repoPublication $managerRegistry->getRepository(Publication::class);
  321.         $publicationsFilterForm $this->createForm(PublicationsFilterType::class);
  322.         $publicationsFilterForm->handleRequest($request);
  323.         $data = ["category" => $category"orderBys" => ["pc.position" => "asc""a.position" => "desc"]];
  324.         if ($publicationsFilterForm->isSubmitted() && $publicationsFilterForm->isValid()) {
  325.             $data["search"] = $publicationsFilterForm["search"]->getData();
  326.         }
  327.         $publications $repoPublication->search($data);
  328.         $publicationsClean = [];
  329.         foreach ($publications as $key => $publication) {
  330.             $publicationCategory $publication->getPublicationCategory();
  331.             if (isset($publicationsClean[$publicationCategory->getId()])) {
  332.                 $publicationsClean[$publicationCategory->getId()]["publications"][] = $publication;
  333.             } else {
  334.                 $publicationsClean[$publicationCategory->getId()] = [
  335.                     "publicationCategory" => $publicationCategory,
  336.                     "publications" => [$publication]
  337.                 ];
  338.             }
  339.         }
  340.         return $this->render('front/publications.html.twig', array(
  341.             'publicationsFilterForm' => $publicationsFilterForm->createView(),
  342.             "category" => $category,
  343.             "publicationCleans" => $publicationsClean,
  344.         ));
  345.     }
  346.     /**
  347.      * @Route("/landing/{slug}", name="front_landing_page")
  348.      */
  349.     public function landingPage(ManagerRegistry $managerRegistryRequest $requestLandingPage $landingPage)
  350.     {
  351.         $repoCategory $managerRegistry->getRepository(Category::class);
  352.         $categories $repoCategory->findBy([], ["position" => "asc"]);
  353.         return $this->render('front/landingPage.html.twig', array(
  354.             "categories" => $categories,
  355.             "landingPage" => $landingPage,
  356.         ));
  357.     }
  358.     /**
  359.      * @Route("/", name="front_landing")
  360.      */
  361.     public function landing(Request $requestManagerRegistry $managerRegistry): Response
  362.     {
  363.         $repoPartner $managerRegistry->getRepository(Partner::class);
  364.         $dataPartners = ["type" => "Customer"];
  365.         if ($request->getLocale() == "zh") {
  366.             $dataPartners["isChinese"] = true;
  367.         }
  368.         $partners $repoPartner->findBy($dataPartners, ["position" => "asc"]);
  369.         $repoPost $managerRegistry->getRepository(Post::class);
  370.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  371.         $data["orderBy"] = ["a.date""desc"];
  372.         $data["isPublished"] = true;
  373.         $data["limit"] = 3;
  374.         $posts $repoPost->search($data);
  375.         $repoTestimonial $managerRegistry->getRepository(Testimonial::class);
  376.         $testimonials $repoTestimonial->findBy([], ["position" => "asc"]);
  377.         $repoCategory $managerRegistry->getRepository(Category::class);
  378.         $categories $repoCategory->findBy([], ["position" => "asc"]);
  379.         $repoPublication $managerRegistry->getRepository(Publication::class);
  380.         $publications $repoPublication->findBy(["displayOnLanding" => true], ["position" => "asc"]);
  381.         $landingContact = new LandingContact();
  382.         $landingContactForm $this->createForm(LandingContactType::class, $landingContact);
  383.         $landingContactForm->handleRequest($request);
  384.         if ($landingContactForm->isSubmitted() && $landingContactForm->isValid()) {
  385.             $em $managerRegistry->getManager();
  386.             $em->persist($landingContact);
  387.             $em->flush();
  388.             $this->addFlash("success""landing.catalog.success");
  389.             return $this->redirectToRoute('front_landing');
  390.         }
  391.         $repoCatalog $managerRegistry->getRepository(Catalog::class);
  392.         $catalogs $repoCatalog->findAll();
  393.         return $this->render('front/landing.html.twig', [
  394.             'landingContactForm' => $landingContactForm->createView(),
  395.             "posts" => $posts,
  396.             "partners" => $partners,
  397.             "testimonials" => $testimonials,
  398.             "categories" => $categories,
  399.             "publications" => $publications,
  400.             "catalogs" => $catalogs,
  401.         ]);
  402.     }
  403.     /**
  404.      * @Route("/offres-d-emploi", name="front_job_offers")
  405.      */
  406.     public function jobOffers(ManagerRegistry $managerRegistryRequest $request)
  407.     {
  408.         $repoJobOffer $managerRegistry->getRepository(JobOffer::class);
  409.         $jobOffers $repoJobOffer->findBy([], ["position" => "asc"]);
  410.         return $this->render('front/jobOffers.html.twig', array(
  411.             "jobOffers" => $jobOffers
  412.         ));
  413.     }
  414.     /**
  415.      * @Route("/offre-d-emploi/{slug}", name="front_job_offer")
  416.      */
  417.     public function jobOffer(ManagerRegistry $managerRegistryRequest $requestJobOfferTranslation $jobOfferTranslation)
  418.     {
  419.         $jobOffer $jobOfferTranslation->getTranslatable();
  420.         $repoJobOfferParagraph $managerRegistry->getRepository(JobOfferParagraph::class);
  421.         $jobOfferParagraphs $repoJobOfferParagraph->findBy(["jobOffer" => $jobOffer], ["position" => "asc"]);
  422.         return $this->render('front/jobOffer.html.twig', array(
  423.             "jobOffer" => $jobOffer,
  424.             "jobOfferParagraphs" => $jobOfferParagraphs,
  425.         ));
  426.     }
  427.     /**
  428.      * @Route("/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
  429.      */
  430.     public function sitemap(Request $requestPackages $packages)
  431.     {
  432.         $repoPage $this->getDoctrine()->getRepository(Page::class);
  433.         $page $repoPage->search(["notNull" => ["a.sitemapFileName"], "limit" => 1]);
  434.         if ($page and $page->getSitemapFileName()) {
  435.             return $this->redirect($packages->getUrl('upload/sitemap/' $page->getSitemapFileName()));
  436.         } else {
  437.             return $this->redirectToRoute('front_landing');
  438.         }
  439.     }
  440.     /**
  441.      * @Route("/support", name="front_support")
  442.      */
  443.     public function support(ManagerRegistry $managerRegistryTranslatorInterface $translatorRequest $request)
  444.     {
  445.         $support = new Support();
  446.         $supportForm $this->createForm(SupportType::class, $support);
  447.         $supportForm->handleRequest($request);
  448.         if ($supportForm->isSubmitted() && $supportForm->isValid()) {
  449.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  450.             $isRecaptchaValid false;
  451.             if ($recaptchaResponse) {
  452.                 $paramsArr = array(
  453.                     "response" => $recaptchaResponse,
  454.                     "secret" => $this->getParameter('recaptchaSecret')
  455.                 );
  456.                 $ch curl_init();
  457.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  458.                 curl_setopt($chCURLOPT_POST1);
  459.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  460.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  461.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  462.             }
  463.             if (!$isRecaptchaValid) {
  464.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  465.             } else {
  466.                 $em $managerRegistry->getManager();
  467.                 $em->persist($support);
  468.                 $em->flush();
  469.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  470.                 $mailer = new Mailer($transport);
  471.                 $email = (new TemplatedEmail())
  472.                     ->from($this->getParameter('mailer_user'))
  473.                     ->to("all_support@viewpoint.fr")
  474.                     ->subject("Nouveau message - Support")
  475.                     // path of the Twig template to render
  476.                     ->htmlTemplate('mail/support.html.twig')
  477.                     // pass variables (name => value) to the template
  478.                     ->context(["support" => $support]);
  479.                 //  foreach ($contact->getCustomFiles() as $key => $customFile) {
  480.                 //    $email->attachFromPath(("upload/customFile/" . $customFile->getCustomFileFileName()));
  481.                 // }
  482.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  483.                 $twigEnv = new Environment($loader);
  484.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  485.                 $twigBodyRenderer->render($email);
  486.                 $mailer->send($email);
  487.                 $this->addFlash("success""flash.support.success");
  488.             }
  489.             return $this->redirectToRoute('front_support');
  490.         }
  491.         return $this->render('front/support.html.twig', array(
  492.             'supportForm' => $supportForm->createView(),
  493.         ));
  494.     }
  495.     /**
  496.      * @Route("/contact/{slug}/{isDemo}", name="front_contact", defaults={"slug":null})
  497.      */
  498.     public function contact(Request $requestManagerRegistry $managerRegistryTranslatorInterface $translatorProductTranslation $productTranslation null$isDemo false)
  499.     {
  500.         $product $productTranslation $productTranslation->getTranslatable() : null;
  501.         $contact = new Contact();
  502.         if ($product) {
  503.             $contact->setMessage($isDemo $translator->trans("contact.message_product_demo", ["%product%" => $product->getTitle()]) : $translator->trans("contact.message_product", ["%product%" => $product->getTitle()]));
  504.         }
  505.         $contactForm $this->createForm(ContactType::class, $contact);
  506.         $contactForm->handleRequest($request);
  507.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  508.             // If we have a middlename (which is a hidden field), we silently fail
  509.             // This should help detect bots I hope
  510.             if ($contactForm->get('middlename')->getData()) {
  511.                 $this->addFlash("success""Message envoyé.");
  512.                 return $this->redirectToRoute('front_contact');
  513.             }
  514.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  515.             $isRecaptchaValid false;
  516.             if ($recaptchaResponse) {
  517.                 $paramsArr = array(
  518.                     "response" => $recaptchaResponse,
  519.                     "secret" => $this->getParameter('recaptchaSecret')
  520.                 );
  521.                 $ch curl_init();
  522.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  523.                 curl_setopt($chCURLOPT_POST1);
  524.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  525.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  526.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  527.             }
  528.             if (!$isRecaptchaValid) {
  529.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  530.             } else {
  531.                 $em $managerRegistry->getManager();
  532.                 $em->persist($contact);
  533.                 $em->flush();
  534.                 $this->addFlash("success""Message envoyé.");
  535.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  536.                 $mailer = new Mailer($transport);
  537.                 $subject = ($contact->getSubject() . " - " $contact->getFirstname() . " " $contact->getLastname() . " - " $contact->getCountry() . " - " . ($product $product->getTitle() : null));
  538.                 $email = (new TemplatedEmail())
  539.                     ->from($this->getParameter('mailer_user'))
  540.                     ->to($translator->trans("customer_email"))
  541.                     ->subject($subject)
  542.                     // path of the Twig template to render
  543.                     ->htmlTemplate('mail/contact.html.twig')
  544.                     // pass variables (name => value) to the template
  545.                     ->context(["contact" => $contact]);
  546.                 if ($contact->getEmail()) {
  547.                     $email
  548.                         ->replyTo($contact->getEmail());
  549.                 }
  550.                 foreach ($contact->getCustomFiles() as $key => $customFile) {
  551.                     $email->attachFromPath(("upload/customFile/" $customFile->getCustomFileFileName()));
  552.                 }
  553.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  554.                 $twigEnv = new Environment($loader);
  555.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  556.                 $twigBodyRenderer->render($email);
  557.                 $mailer->send($email);
  558.                 return $this->redirectToRoute('front_contact');
  559.             }
  560.         }
  561.         $repoSetting $managerRegistry->getRepository(Setting::class);
  562.         $setting $repoSetting->findOneBy([]);
  563.         return $this->render('front/contact.html.twig', array(
  564.             'contactForm' => $contactForm->createView(),
  565.             'setting' => $setting,
  566.         ));
  567.     }
  568.     /**
  569.      * @Route("/sitemap", name="front_sitemap_links")
  570.      */
  571.     public function sitemapLinks(ManagerRegistry $managerRegistryRequest $request)
  572.     {
  573.         return $this->render('front/sitemapLinks.html.twig', array());
  574.     }
  575.     /**
  576.      * @Route("/notre-equipe", name="front_members")
  577.      */
  578.     public function members(ManagerRegistry $managerRegistryRequest $request)
  579.     {
  580.         $repoMember $managerRegistry->getRepository(Member::class);
  581.         $members $repoMember->findBy([], ["position" => "asc"]);
  582.         return $this->render('front/members.html.twig', array(
  583.             "members" => $members
  584.         ));
  585.     }
  586.     /**
  587.      * @Route("/news", name="front_posts")
  588.      */
  589.     public function posts(Request $requestPaginatorInterface $paginatorManagerRegistry $managerRegistry)
  590.     {
  591.         $repoPost $managerRegistry->getRepository(Post::class);
  592.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  593.         $data["orderBy"] = ["a.date""desc"];
  594.         $data["isPublished"] = true;
  595.         $postsLimit 12;
  596.         $data["limit"] = $postsLimit;
  597.         $postsFilterForm $this->createForm(PostsFilterType::class);
  598.         $postsFilterForm->handleRequest($request);
  599.         if ($postsFilterForm->isSubmitted() && $postsFilterForm->isValid()) {
  600.             $data array_merge($data$postsFilterForm->getData());
  601.         }
  602.         $posts $repoPost->search($data);
  603.         return $this->render('front/posts.html.twig', array(
  604.             'postsFilterForm' => $postsFilterForm->createView(),
  605.             "posts" => $posts,
  606.             "postsLimit" => $postsLimit
  607.         ));
  608.     }
  609.     /**
  610.      * @Route("/navbar-search", name="front_navbar_search")
  611.      */
  612.     public function navbarSearch(ManagerRegistry $managerRegistryRequest $request)
  613.     {
  614.         $query $request->query->get('nav-search');
  615.         $repoPost $managerRegistry->getRepository(Post::class);
  616.         $data["search"] = $query;
  617.         $data["isPublished"] = true;
  618.         $data["orderBy"] = ["a.date""asc"];
  619.         $posts $repoPost->search($data);
  620.         $repoProduct $managerRegistry->getRepository(Product::class);
  621.         $products $repoProduct->search(["search" => $query"hide" => false"orderBy" => ["a.position""asc"]]);
  622.         return $this->render('front/navbarSearch.html.twig', array(
  623.             "posts" => $posts,
  624.             "products" => $products,
  625.             "navSearchQuery" => $query
  626.         ));
  627.     }
  628.     /**
  629.      * @Route("/news/{slug}", name="front_post")
  630.      */
  631.     public function post(Request $requestManagerRegistry $managerRegistrystring $slug)
  632.     {
  633.         $repoPostTranslation $managerRegistry->getRepository(PostTranslation::class);
  634.         $postTranslation $repoPostTranslation->findOneBy(["slug" => $slug]);
  635.         if ($postTranslation and $post $postTranslation->getTranslatable()) {
  636.             if ($post->getIsPublished() or $this->isGranted("ROLE_ADMIN")) {
  637.                 $repoParagraph $managerRegistry->getRepository(Paragraph::class);
  638.                 $paragraphs $repoParagraph->findBy(["post" => $post], ["position" => "asc"]);
  639.                 $repoPostMedia $managerRegistry->getRepository(PostMedia::class);
  640.                 $postMedias $repoPostMedia->findBy(["post" => $post], ["position" => "asc"]);
  641.                 $repoPost $managerRegistry->getRepository(Post::class);
  642.                 $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  643.                 $data["orderBy"] = ["a.date""desc"];
  644.                 $data["isPublished"] = true;
  645.                 $data["limit"] = 3;
  646.                 $posts $repoPost->search($data);
  647.                 return $this->render('front/post.html.twig', array(
  648.                     "posts" => $posts,
  649.                     "post" => $post,
  650.                     "paragraphs" => $paragraphs,
  651.                     "postMedias" => $postMedias,
  652.                 ));
  653.             } else {
  654.                 $this->addFlash("danger""flash.not_allowed_post");
  655.                 return $this->redirectToRoute('front_posts');
  656.             }
  657.         } else {
  658.             $this->addFlash("danger""flash.post_not_found");
  659.             return $this->redirectToRoute('front_posts');
  660.         }
  661.     }
  662.     /**
  663.      * @Route("/inscription-newsletter", name="front_subscribe_newsletter")
  664.      */
  665.     public function subscribeNewsletter(ManagerRegistry $managerRegistryRequest $requestAppService $appService)
  666.     {
  667.         $newsletter = new Newsletter();
  668.         $newsletterForm $this->createForm(NewsletterType::class, $newsletter);
  669.         $newsletterForm->handleRequest($request);
  670.         $em $managerRegistry->getManager();
  671.         if ($newsletterForm->isSubmitted() && $newsletterForm->isValid()) {
  672.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  673.             $isRecaptchaValid false;
  674.             if ($recaptchaResponse) {
  675.                 $paramsArr = array(
  676.                     "response" => $recaptchaResponse,
  677.                     "secret" => $this->getParameter('recaptchaSecret')
  678.                 );
  679.                 $ch curl_init();
  680.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  681.                 curl_setopt($chCURLOPT_POST1);
  682.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  683.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  684.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  685.             }
  686.             if (!$isRecaptchaValid) {
  687.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  688.             } else {
  689.                 $mj = new \Mailjet\Client($this->getParameter('mj_apikey_public'), $this->getParameter('mj_apikey_private'), true, ['version' => 'v3']);
  690.                 $body = [
  691.                     //                'IsExcludedFromCampaigns' => "true",
  692.                     'Name' => $newsletter->getName(),
  693.                     'Email' => $newsletter->getEmail()
  694.                 ];
  695.                 $response $mj->post(Resources::$Contact, ['body' => $body]);
  696.                 $em->persist($newsletter);
  697.                 $em->flush();
  698.                 $this->addFlash("success""flash.newsletter.success");
  699.                 return $this->redirectToRoute('front_landing');
  700.             }
  701.         }
  702.         return $this->render('form/newsletterForm.html.twig', array(
  703.             'newsletterForm' => $newsletterForm->createView(),
  704.         ));
  705.     }
  706.     /**
  707.      * @Route("/admin/fsdhj78Hjkdfsb0920dfjdfhq87djhaoppsnv720", name="front_clear_cache")
  708.      */
  709.     public function clearCache(Request $requestKernelInterface $kernel)
  710.     {
  711.         $application = new FrameworkApplication($kernel);
  712.         $application->setAutoExit(false);
  713.         $input = new ArrayInput([
  714.             'command' => 'cache:clear',
  715.         ]);
  716.         // You can use NullOutput() if you don't need the output
  717.         $output = new NullOutput();
  718.         $application->run($input$output);
  719.         $this->addFlash("success""Le cache a bien été nettoyé, les traductions sont à jour !");
  720.         return $this->redirectToRoute('front_landing');
  721.     }
  722. }