<?php
namespace App\Controller\Front\Modules;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Category;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class MenuController extends \App\Controller\Front\FrontController
{
public function main(Request $request, EntityManagerInterface $em, \App\Manager\CustomerManager $customerMgr, \App\Manager\CacheManager $cacheMgr)
{
$key = 'main-menu';
if($customerMgr->isExpert()) {
$key .= '-expert';
}
$menuItem = $cacheMgr->getItem($request->getLocale(), $key);
if (!$menuItem->isHit()) {
$categories = $em->getRepository(Category::class)->getRoots(5);
$html = $this->renderView('front/modules/menu/cache.html.twig', [
'categories' => $categories
]);
$cacheMgr->setItem($menuItem, $html, \App\Manager\CacheManager::TAG_MENU);
}
$menu = $menuItem->get();
return $this->render('front/modules/menu/main.html.twig', [
'cache' => $menu
]);
}
}