src/Controller/FrontController.php line 168

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Accessoire;
  4. use App\Entity\AccessoireProduit;
  5. use App\Entity\AccessoireTranslation;
  6. use App\Entity\Caracteristique;
  7. use App\Entity\CaracteristiqueProduit;
  8. use App\Entity\CaracteristiqueTranslation;
  9. use App\Entity\Category;
  10. use App\Entity\Coloris;
  11. use App\Entity\ColorisCategory;
  12. use App\Entity\Contact;
  13. use App\Entity\ExpertiseParagraph;
  14. use App\Entity\FaqCategory;
  15. use App\Entity\FicheTechnique;
  16. use App\Entity\Gamme;
  17. use App\Entity\Member;
  18. use App\Entity\Newsletter;
  19. use App\Entity\Page;
  20. use App\Entity\Paragraph;
  21. use App\Entity\Partner;
  22. use App\Entity\Post;
  23. use App\Entity\PostTranslation;
  24. use App\Entity\Product;
  25. use App\Entity\ProductColoris;
  26. use App\Entity\ProductColorisOption;
  27. use App\Entity\ProductMedia;
  28. use App\Entity\ProductTranslation;
  29. use App\Entity\ServiceParagraph;
  30. use App\Entity\Setting;
  31. use App\Entity\SubCategory;
  32. use App\Entity\SubCategoryTranslation;
  33. use App\Entity\Testimonial;
  34. use App\Form\ContactType;
  35. use App\Form\NewsletterType;
  36. use App\Form\ProductsFilterType;
  37. use App\Service\AppService;
  38. use Doctrine\Persistence\ManagerRegistry;
  39. use Knp\Component\Pager\PaginatorInterface;
  40. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  41. use Symfony\Bridge\Twig\Mime\BodyRenderer;
  42. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  43. use Symfony\Bundle\FrameworkBundle\Console\Application as FrameworkApplication;
  44. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  45. use Symfony\Component\Asset\Packages;
  46. use Symfony\Component\Console\Input\ArrayInput;
  47. use Symfony\Component\Console\Output\NullOutput;
  48. use Symfony\Component\HttpFoundation\Request;
  49. use Symfony\Component\HttpFoundation\Response;
  50. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  51. use Symfony\Component\HttpKernel\KernelInterface;
  52. use Symfony\Component\Mailer\Mailer;
  53. use Symfony\Component\Mailer\MailerInterface;
  54. use Symfony\Component\Mailer\Transport;
  55. use Symfony\Component\Mime\Email;
  56. use Symfony\Component\Routing\Annotation\Route;
  57. use Twig\Environment;
  58. use Twig\Loader\FilesystemLoader;
  59. class FrontController extends AbstractController
  60. {
  61.     /**
  62.      * @Route("/changer-la-langue/{locale}/{redirectUrl}", name="front_change_language", requirements={"redirectUrl"=".+"})
  63.      */
  64.     public function changeLanguage(Request $requestSessionInterface $session$locale$redirectUrl null)
  65.     {
  66.         $session->set('_locale'$locale);
  67.         if ($redirectUrl == "front_product") {
  68.             return $this->redirectToRoute("front_products", ['_locale' => $locale]);
  69.         } elseif ($redirectUrl == "front_post") {
  70.             return $this->redirectToRoute("front_posts", ['_locale' => $locale]);
  71.         }
  72.         return $this->redirectToRoute($redirectUrl, ['_locale' => $locale]);
  73.     }
  74.     /**
  75.      * @Route({
  76.      *     "fr": "/societe/presentation",
  77.      *     "en": "/company/who-are-we"
  78.      * }, name="front_who_are_we")
  79.      */
  80.     public function whoAreWe(ManagerRegistry $managerRegistryRequest $request)
  81.     {
  82.         $repoSetting $managerRegistry->getRepository(Setting::class);
  83.         $setting $repoSetting->findOneBy([]);
  84.         return $this->render('front/whoAreWe.html.twig', array(
  85.             "setting" => $setting
  86.         ));
  87.     }
  88.     /**
  89.      * @Route({
  90.      *     "fr": "/societe/expertises",
  91.      *     "en": "/company/expertises"
  92.      * }, name="front_expertises")
  93.      */
  94.     public function expertises(ManagerRegistry $managerRegistryRequest $request)
  95.     {
  96.         $repoExpertiseParagraph $managerRegistry->getRepository(ExpertiseParagraph::class);
  97.         $expertiseParagraphs $repoExpertiseParagraph->findBy([], ["position" => "asc"]);
  98.         return $this->render('front/expertises.html.twig', array(
  99.             "expertiseParagraphs" => $expertiseParagraphs
  100.         ));
  101.     }
  102.     /**
  103.      * @Route({
  104.      *     "fr": "/societe/services",
  105.      *     "en": "/company/services"
  106.      * }, name="front_services")
  107.      */
  108.     public function services(ManagerRegistry $managerRegistryRequest $request)
  109.     {
  110.         $repoServiceParagraph $managerRegistry->getRepository(ServiceParagraph::class);
  111.         $serviceParagraphs $repoServiceParagraph->findBy([], ["position" => "asc"]);
  112.         return $this->render('front/services.html.twig', array(
  113.             "serviceParagraphs" => $serviceParagraphs
  114.         ));
  115.     }
  116.     /**
  117.      * @Route({
  118.      *     "fr": "/produits/{catSlug}/{subCatSlug}",
  119.      *     "en": "/products/{catSlug}/{subCatSlug}"
  120.      * }, name="front_products")
  121.      */
  122.     public function products(ManagerRegistry $managerRegistryPaginatorInterface $paginatorRequest $request$subCatSlug null$catSlug null)
  123.     {
  124.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  125.         $subCategory $repoSubCategory->search(["slug" => $subCatSlug"limit" => 1]);
  126.         $repoCategory $managerRegistry->getRepository(Category::class);
  127.         $category $subCategory $subCategory->getCategory() : $repoCategory->search(["slug" => $catSlug"limit" => 1]);
  128. //        $data["orderBys"] = ["a.category" => "asc", "a.subCategory" => "asc", "a.gamme" => "asc"];
  129.         $data["orderBys"] = ["a.id" => "asc"];
  130.         $data["limit"] = 15;
  131.         $data["searchProducts"] = ["categories" => [], "subCategories" => []];
  132.         if (!$request->isXmlHttpRequest()) {
  133.             if ($subCategory) {
  134.                 $data["searchProducts"]["subCategories"][] = $subCategory;
  135.             }
  136.             if ($category) {
  137.                 $data["searchProducts"]["categories"][] = $category;
  138.             }
  139.         }
  140.         $productsFilterForm $this->createForm(ProductsFilterType::class);
  141.         $productsFilterForm->handleRequest($request);
  142.         if ($productsFilterForm->isSubmitted() && $productsFilterForm->isValid()) {
  143.             $data["searchProducts"] = $productsFilterForm->getData();
  144.         }
  145.         $repoProduct $managerRegistry->getRepository(Product::class);
  146.         $products $repoProduct->search($data);
  147.         $products = (is_array($products) ? $products : ($products ? [$products] : []));
  148.         return $this->render('front/products.html.twig', array(
  149.             'productsFilterForm' => $productsFilterForm->createView(),
  150.             "products" => $products,
  151.             "categoryActive" => $category,
  152.             "subCategoryActive" => $subCategory,
  153.         ));
  154.     }
  155.     /**
  156.      * @Route("/inscription-newsletter", name="front_subscribe_newsletter")
  157.      */
  158.     public function subscribeNewsletter(ManagerRegistry $managerRegistryRequest $requestAppService $appService)
  159.     {
  160.         $newsletter = new Newsletter();
  161.         $newsletterForm $this->createForm(NewsletterType::class, $newsletter);
  162.         $newsletterForm->handleRequest($request);
  163.         $em $managerRegistry->getManager();
  164.         if ($newsletterForm->isSubmitted() && $newsletterForm->isValid()) {
  165.             $appService->suscribeToList($newsletter->getEmail());
  166.             $em->persist($newsletter);
  167.             $em->flush();
  168.             $this->addFlash("success""flash.newsletter.success");
  169.             return $this->redirectToRoute('front_landing');
  170.         }
  171.         return $this->render('form/newsletterForm.html.twig', array(
  172.             'newsletterForm' => $newsletterForm->createView(),
  173.         ));
  174.     }
  175.     /**
  176.      * @Route("/fdskj986765GDHOjfdkfhjr87890", name="front_import_products_csv")
  177.      */
  178.     public function importProductsCsv(ManagerRegistry $managerRegistryRequest $request)
  179.     {
  180.         dump("cancel");
  181.         exit;
  182.         $row 1;
  183.         $repoCategory $managerRegistry->getRepository(Category::class);
  184.         $repoSubCategory $managerRegistry->getRepository(SubCategory::class);
  185.         $repoGamme $managerRegistry->getRepository(Gamme::class);
  186.         $repoColoris $managerRegistry->getRepository(Coloris::class);
  187.         $repoCaracteristique $managerRegistry->getRepository(Caracteristique::class);
  188.         $repoCaracteristiqueProduit $managerRegistry->getRepository(CaracteristiqueProduit::class);
  189.         $repoCaracteristiqueTranslation $managerRegistry->getRepository(CaracteristiqueTranslation::class);
  190.         $repoAccessoire $managerRegistry->getRepository(Accessoire::class);
  191.         $repoProduct $managerRegistry->getRepository(Product::class);
  192.         $em $managerRegistry->getManager();
  193.         for ($i 0$i 2$i++) {
  194.             $nbColonnesAttributs = ($i 14 10);
  195.             if (($handle fopen("products" . ($i "1" "") . ".csv""r")) !== FALSE) {
  196.                 $attributes = [];
  197.                 while (($data fgetcsv($handle0",")) !== FALSE) {
  198.                     if ($row == 1) {
  199.                         for ($j 18$j < (18 $nbColonnesAttributs); $j++) {
  200.                             $attribute explode("("$data[$j]);
  201.                             $attribute explode(")"$attribute[1]);
  202.                             $attribute $attribute[0];
  203.                             $attributes[] = $attribute;
  204.                         }
  205.                     }
  206.                     if ($row 1) {
  207.                         $product = new Product();
  208.                         $em->persist($product);
  209.                         $category $repoCategory->search(["limit" => 1"title" => trim($data[0])]);
  210.                         $product->setCategory($category);
  211.                         $subCategory $repoSubCategory->search(["limit" => 1"title" => trim($data[1])]);
  212.                         $product->setSubCategory($subCategory);
  213.                         $gamme $repoGamme->search(["limit" => 1"title" => trim($data[2])]);
  214.                         $product->setGamme($gamme);
  215.                         $product->translate('fr')->setTitle(trim($data[3]));
  216.                         $product->setReference(trim($data[4]));
  217.                         $product->translate('fr')->setIntro(trim($data[5]));
  218.                         $product->translate('fr')->setDescription(trim($data[6]));
  219.                         $colorisArr array_merge(explode(","$data[8]), explode(","$data[12]));
  220.                         $colorisOptionArr array_merge(explode(","$data[10]), explode(","$data[14]));
  221.                         foreach ([$colorisArr$colorisOptionArr] as $key1 => $colSerOpt) {
  222.                             $isOption = ($key1 == 1);
  223.                             foreach ($colSerOpt as $key => $colorisTitle) {
  224.                                 $coloris $repoColoris->search(["limit" => 1"title" => trim($colorisTitle)]);
  225.                                 if ($coloris) {
  226.                                     $productColoris = ($isOption ? new ProductColorisOption() : new ProductColoris());
  227.                                     $productColoris->setProduct($product);
  228.                                     $productColoris->setColoris($coloris);
  229.                                     $em->persist($productColoris);
  230.                                 }
  231.                             }
  232.                         }
  233.                         $product->translate('fr')->setInfo(trim($data[15]));
  234.                         $caracteristiques explode("\n"$data[16]);
  235.                         $caracteristiquesValues explode("\n"$data[17]);
  236.                         foreach ([$caracteristiques$attributes] as $key => $carAtt) {
  237.                             $isFilter = ($key == 1);
  238.                             foreach ($carAtt as $key => $caracteristiqueTitle) {
  239.                                 $caracteristiqueTitle trim($caracteristiqueTitle);
  240.                                 $caracteristique $repoCaracteristique->search(["limit" => 1"title" => $caracteristiqueTitle]);
  241.                                 if (!$caracteristique) {
  242.                                     $caracteristique = new Caracteristique();
  243.                                     $caracteristique->translate('fr')->setTitle($caracteristiqueTitle);
  244.                                     $caracteristique->mergeNewTranslations();
  245.                                     $em->persist($caracteristique);
  246.                                 }
  247.                                 $caracteristique->setIsFilter($isFilter);
  248.                                 $carAttrValue = ($isFilter $data[(18 $key)] : (isset($caracteristiquesValues[$key]) ? $caracteristiquesValues[$key] : null));
  249.                                 if ($carAttrValue) {
  250.                                     $caracteristiqueProduit $repoCaracteristiqueProduit->findOneBy(["caracteristique" => $caracteristique"product" => $product"locale" => "fr"]) ?? new CaracteristiqueProduit();
  251.                                     $caracteristiqueProduit->setProduct($product);
  252.                                     $caracteristiqueProduit->setCaracteristique($caracteristique);
  253.                                     $caracteristiqueProduit->setLocale("fr");
  254.                                     $caracteristiqueProduit->setTitle(trim($carAttrValue));
  255.                                     $em->persist($caracteristiqueProduit);
  256.                                 }
  257.                                 $product->mergeNewTranslations();
  258.                                 $em->flush();
  259.                             }
  260.                         }
  261.                         $mediasArr explode("\n"$data[(18 $nbColonnesAttributs)]);
  262.                         $mediasArr[] = $data[(20 $nbColonnesAttributs)];
  263.                         foreach ($mediasArr as $key => $productMediaFileName) {
  264.                             $productMedia = new ProductMedia();
  265.                             $productMedia->setProduct($product);
  266.                             $productMedia->translate('fr')->setTitle(trim($productMediaFileName));
  267.                             $productMedia->translate('en')->setTitle(trim($productMediaFileName));
  268.                             $productMedia->setProductMediaFileName(trim($productMediaFileName));
  269.                             $productMedia->mergeNewTranslations();
  270.                             $em->persist($productMedia);
  271.                         }
  272.                         $ficheTechnique = new FicheTechnique();
  273.                         $ficheTechnique->setLocale("fr");
  274.                         $ficheTechnique->setProduct($product);
  275.                         $ficheTechnique->setFicheTechniqueFileName(trim($data[(19 $nbColonnesAttributs)]));
  276.                         $product->setProductCe(($data[(21 $nbColonnesAttributs)] == "logo CE"));
  277.                         $product->setFabricationFrancaise(($data[(22 $nbColonnesAttributs)] == "oui"));
  278.                         $em->persist($ficheTechnique);
  279.                         $product->mergeNewTranslations();
  280.                     }
  281.                     $row++;
  282.                 }
  283.                 $em->flush();
  284.                 fclose($handle);
  285.             }
  286.             if (($handle fopen("products" . ($i "1" "") . "_en.csv""r")) !== FALSE) {
  287.                 $row 1;
  288.                 $attributes = [];
  289.                 while (($data fgetcsv($handle0",")) !== FALSE) {
  290.                     if ($row == 1) {
  291.                         for ($j 18$j < (18 $nbColonnesAttributs); $j++) {
  292.                             $attribute explode("("$data[$j]);
  293.                             $attribute explode(")"$attribute[1]);
  294.                             $attribute $attribute[0];
  295.                             $attributes[] = $attribute;
  296.                         }
  297.                     }
  298.                     if ($row 1) {
  299.                         $product $repoProduct->findOneBy(["reference" => trim($data[4])]);
  300.                         if ($product) {
  301.                             $productTranslation = new ProductTranslation();
  302.                             $productTranslation->setTranslatable($product);
  303.                             $productTranslation->setLocale("en");
  304.                             $productTranslation->setTitle(trim($data[3]));
  305.                             $productTranslation->setIntro(trim($data[5]));
  306.                             $productTranslation->setDescription(trim($data[6]));
  307.                             $productTranslation->setInfo(trim($data[15]));
  308.                             $em->persist($productTranslation);
  309.                             $caracteristiques explode("\n"$data[16]);
  310.                             $caracteristiquesValues explode("\n"$data[17]);
  311.                             $attributesClean = [];
  312.                             $attributesValClean = [];
  313.                             foreach ($attributes as $key => $attribute) {
  314.                                 if ($data[(18 $key)]) {
  315.                                     $attributesClean[] = $attribute;
  316.                                     $attributesValClean[] = $data[(18 $key)];
  317.                                 }
  318.                             }
  319.                             $carAttrVal array_merge($caracteristiquesValues$attributesValClean);
  320.                             $carAttr array_merge($caracteristiques$attributesClean);
  321.                             $caracteristiqueProduits $repoCaracteristiqueProduit->findBy(["product" => $product], ["position" => 'asc']);
  322.                             foreach ($caracteristiqueProduits as $key => $caracteristiqueProduit) {
  323.                                 $caracteristique $caracteristiqueProduit->getCaracteristique();
  324.                                 $caracteristiqueTranslation $repoCaracteristiqueTranslation->findOneBy(["translatable" => $caracteristique"locale" => "en"]);
  325.                                 if (!$caracteristiqueTranslation) {
  326.                                     $caracteristiqueTranslation = new CaracteristiqueTranslation();
  327.                                     $caracteristiqueTranslation->setTranslatable($caracteristique);
  328.                                     $caracteristiqueTranslation->setLocale("en");
  329.                                     $caracteristiqueTranslation->setTitle(trim($carAttr[$key]));
  330.                                     $em->persist($caracteristiqueTranslation);
  331.                                 }
  332.                                 $caracteristiqueProduit = new CaracteristiqueProduit();
  333.                                 $caracteristiqueProduit->setProduct($product);
  334.                                 $caracteristiqueProduit->setCaracteristique($caracteristique);
  335.                                 $caracteristiqueProduit->setLocale("en");
  336.                                 $caracteristiqueProduit->setTitle(trim($carAttrVal[$key]));
  337.                                 $em->persist($caracteristiqueProduit);
  338.                                 $em->flush();
  339.                             }
  340.                             $ficheTechnique = new FicheTechnique();
  341.                             $ficheTechnique->setLocale("en");
  342.                             $ficheTechnique->setProduct($product);
  343.                             $ficheTechnique->setFicheTechniqueFileName(trim($data[(19 $nbColonnesAttributs)]));
  344.                             $em->persist($ficheTechnique);
  345.                         }
  346.                     }
  347.                     $row++;
  348.                 }
  349.                 $em->flush();
  350.                 fclose($handle);
  351.             }
  352.         }
  353.         $row 1;
  354.         if (($handle fopen("accessoires.csv""r")) !== FALSE) {
  355.             while (($data fgetcsv($handle0",")) !== FALSE) {
  356.                 if ($row 1) {
  357.                     $accessoire = new Accessoire();
  358.                     $em->persist($accessoire);
  359.                     $productRefs explode("\n"$data[0]);
  360.                     foreach ($productRefs as $key => $productRef) {
  361.                         $product $repoProduct->findOneBy(["reference" => trim($productRef)]);
  362.                         if ($product) {
  363.                             $accessoireProduit = new AccessoireProduit();
  364.                             $accessoireProduit->setAccessoire($accessoire);
  365.                             $accessoireProduit->setProduct($product);
  366.                             $em->persist($accessoireProduit);
  367.                         }
  368.                     }
  369.                     $accessoire->setReference(trim($data[1]));
  370.                     $accessoire->setTitle(trim($data[2]));
  371.                     $accessoire->setAccessoireFileName(trim($data[3]));
  372.                     $accessoire->mergeNewTranslations();
  373.                 }
  374.                 $row++;
  375.             }
  376.             $em->flush();
  377.             fclose($handle);
  378.         }
  379.         $row 1;
  380.         $accessoires $repoAccessoire->findBy([], ["id" => "asc"]);
  381.         if (($handle fopen("accessoires_en.csv""r")) !== FALSE) {
  382.             while (($data fgetcsv($handle0",")) !== FALSE) {
  383.                 if ($row 1) {
  384.                     $accessoire $accessoires[($row 2)];
  385.                     if ($accessoire) {
  386.                         $accessoireTranslation = new AccessoireTranslation();
  387.                         $accessoireTranslation->setTranslatable($accessoire);
  388.                         $accessoireTranslation->setLocale("en");
  389.                         $accessoireTranslation->setTitle(trim($data[2]));
  390.                         $em->persist($accessoireTranslation);
  391.                     }
  392.                 }
  393.                 $row++;
  394.             }
  395.             $em->flush();
  396.             fclose($handle);
  397.         }
  398.         exit;
  399.     }
  400.     /**
  401.      * @Route({
  402.      *     "fr": "/support",
  403.      *     "en": "/faq"
  404.      * }, name="front_faq")
  405.      */
  406.     public function faq(ManagerRegistry $managerRegistryRequest $request)
  407.     {
  408.         $repoFaqCategory $managerRegistry->getRepository(FaqCategory::class);
  409.         $faqCategories $repoFaqCategory->findBy([], ["position" => "asc"]);
  410.         return $this->render('front/faq.html.twig', array(
  411.             "faqCategories" => $faqCategories
  412.         ));
  413.     }
  414.     /**
  415.      * @Route("/fsdhj78Hjkdfsb0920dfjdfhq87djhaoppsnv720", name="front_clear_cache")
  416.      */
  417.     public function clearCache(Request $requestKernelInterface $kernel)
  418.     {
  419.         $application = new FrameworkApplication($kernel);
  420.         $application->setAutoExit(false);
  421.         $input = new ArrayInput([
  422.             'command' => 'cache:clear',
  423.         ]);
  424.         // You can use NullOutput() if you don't need the output
  425.         $output = new NullOutput();
  426.         $application->run($input$output);
  427.         $this->addFlash("success""Le cache a bien été nettoyé, les traductions sont à jour !");
  428.         return $this->redirectToRoute('front_landing');
  429.     }
  430.     /**
  431.      * @Route({
  432.      *     "fr": "/guide-coloris",
  433.      *     "en": "/colors-guide"
  434.      * }, name="front_coloris_guide")
  435.      */
  436.     public function colorisGuide(ManagerRegistry $managerRegistryRequest $request)
  437.     {
  438.         $repoColorisCategory $managerRegistry->getRepository(ColorisCategory::class);
  439.         $colorisCategories $repoColorisCategory->findBy([], ["position" => "asc"]);
  440.         return $this->render('front/colorisGuide.html.twig', array(
  441.             "colorisCategories" => $colorisCategories
  442.         ));
  443.     }
  444.     /**
  445.      * @Route({
  446.      *     "fr": "/produit/{slug}",
  447.      *     "en": "/product/{slug}"
  448.      * }, name="front_product")
  449.      */
  450.     public function product(ManagerRegistry $managerRegistryRequest $requestProductTranslation $productTranslation)
  451.     {
  452.         $repoColorisCategory $managerRegistry->getRepository(ColorisCategory::class);
  453.         $colorisCategories $repoColorisCategory->findBy([], ["position" => "asc"]);
  454.         $product $productTranslation->getTranslatable();
  455.         $repoProductColoris $managerRegistry->getRepository(ProductColoris::class);
  456.         $productColoris $repoProductColoris->findBy(["product" => $product], ["position" => "asc"]);
  457.         $repoProductColorisOption $managerRegistry->getRepository(ProductColorisOption::class);
  458.         $productColorisOptions $repoProductColorisOption->findBy(["product" => $product], ["position" => "asc"]);
  459.         return $this->render('front/product.html.twig', array(
  460.             "product" => $product,
  461.             "colorisCategories" => $colorisCategories,
  462.             "productColoris" => $productColoris,
  463.             "productColorisOptions" => $productColorisOptions,
  464.         ));
  465.     }
  466.     /**
  467.      * @Route({
  468.      *     "fr": "/mentions-legales",
  469.      *     "en": "/legals"
  470.      * }, name="front_privacy_policy")
  471.      */
  472.     public function privacyPolicy(ManagerRegistry $managerRegistryRequest $request)
  473.     {
  474.         return $this->render('front/privacyPolicy.html.twig', array());
  475.     }
  476.     /**
  477.      * @Route("/", name="front_landing")
  478.      */
  479.     public function landing(Request $requestManagerRegistry $managerRegistry): Response
  480.     {
  481.         $repoPartner $managerRegistry->getRepository(Partner::class);
  482.         $partners $repoPartner->findBy([], ["position" => "asc"]);
  483.         $repoPost $managerRegistry->getRepository(Post::class);
  484.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  485.         $data["endDate"] = new \DateTime();
  486.         $data["orderBy"] = ["a.date""desc"];
  487.         $data["isPublished"] = true;
  488.         $data["limit"] = 6;
  489.         $posts $repoPost->search($data);
  490.         $repoTestimonial $managerRegistry->getRepository(Testimonial::class);
  491.         $testimonials $repoTestimonial->findBy([], ["position" => "asc"]);
  492.         $repoProduct $managerRegistry->getRepository(Product::class);
  493.         $products $repoProduct->findBy(["displayOnLanding" => true], ["position" => "asc"], 4);
  494.         $repoCategory $managerRegistry->getRepository(Category::class);
  495.         $categories $repoCategory->findBy([], ["position" => "asc"]);
  496.         return $this->render('front/landing.html.twig', [
  497.             "posts" => $posts,
  498.             "partners" => $partners,
  499.             "testimonials" => $testimonials,
  500.             "products" => $products,
  501.             "categories" => $categories,
  502.         ]);
  503.     }
  504.     /**
  505.      * @Route("/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
  506.      */
  507.     public function sitemap(Request $requestPackages $packages)
  508.     {
  509.         $repoPage $this->getDoctrine()->getRepository(Page::class);
  510.         $page $repoPage->search(["notNull" => ["a.sitemapFileName"], "limit" => 1]);
  511.         if ($page and $page->getSitemapFileName()) {
  512.             return $this->redirect($packages->getUrl('upload/sitemap/' $page->getSitemapFileName()));
  513.         } else {
  514.             return $this->redirectToRoute('front_landing');
  515.         }
  516.     }
  517.     /**
  518.      * @Route({
  519.      *     "fr": "/contact/{slug}",
  520.      *     "en": "/contact-us/{slug}"
  521.      * }, name="front_contact", defaults={"slug":null})
  522.      */
  523.     public function contact(Request $requestManagerRegistry $managerRegistryProductTranslation $productTranslation null)
  524.     {
  525.         $product $productTranslation $productTranslation->getTranslatable() : null;
  526.         $contact = new Contact();
  527.         $contactForm $this->createForm(ContactType::class, $contact, [
  528.             "product" => $product
  529.         ]);
  530.         $contactForm->handleRequest($request);
  531.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  532.             $recaptchaResponse $request->request->get('g-recaptcha-response'null);
  533.             $isRecaptchaValid false;
  534.             if ($recaptchaResponse) {
  535.                 $paramsArr = array(
  536.                     "response" => $recaptchaResponse,
  537.                     "secret" => $this->getParameter('recaptchaSecret')
  538.                 );
  539.                 $ch curl_init();
  540.                 curl_setopt($chCURLOPT_URL"https://www.google.com/recaptcha/api/siteverify");
  541.                 curl_setopt($chCURLOPT_POST1);
  542.                 curl_setopt($chCURLOPT_POSTFIELDShttp_build_query($paramsArr));
  543.                 curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  544.                 $isRecaptchaValid json_decode(curl_exec($ch))->success;
  545.             }
  546.             if (!$isRecaptchaValid) {
  547.                 $this->addFlash("danger""Veuillez recommencer en validant le captcha.");
  548.             } else {
  549.                 $em $managerRegistry->getManager();
  550.                 $em->persist($contact);
  551.                 $em->flush();
  552.                 $this->addFlash("success""Message envoyé.");
  553.                 $transport Transport::fromDsn($this->getParameter('mailer_dsn'));
  554.                 $mailer = new Mailer($transport);
  555.                 $locale $request->getLocale();
  556.                 $email = (new TemplatedEmail())
  557.                     ->from($this->getParameter('mailer_user'))
  558.                     ->to(($locale == "en" "s.ivanoff@carinamedical.com" "commercial@carinamedical.com"))
  559.                     ->subject("Nouveau message")
  560.                     // path of the Twig template to render
  561.                     ->htmlTemplate('mail/contact.html.twig')
  562.                     // pass variables (name => value) to the template
  563.                     ->context(["contact" => $contact]);
  564.                 foreach ($contact->getCustomFiles() as $key => $customFile) {
  565.                     $email->attachFromPath(("upload/customFile/" $customFile->getCustomFileFileName()));
  566.                 }
  567.                 $loader = new FilesystemLoader($this->getParameter('kernel.project_dir') . '/templates/');
  568.                 $twigEnv = new Environment($loader);
  569.                 $twigBodyRenderer = new BodyRenderer($twigEnv);
  570.                 $twigBodyRenderer->render($email);
  571.                 $mailer->send($email);
  572.                 return $this->redirectToRoute('front_contact');
  573.             }
  574.         }
  575.         return $this->render('front/contact.html.twig', array(
  576.             'contactForm' => $contactForm->createView(),
  577.         ));
  578.     }
  579.     /**
  580.      * @Route({
  581.      *     "fr": "/plan-du-site",
  582.      *     "en": "/sitemap"
  583.      * }, name="front_sitemap_links")
  584.      */
  585.     public function sitemapLinks(ManagerRegistry $managerRegistryRequest $request)
  586.     {
  587.         return $this->render('front/sitemapLinks.html.twig', array());
  588.     }
  589.     /**
  590.      * @Route("/notre-equipe", name="front_members")
  591.      */
  592.     public function members(ManagerRegistry $managerRegistryRequest $request)
  593.     {
  594.         $repoMember $managerRegistry->getRepository(Member::class);
  595.         $members $repoMember->findBy([], ["position" => "asc"]);
  596.         return $this->render('front/members.html.twig', array(
  597.             "members" => $members
  598.         ));
  599.     }
  600.     /**
  601.      * @Route({
  602.      *     "fr": "/actualites",
  603.      *     "en": "/news"
  604.      * }, name="front_posts")
  605.      */
  606.     public function posts(Request $requestPaginatorInterface $paginatorManagerRegistry $managerRegistry)
  607.     {
  608.         $repoPost $managerRegistry->getRepository(Post::class);
  609.         $data["between"]["notStrict"]["a.date"]["max"] = new \DateTime();
  610.         $data["endDate"] = new \DateTime();
  611.         $data["orderBy"] = ["a.date""desc"];
  612.         $data["isPublished"] = true;
  613.         $posts $paginator->paginate(
  614.             $repoPost->search($data), $request->query->getInt('page'1)/* page number */6/* limit per page */
  615.         );
  616.         return $this->render('front/posts.html.twig', array(
  617.             "posts" => $posts
  618.         ));
  619.     }
  620.     /**
  621.      * @Route("/navbar-search", name="front_navbar_search")
  622.      */
  623.     public function navbarSearch(ManagerRegistry $managerRegistryRequest $request)
  624.     {
  625.         if ($request->isXmlHttpRequest()) {
  626.             $query $request->request->get('query'null);
  627.             $repoProduct $managerRegistry->getRepository(Product::class);
  628.             $products $repoProduct->search(["search" => $query"orderBy" => ["a.position""asc"]]);
  629.             $response = new Response(json_encode(array(
  630.                 'template' => $this->renderView('front/navbarSearch.html.twig', [
  631.                     "products" => $products,
  632.                 ]),
  633.             )));
  634.             $response->headers->set('Content-Type''application/json');
  635.             return $response;
  636.         }
  637. //        return $this->render('front/navbarSearch.html.twig', array());
  638.     }
  639.     /**
  640.      * @Route("/distributeurs", name="front_distributeurs")
  641.      */
  642.     public function distributeurs(ManagerRegistry $managerRegistryRequest $request)
  643.     {
  644.         return $this->render('front/distributeurs.html.twig', array());
  645.     }
  646.     /**
  647.      * @Route({"en": "/post/{slug}", "fr": "/actualite/{slug}"}, name="front_post")
  648.      */
  649.     public function post(Request $requestManagerRegistry $managerRegistrystring $slug)
  650.     {
  651.         $repoPostTranslation $managerRegistry->getRepository(PostTranslation::class);
  652.         $postTranslation $repoPostTranslation->findOneBy(["slug" => $slug]);
  653.         if ($postTranslation and $post $postTranslation->getTranslatable()) {
  654.             if ($post->getIsPublished() or $this->isGranted("ROLE_ADMIN")) {
  655.                 $repoParagraph $managerRegistry->getRepository(Paragraph::class);
  656.                 $paragraphs $repoParagraph->findBy(["post" => $post], ["position" => "asc"]);
  657.                 return $this->render('front/post.html.twig', array(
  658.                     "post" => $post,
  659.                     "paragraphs" => $paragraphs,
  660.                 ));
  661.             } else {
  662.                 $this->addFlash("danger""flash.not_allowed_post");
  663.                 return $this->redirectToRoute('front_posts');
  664.             }
  665.         } else {
  666.             $this->addFlash("danger""flash.post_not_found");
  667.             return $this->redirectToRoute('front_posts');
  668.         }
  669.     }
  670. }