src/Controller/Main/StaticController.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Main;
  3. use App\Services\Admin\InstagramPostsManager;
  4. use App\Entity\Main\MarketingTestimony;
  5. use App\Form\Main\AffiliationContactType;
  6. use App\Form\Main\ContactType;
  7. use App\Services\EmailManager;
  8. use App\Services\ReCaptchaManager;
  9. use App\Services\SiteManager;
  10. use App\Services\TranslationManager;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use data\brulafine\staticData\IngredientsProvider;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. /**
  21.  * @Route(
  22.  *     condition="not (context.getHost() matches '%coaching_domain.host.regexp%')"
  23.  * )
  24.  */
  25. class StaticController extends AbstractController
  26. {
  27.     use BrulafineControllerTrait;
  28.     /**
  29.      * @param Request $request
  30.      * @param EntityManagerInterface $entityManager
  31.      * @return Response
  32.      */
  33.     #[Route(path: [
  34.         'fr' => '/',
  35.         'en' => '/en',
  36.         'es' => '/es',
  37.         'it' => '/it',
  38.     ], name"brulafine_home")]
  39.     public function indexAction(Request $requestEntityManagerInterface $entityManagerSiteManager $siteManagerInstagramPostsManager $instagramPostsManager)
  40.     {
  41.        // We have two different systems we need to handle there.
  42.         if ($siteManager->getYamlConfigParameter('siteUseStaticTestimonies')) {
  43.             $testimonyProvider "data\\{$siteManager->getYamlConfigParameter('websiteName')}\\staticData\\TestimoniesProvider";
  44.             $rawTestimonies $testimonyProvider::$testimonies;
  45.             $testimonies array_map(function (array $item): array {
  46.                 $item['age'] = date_create()->diff(date_create($item['birthdate']))->y;
  47.                 return $item;
  48.             }, array_slice($rawTestimonies03));
  49.         } else {
  50.             $testimonies $entityManager->getRepository(MarketingTestimony::class)->getTestimonies($request->getLocale());
  51.         }
  52.         $session $request->getSession();
  53.         $email $request->query->get('f_mail');
  54.         if (null === $email) {
  55.             $email $session->get('f_mail');
  56.         }
  57.         if (isset($email) && filter_var($emailFILTER_VALIDATE_EMAIL)) {
  58.             $session->set('f_mail'$email);
  59.         }
  60.         $ingredientsProvider '\data\\'$siteManager->getYamlConfigParameter('websiteName') .'\staticData\IngredientsProvider';
  61.         $activeIgPosts $instagramPostsManager->getActiveIgPosts(true);
  62.         return $this->staticAction($this->getTemplatesDir() . '/Static/index.html.twig', [
  63.             'testimonies' => $testimonies,
  64.             'ingredients' => $ingredientsProvider::$ingredients,
  65.             'activeIgPosts' => $activeIgPosts
  66.         ]);
  67.     }
  68.     /**
  69.      * @param Request $request
  70.      */
  71.     #[Route(path: [
  72.         'fr' => '/ingredients/',
  73.         'en' => '/ingredients/',
  74.         'es' => '/ingredientes/',
  75.         'it' => '/ingredienti/',
  76.     ], name"brulafine_ingredients")]
  77.     public function ingredientsAction(SiteManager $siteManager)
  78.     {
  79.         $ingredientsProvider '\data\\'$siteManager->getYamlConfigParameter('websiteName') .'\staticData\IngredientsProvider';
  80.         return $this->staticAction(
  81.             $this->getTemplatesDir() . '/Static/ingredients.html.twig',
  82.             [
  83.                 'ingredients' => $ingredientsProvider::$ingredients
  84.             ]
  85.         );
  86.     }
  87.     /**
  88.      * @Route("/contact/", name="brulafine_contact")
  89.      * @param Request $request
  90.      * @param ReCaptchaManager $reCaptchaManager
  91.      * @return RedirectResponse|Response
  92.      */
  93.     public function contactAction(Request $requestReCaptchaManager $reCaptchaManagerEmailManager $emailManagerTranslatorInterface $translator)
  94.     {
  95.         $setup $this->getSetup();
  96.         $form $this->createForm(ContactType::class);
  97.         $form->handleRequest($request);
  98.         $googleResponse $reCaptchaManager->getResponse();
  99.         if ($form->isSubmitted() && $form->isValid() && $googleResponse->success) {
  100.             $emailManager->sendContactMail($form$request);
  101.             $this->addFlash('info''flashMessages.site.messageWillBeSend');
  102.             return $this->redirectToRoute('brulafine_contact');
  103.         }
  104.         if ($form->isSubmitted() && !$googleResponse->success && property_exists($googleResponse"error-codes")) {
  105.             $recaptchaErrorMessage $translator->trans('flashMessages.site.recaptchaErrorMsg', array(), TranslationManager::TRANSLATION_DOMAIN_FLASH);
  106.         }
  107.         $mtcaptchaSiteKey $this->parameterBag->get('mtcaptcha_site_key');
  108.         
  109.         return $this->staticAction($this->getTemplatesDir() . '/Static/contact.html.twig', [
  110.             'form' => $form->createView(),
  111.             'cart' => $setup->getCart(),
  112.             'recaptchaErrorMessage' => $recaptchaErrorMessage ?? '',
  113.             'mtcaptchaSiteKey' => $mtcaptchaSiteKey
  114.         ]);
  115.     }
  116.     /**
  117.      * @Route("/affiliation/", name="brulafine_affiliation")
  118.      * @param Request $request
  119.      * @param ReCaptchaManager $reCaptchaManager
  120.      * @return RedirectResponse|Response
  121.      */
  122.     public function affiliationAction(Request $requestReCaptchaManager $reCaptchaManagerEmailManager $emailManager)
  123.     {
  124.         $setup $this->getSetup();
  125.         $form $this->createForm(AffiliationContactType::class);
  126.         $form->handleRequest($request);
  127.         $googleResponse $reCaptchaManager->getResponse();
  128.         if ($form->isSubmitted() && $form->isValid() && $googleResponse->success) {
  129.             $emailManager->sendAffiliationContactMail($form);
  130.             $this->addFlash('info''flashMessages.site.messageWillBeSend');
  131.             return $this->redirectToRoute('brulafine_affiliation');
  132.         }
  133.         if ($form->isSubmitted() && !$googleResponse->success && property_exists($googleResponse"error-codes")) {
  134.             $recaptchaErrorMessage 'flashMessages.site.recaptchaErrorMsg';
  135.         }
  136.         return $this->staticAction($this->getTemplatesDir() . '/Static/affiliation.contact.html.twig', [
  137.             'form' => $form->createView(),
  138.             'cart' => $setup->getCart(),
  139.             'recaptchaErrorMessage' => $recaptchaErrorMessage ?? ''
  140.         ]);
  141.     }
  142.     /**
  143.      * @Route(
  144.      *     "/temoignages/",
  145.      *     name="brulafine_temoignages_no_page")
  146.      * @Route(
  147.      *     "/temoignages/{page}/",
  148.      *     name="brulafine_temoignages",
  149.      *     requirements={"page"="\d*"}, defaults={"page"="2"})
  150.      * @Route (
  151.      *     "/avis/",
  152.      *     name="brulafine_avis_no_page")
  153.      * @Route(
  154.      *     "/avis/{page}/",
  155.      *     name="brulafine_avis",
  156.      *     requirements={"page"="\d*"},
  157.      *     defaults={"page"="2"})
  158.      * @param Request $request
  159.      * @param EntityManagerInterface $entityManager
  160.      * @param SiteManager $siteManager
  161.      * @param mixed $page
  162.      * @return Response
  163.      */
  164.     public function temoignagesAction(Request $requestEntityManagerInterface $entityManagerSiteManager $siteManager$page 1)
  165.     {
  166.         $route $request->attributes->get('_route');
  167.         // Chris don't want anymore the page 1 to exists... we destroy her (RIP)
  168.         if (== $page && in_array($route, ['brulafine_temoignages''brulafine_avis'])) {
  169.             throw new NotFoundHttpException("Page not found.");
  170.         }
  171.         $pageSize $siteManager->getYamlConfigParameter('testimoniesPerPage');
  172.         if ($siteManager->getYamlConfigParameter('siteUseStaticTestimonies')) {
  173.             $pagesCount 5;
  174.             if ($page $pagesCount) {
  175.                 $page $pagesCount;
  176.             } elseif ($page 1) {
  177.                 $page 1;
  178.             }
  179.             $testimonyProvider "data\\{$siteManager->getYamlConfigParameter('websiteName')}\\staticData\\TestimoniesProvider";
  180.             $rawTestimonies $testimonyProvider::$testimonies;
  181.             $testimonies array_map(function (array $item): array {
  182.                 $item['age'] = date_create()->diff(date_create($item['birthdate']))->y;
  183.                 return $item;
  184.             }, array_slice($rawTestimonies, ($page 1) * $pageSize$pageSize));
  185.         } else {
  186.             $result $entityManager->getRepository(MarketingTestimony::class)->getTestimoniesPaginator($page$pageSize$request->getLocale());
  187.             $pagesCount ceil($result['totalItems'] / $pageSize);
  188.             $testimonies $result['paginator'];
  189.         }
  190.         $start = (($page 1) * $pageSize);
  191.         if (=== $start) {
  192.             $start 1;
  193.         }
  194.         $end = ($page $pageSize);
  195.         return $this->staticAction($this->getTemplatesDir() . '/Static/temoignages.html.twig', [
  196.             'testimonies' => $testimonies,
  197.             'page' => $page,
  198.             'nb_pages' => $pagesCount,
  199.             'startItem' => $start,
  200.             'endItem' => $end
  201.         ]);
  202.     }
  203.     /**
  204.      * @Route("/temoignage/{client}/", name="brulafine_temoignage_interactive", defaults={"client"="cyrielle"})
  205.      * @param null|string $client
  206.      */
  207.     public function temoignagesInteractiveAction(SiteManager $siteManagerstring $client null)
  208.     {
  209.         return $this->redirectToRoute('brulafine_temoignage_videos', [], 301);
  210. //        $hasVideoTestimony = $this->getParameter("hasVideoTestimony");
  211. //
  212. //        if (!$hasVideoTestimony) {
  213. //            return $this->redirect($this->generateUrl("brulafine_home"));
  214. //        }
  215. //
  216. //        $testimonyProvider = "data\\{$siteManager->getYamlConfigParameter('websiteName')}\\staticData\\TestimoniesProvider";
  217. //        $rawTestimonies = $testimonyProvider::$videoTestimonies;
  218. //
  219. //        if (empty($rawTestimonies[$client])) {
  220. //            return $this->redirect($this->generateUrl("brulafine_home"));
  221. //        }
  222. //
  223. //        return $this->staticAction(
  224. //            $this->getTemplatesDir() . '/Static/temoignages.photos.html.twig',
  225. //            $rawTestimonies[$client]
  226. //        );
  227.     }
  228.     /**
  229.      * @Route("/avis/temoignages/", name="brulafine_temoignage_videos")
  230.      */
  231.     public function temoignagesVideosAction(Request $requestTranslatorInterface $translator)
  232.     {
  233.         if (!$translator->getCatalogue($translator->getLocale())->has($request->get('_route'), TranslationManager::TRANSLATION_DOMAIN_ROUTES)) {
  234.             return $this->redirect($this->generateUrl("brulafine_home"));
  235.         }
  236.         // TODO - make it compatible with all the sites and do the translations
  237.         $hasVideoTestimony $this->getParameter("hasVideoTestimony");
  238.         if (!$hasVideoTestimony) {
  239.             return $this->redirect($this->generateUrl("brulafine_home"));
  240.         }
  241.         return $this->staticAction(
  242.             $this->getTemplatesDir() . '/Static/temoignages.photos.html.twig',
  243.         );
  244.     }
  245.     /**
  246.      * @Route("/coaching/", name="brulafine_coaching")
  247.      * @param Request $request
  248.      */
  249.     public function coachingAction()
  250.     {
  251.         return $this->staticAction($this->getTemplatesDir() . '/Static/coaching.html.twig');
  252.     }
  253.     /**
  254.      * @Route("/aide/", name="brulafine_aide")
  255.      * @param Request $request
  256.      */
  257.     public function aideAction(SiteManager $siteManager)
  258.     {
  259.         $ingredientsProvider '\data\\'$siteManager->getYamlConfigParameter('websiteName') .'\staticData\IngredientsProvider';
  260.         return $this->staticAction(
  261.             $this->getTemplatesDir() . '/Static/aide.html.twig',
  262.             [
  263.                 'ingredients' => $ingredientsProvider::$ingredients
  264.             ]
  265.         );
  266.     }
  267.     /**
  268.      * @Route("/plan/", name="brulafine_plan")
  269.      * @return Response
  270.      */
  271.     public function planAction()
  272.     {
  273.         return $this->staticAction($this->getTemplatesDir() . '/Static/plan.html.twig');
  274.     }
  275.     /**
  276.      * @Route("/cgu/", name="brulafine_cgu")
  277.      * @return Response
  278.      */
  279.     public function cguAction()
  280.     {
  281.         return $this->staticAction($this->getTemplatesDir() . '/Static/cgu.html.twig');
  282.     }
  283.     /**
  284.      * @Route("/cgv/", name="brulafine_cgv")
  285.      * @return Response
  286.      */
  287.     public function cgvAction()
  288.     {
  289.         return $this->staticAction($this->getTemplatesDir() . '/Static/cgv.html.twig');
  290.     }
  291.     /**
  292.      * @Route("/legal/", name="brulafine_legal")
  293.      * @return Response
  294.      */
  295.     public function legalAction()
  296.     {
  297.         return $this->staticAction($this->getTemplatesDir() . '/Static/mentions-legales.html.twig');
  298.     }
  299.     /**
  300.      * @Route("/confidentialite/", name="brulafine_confidential")
  301.      * @return Response
  302.      */
  303.     public function confidentialAction()
  304.     {
  305.         return $this->staticAction($this->getTemplatesDir() . '/Static/confidentialite-vie-privee.html.twig');
  306.     }
  307.     /**
  308.      * @Route("/cookies/", name="brulafine_cookies")
  309.      * @return Response
  310.      */
  311.     public function cookiesAction()
  312.     {
  313.         return $this->staticAction($this->getTemplatesDir() . '/Static/cookies.html.twig');
  314.     }
  315.     /**
  316.      * @Route("/bruleur-graisse-comment/", name="brulafine_landing_fat_burner_how")
  317.      * @return Response
  318.      */
  319.     public function landingFatBurnerHowAction()
  320.     {
  321.         return $this->staticAction($this->getTemplatesDir() . '/Static/LandingPages/bruleur-graisse-comment.html.twig');
  322.     }
  323.     /**
  324.      * @Route("/bruleur-graisse-naturel/", name="brulafine_landing_fat_burner_normal")
  325.      * @return Response
  326.      */
  327.     public function landingFatBurnerNormalAction()
  328.     {
  329.         return $this->staticAction($this->getTemplatesDir() . '/Static/LandingPages/bruleur-graisse-naturel.html.twig');
  330.     }
  331.     /**
  332.      * @Route("/coupe-faim/", name="brulafine_landing_appetite_suppressant")
  333.      * @return Response
  334.      */
  335.     public function landingAppetiteSuppressantAction()
  336.     {
  337.         return $this->staticAction($this->getTemplatesDir() . '/Static/LandingPages/coupe-faim.html.twig');
  338.     }
  339.     /**
  340.      * @Route("/gelule-minceur/", name="brulafine_landing_slimming_gel")
  341.      * @return Response
  342.      */
  343.     public function landingSlimmingGelAction()
  344.     {
  345.         return $this->staticAction($this->getTemplatesDir() . '/Static/LandingPages/gelule-minceur.html.twig');
  346.     }
  347.     /**
  348.      * @Route("/sitemap/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
  349.      */
  350.     public function sitemapAction(Request $request)
  351.     {
  352.         $urls = array();
  353.         $hostname $request->getSchemeAndHttpHost();
  354.         // add static urls
  355.         $urls[] = array('loc' => $this->generateUrl('brulafine_home'));
  356.         $urls[] = array('loc' => $this->generateUrl('brulafine_ingredients'));
  357.         $urls[] = array('loc' => $this->generateUrl('brulafine_coaching'));
  358.         $urls[] = array('loc' => $this->generateUrl('brulafine_aide'));
  359.         $urls[] = array('loc' => $this->generateUrl('brulafine_contact'));
  360.         $urls[] = array('loc' => $this->generateUrl('brulafine_plan'));
  361.         $urls[] = array('loc' => $this->generateUrl('brulafine_show_packs'));
  362.         $urls[] = array('loc' => $this->generateUrl('brulafine_affiliation'));
  363.         $urls[] = array('loc' => $this->generateUrl('brulafine_avis_no_page'));
  364.         //all avis pages.
  365.         $pages 11;
  366.         if ('it' == $request->getLocale()) {
  367.             $pages 6;
  368.         }
  369.         for ($i 1$i <= $pages$i++) {
  370.             $urls[] = array('loc' => $this->generateUrl('brulafine_avis', ['page' => $i]));
  371.         }
  372.         $urls[] = array('loc' => $this->generateUrl('brulafine_temoignage_videos'));
  373.         // return response in XML format
  374.         $response = new Response(
  375.             $this->renderView($this->getTemplatesDir() . '/Static/sitemap.html.twig', array( 'urls' => $urls,
  376.                 'hostname' => $hostname)),
  377.             200
  378.         );
  379.         $response->headers->set('Content-Type''text/xml');
  380.         return $response;
  381.     }
  382.     protected function get($id)
  383.     {
  384.         // TODO: Implement get() method.
  385.     }
  386. }