src/Controller/AppController.php line 213

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Activite;
  4. use App\Entity\Category;
  5. use App\Entity\Extension;
  6. use App\Entity\Cgv;
  7. use App\Entity\InfoLine;
  8. use App\Entity\Legal;
  9. use App\Entity\Promote;
  10. use App\Entity\Rgpd;
  11. use App\Entity\Slider;
  12. use App\Repository\InfoLineRepository;
  13. use App\Repository\PromoteRepository;
  14. use App\Repository\SliderRepository;
  15. use App\Repository\ProductRepository;
  16. use App\Entity\Cart;
  17. use App\Service\Order;
  18. use App\Service\Pwa;
  19. use App\Service\Sitemap;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  23. use Symfony\Component\HttpFoundation\JsonResponse;
  24. use Symfony\Component\HttpFoundation\Request;
  25. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  26. use Symfony\Component\Routing\Router;
  27. use App\Entity\User;
  28. use Symfony\Component\VarDumper\VarDumper;
  29. class AppController extends AbstractController
  30. {
  31.     /**
  32.      * @Route("/", name="homepage", options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  33.      */
  34.     public function indexAction(Request $requestPwa $pwaEntityManagerInterface $em)
  35.     {
  36.         $categories $em->getRepository('App:Category')->findBy(["parent" => null"deletedAt" => null], ['sort' => 'ASC']);
  37.         return $this->render('app/pages/index.html.twig', [
  38.             'categories' => $categories,
  39.         ]);
  40.     }
  41.     public function renderMenuAction(Request $requestEntityManagerInterface $em)
  42.     {
  43.         $categories $em->getRepository('App:Category')->findBy(["parent" => null"deletedAt" => null], ['sort' => 'ASC']);
  44.         $pages $em->getRepository('App:Page')->findBy(["deletedAt" => null], ['sort' => 'ASC']);
  45.         return $this->render('app/_inc/_menu.html.twig', ['categories' => $categories'pages' => $pages]);
  46.     }
  47.     public function renderFooterAction(Request $reqEntityManagerInterface $em)
  48.     {
  49.         $categories $em->getRepository('App:Category')->findBy(["parent" => null"deletedAt" => null], ['sort' => 'ASC']);
  50.         $pages $em->getRepository('App:Page')->findBy(["deletedAt" => null], ['sort' => 'ASC']);
  51.         
  52.         return $this->render('app/_inc/_footer.html.twig', ['categories' => $categories'pages' => $pages,'req'=>$req,'locales'=>$this->getParameter('a2lix_translation_form.locales')]);
  53.     }
  54.     public function renderCartAction(Request $requestOrder $orderServiceEntityManagerInterface $em)
  55.     {
  56. //        $repoCart = $em->getRepository('App:Cart');
  57. //        $orderService->updateCart($request);
  58. //        /** @var Cart $cart */
  59. //        $cart = $repoCart->findOneBy(array(
  60. //            "session" => User::getSessionId($request),
  61. //            "ordered" => false
  62. //        ));
  63. //        if ($cart instanceof Cart) {
  64. //            $cartProducts = $cart->getCartProducts();
  65. //        } else {
  66. //            $cartProducts = null;
  67. //        }
  68.         return $this->render('app/_inc/_cart.html.twig', []);
  69.     }
  70.     public function renderSliderAction(EntityManagerInterface $em)
  71.     {
  72.         /** @var SliderRepository $repoSlider */
  73.         $repoSlider $em->getRepository('App:Slider');
  74.         $slider $repoSlider->find(1);
  75.         if (!$slider instanceof Slider) {
  76.             $slider = new Slider();
  77.             $em->persist($slider);
  78.             $em->flush();
  79.         }
  80.         return $this->render("app/_inc/_slider.html.twig", array(
  81.             'slides' => $slider->getSlides()
  82.         ));
  83.     }
  84.     public function renderInfoAction(EntityManagerInterface $em)
  85.     {
  86.         /** @var InfoLineRepository $repoInfoLine */
  87.         $repoInfoLine $em->getRepository('App:InfoLine');
  88.         $infoLine $repoInfoLine->find(1);
  89.         if (!$infoLine instanceof InfoLine) {
  90.             $infoLine = new InfoLine();
  91.             $em->persist($infoLine);
  92.             $em->flush();
  93.         }
  94.         return $this->render("app/_inc/_info.html.twig", array(
  95.             'infos' => $infoLine->getInfos()
  96.         ));
  97.     }
  98.     public function renderHighlightAction(Request $requestEntityManagerInterface $em)
  99.     {
  100.         /** @var ProductRepository $productRepository */
  101.         $productRepository $em->getRepository('App:Product');
  102.         $newProducts $productRepository->newProducts();
  103.         $promoProducts $productRepository->promoProducts();
  104.         return $this->render('app/_inc/_highlight.html.twig', [
  105.             'newProducts' => $newProducts,
  106.             'promoProducts' => $promoProducts,
  107.         ]);
  108.     }
  109.     public function renderPromoteAction(Request $requestEntityManagerInterface $em)
  110.     {
  111.         /** @var PromoteRepository $repoPromote */
  112.         $repoPromote $em->getRepository('App:Promote');
  113.         $promote $repoPromote->find(1);
  114.         if (!$promote instanceof Promote) {
  115.             $promote = new Promote();
  116.             $em->persist($promote);
  117.             $em->flush();
  118.         }
  119.         return $this->render("app/_inc/_promote.html.twig", array(
  120.             'cards' => $promote->getCards()
  121.         ));
  122.     }
  123.     /**
  124.      * @Route("/search", name="search", methods={"POST"}, options={"sitemap": false})
  125.      */
  126.     public function searchAction(Request $requestEntityManagerInterface $em)
  127.     {
  128.         $repoProduct $em->getRepository('App:Product');
  129.         $products $repoProduct->filterProduct($request->getLocale(), null$request->get("search"), [], "name", [], 110);
  130.         $html $this->render('app/_inc/_res.html.twig', ['products' => $products["products"]])->getContent();
  131.         return new JsonResponse(array('html' => $html));
  132.     }
  133.     /**
  134.      * @Route("/mentions-legales", name="legal",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  135.      */
  136.     public function legalAction(Request $request)
  137.     {
  138.         return $this->render('app/legal/legal.html.twig');
  139.     }
  140.     /**
  141.      * @Route("/protection-des-donnees", name="rgpd",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  142.      */
  143.     public function rgpdAction(Request $request)
  144.     {
  145.         return $this->render('app/legal/rgpd.html.twig');
  146.     }
  147.     /**
  148.      * @Route("activite/{id}/show", name="activiteShow",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  149.      */
  150.     public function activiteShowAction(Request $requestCategory $category)
  151.     {
  152.         $realisations $category->getActivites();
  153.         return $this->render('app/activites/activite_show.html.twig', ['category' => $category'realisations' => $realisations]);
  154.     }
  155.     /**
  156.      * @Route("/sablage", name="sablage",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  157.      */
  158.     public function sablageAction(Request $request)
  159.     {
  160.         return $this->render('app/activites/sablage.html.twig');
  161.     }
  162.     /**
  163.      * @Route("/hydrosablage", name="hydrosablage",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  164.      */
  165.     public function hydrosablageAction(Request $request)
  166.     {
  167.         return $this->render('app/activites/hydrosablage.html.twig');
  168.     }
  169.     /**
  170.      * @Route("/aerogommage", name="aerogommage",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  171.      */
  172.     public function aerogommageAction(Request $request)
  173.     {
  174.         return $this->render('app/activites/aerogommage.html.twig');
  175.     }
  176.     /**
  177.      * @Route("/hydrogommage", name="hydrogommage",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  178.      */
  179.     public function hydrogommageAction(Request $request)
  180.     {
  181.         return $this->render('app/activites/hydrogommage.html.twig');
  182.     }
  183.     /**
  184.      * @Route("/demolition-interieure", name="demolition",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  185.      */
  186.     public function demolitionAction(Request $request)
  187.     {
  188.         return $this->render('app/activites/demolition.html.twig');
  189.     }
  190.     /**
  191.      * @Route("/joints-de-pierre", name="joints",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  192.      */
  193.     public function jointsAction(Request $request)
  194.     {
  195.         return $this->render('app/activites/joints.html.twig');
  196.     }
  197.     /**
  198.      * @Route("/nos-realisations", name="realisations",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  199.      */
  200.     public function realisationsAction(Request $requestEntityManagerInterface $em)
  201.     {
  202.         $realisations $em->getRepository('App:Activite')->findBy(['deletedAt'=>null]);
  203.         return $this->render('app/pages/realist.html.twig', ['realisations' => $realisations]);
  204.     }
  205.     /**
  206.      * @Route("realisation/{id}/show", name="realisationshow",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  207.      */
  208.     public function realisationshowAction(Activite $realisationRequest $requestEntityManagerInterface $em)
  209.     {
  210. //        $other = $realisation->getCategory()->getActivites();
  211.         $qb $em->createQueryBuilder();
  212.         $qb->select('a')
  213.             ->from('App:Activite''a')
  214.             ->where('a.deletedAt IS NULL')
  215.             ->andWhere('a.category_rea = :category')
  216.             ->setParameter('category'$realisation->getCategoryRea())
  217.             ->orderBy('a.id''DESC');
  218.         $other $qb->getQuery()->getResult();
  219.         return $this->render('app/pages/realisationshow.html.twig', ['realisation' => $realisation'other' => $other]);
  220.     }
  221.     /**
  222.      * @Route("{id}/nos-activites", name="activiteslist",  options={"sitemap": false, "priority": 1, "changefreq": "yearly"})
  223.      */
  224.     public function activiteslistAction(Category $categoryRequest $request)
  225.     {
  226.         return $this->render('app/activites/activiteslist.html.twig', ['category' => $category]);
  227.     }
  228.     /**
  229.      * @Route("/conditions-generales-de-vente", name="cgv",  options={"sitemap": false, "priority": 1, "changefreq": "yearly"})
  230.      */
  231.     public function cgvAction(Request $request)
  232.     {
  233.         return $this->render('app/legal/cgv.html.twig');
  234.     }
  235.     /**
  236.      * @Route("/cookies", name="cookies",  options={"sitemap": true, "priority": 1, "changefreq": "yearly"})
  237.      */
  238.     public function cookiesAction(Request $request)
  239.     {
  240.         return $this->render('app/legal/cookies.html.twig');
  241.     }
  242.     /**
  243.      * @Route("/sitemap", name="sitemap",  options={"sitemap": true, "priority": 1, "changefreq": "daily"})
  244.      */
  245.     public function sitemapAction(Request $requestSitemap $sitemapService)
  246.     {
  247.         /** @var Router $router */
  248.         $router $this->container->get('router');
  249.         $collection $router->getRouteCollection();
  250.         $allRoutes $collection->all();
  251.         $urls = [];
  252.         /** @var \Symfony\Component\Routing\Route $route */
  253.         foreach ($allRoutes as $routeName => $route) {
  254.             if ($route->getOption('sitemap') == true) {
  255.                 $formatedRoute $sitemapService->generate($routeName$route$request->getLocale());
  256.                 if (count($formatedRoute) > 0) {
  257.                     if (array_key_exists('loc'$formatedRoute)) {
  258.                         $urls[] = $formatedRoute;
  259.                     } else {
  260.                         foreach ($formatedRoute as $formRoute) {
  261.                             $urls[] = $formRoute;
  262.                         }
  263.                     }
  264.                 }
  265.             }
  266.         }
  267.         return $this->render('app/legal/sitemap.html.twig', ['urls' => $urls]);
  268.     }
  269.     /**
  270.      * @Route("/sitemap.{_format}", requirements={"_locale" = "en|fr", "_format" = "xml"}, name="sitemap_xml")
  271.      */
  272.     public function sitemapXmlAction(Request $requestSitemap $sitemapService)
  273.     {
  274.         /** @var Router $router */
  275.         $router $this->container->get('router');
  276.         $collection $router->getRouteCollection();
  277.         $allRoutes $collection->all();
  278.         $urls = [];
  279.         /** @var \Symfony\Component\Routing\Route $route */
  280.         foreach ($allRoutes as $routeName => $route) {
  281.             if ($route->getOption('sitemap') == true) {
  282.                 $formatedRoute $sitemapService->generate($routeName$route$request->getLocale());
  283.                 if (count($formatedRoute) > 0) {
  284.                     if (array_key_exists('loc'$formatedRoute)) {
  285.                         $urls[] = $formatedRoute;
  286.                     } else {
  287.                         foreach ($formatedRoute as $formRoute) {
  288.                             $urls[] = $formRoute;
  289.                         }
  290.                     }
  291.                 }
  292.             }
  293.         }
  294.         return $this->render('app/legal/sitemap.xml.twig', ['urls' => $urls]);
  295.     }
  296.     /**
  297.      * @Route("/extension/{key}.json", name="extension_json",  options={"sitemap": false})
  298.      */
  299.     public function extensionJsonAction(Request $request$keyEntityManagerInterface $em)
  300.     {
  301.         $data = [];
  302.         if ($key == md5($request->getSchemeAndHttpHost())) {
  303.             $data["status"] = "OK";
  304.             $data["refresh"] = "1000";
  305.             $data["read"] = $this->generateUrl('notifications_readed', [], UrlGeneratorInterface::ABSOLUTE_URL);
  306.             $extension $em->getRepository('App:Extension')->find(1);
  307.             if (!$extension) {
  308.                 $extension = new Extension();
  309.             }
  310.             $total 0;
  311.             if (in_array("order"$extension->getAlert())) {
  312.                 $orders $em->getRepository('App:EcommerceOrder')->findBy(array('notificationReadedAt' => null));
  313.                 $data["data"]["orders"]["count"] = count($orders);
  314.                 if (count($orders) <= 0) {
  315.                     $data["data"]["orders"]["text"] = "Vous n'avez pas de nouvelles commandes";
  316.                 } elseif (count($orders) == 1) {
  317.                     $data["data"]["orders"]["text"] = "Vous avez 1 nouvelle commande";
  318.                 } else {
  319.                     $data["data"]["orders"]["text"] = "Vous avez " count($orders) . " nouvelles commandes";
  320.                 }
  321.                 $data["data"]["orders"]["url"] = $this->generateUrl('admin_order_index', [], UrlGeneratorInterface::ABSOLUTE_URL);
  322.                 $data["data"]["orders"]["icon"] = "money-bill-alt";
  323.                 $total += count($orders);
  324.             }
  325.             if (in_array("contact"$extension->getAlert())) {
  326.                 $contacts $em->getRepository('App:Contact')->findBy(array('notificationReadedAt' => null));
  327.                 $data["data"]["contacts"]["count"] = count($contacts);
  328.                 if (count($contacts) <= 0) {
  329.                     $data["data"]["contacts"]["text"] = "Vous n'avez pas de nouvelles demandes de contact";
  330.                 } elseif (count($contacts) == 1) {
  331.                     $data["data"]["contacts"]["text"] = "Vous avez 1 nouvelle demande de contact";
  332.                 } else {
  333.                     $data["data"]["contacts"]["text"] = "Vous avez " count($contacts) . " nouvelles demandes de contact";
  334.                 }
  335.                 $data["data"]["contacts"]["url"] = $this->generateUrl('admin_contact_index', [], UrlGeneratorInterface::ABSOLUTE_URL);
  336.                 $data["data"]["contacts"]["icon"] = "envelope";
  337.                 $total += count($contacts);
  338.             }
  339.             $data["total"] = $total;
  340.             $data["host"] = $request->getHost();
  341.             $data["color"] = $this->getParameter("color");
  342.         } else {
  343.             $data["status"] = "KO";
  344.         }
  345.         $response = new JsonResponse($data);
  346.         $response->headers->set("Access-Control-Allow-Origin""*");
  347.         return $response;
  348.     }
  349.     /**
  350.      * @Route("/notifications/readed", name="notifications_readed",  options={"sitemap": false})
  351.      */
  352.     public function notificationsReadedAction(Request $requestEntityManagerInterface $em)
  353.     {
  354.         $orders $em->getRepository('App:EcommerceOrder')->findBy(array('notificationReadedAt' => null));
  355.         foreach ($orders as $order) {
  356.             $order->setNotificationReadedAt(new \DateTime());
  357.             $em->persist($order);
  358.         }
  359.         $contacts $em->getRepository('App:Contact')->findBy(array('notificationReadedAt' => null));
  360.         foreach ($contacts as $contact) {
  361.             $contact->setNotificationReadedAt(new \DateTime());
  362.             $em->persist($contact);
  363.         }
  364.         $em->flush();
  365.         $response = new JsonResponse(["status" => "OK"]);
  366.         $response->headers->set("Access-Control-Allow-Origin""*");
  367.         return $response;
  368.     }
  369.     /**
  370.      * @Route("/editor/page", name="admin_editor_page")
  371.      */
  372.     public function editorPageAction(Request $request)
  373.     {
  374.         return $this->render('admin/editor/page.html.twig');
  375.     }
  376.     /**
  377.      * @Route("/editor/template", name="admin_editor_template")
  378.      */
  379.     public function editorTemplateAction(Request $request)
  380.     {
  381.         return $this->render('admin/editor/newsletter.html.twig', [
  382.             'url' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
  383.             'unsubscribe' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL)
  384.         ]);
  385.     }
  386. }