src/Controller/Front/Modules/MenuController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Modules;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use App\Entity\Category;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  11. class MenuController extends \App\Controller\Front\FrontController
  12. {
  13. public function main(Request $request, EntityManagerInterface $em, \App\Manager\CustomerManager $customerMgr, \App\Manager\CacheManager $cacheMgr)
  14. {
  15. $key = 'main-menu';
  16. if($customerMgr->isExpert()) {
  17. $key .= '-expert';
  18. }
  19. $menuItem = $cacheMgr->getItem($request->getLocale(), $key);
  20. if (!$menuItem->isHit()) {
  21. $categories = $em->getRepository(Category::class)->getRoots(5);
  22. $html = $this->renderView('front/modules/menu/cache.html.twig', [
  23. 'categories' => $categories
  24. ]);
  25. $cacheMgr->setItem($menuItem, $html, \App\Manager\CacheManager::TAG_MENU);
  26. }
  27. $menu = $menuItem->get();
  28. return $this->render('front/modules/menu/main.html.twig', [
  29. 'cache' => $menu
  30. ]);
  31. }
  32. }