<?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, \Symfony\Component\HttpKernel\KernelInterface $kernel, \App\Manager\CustomerManager $customerMgr)
{
$cache = new \Symfony\Component\Cache\Adapter\FilesystemAdapter();
// $cache->deleteItem('main-menu-'.$request->getLocale());
$key = $kernel->getEnvironment().'-main-menu-'.$request->getLocale();
if($customerMgr->isExpert()) {
$key .= '-expert';
}
$menuItem = $cache->getItem($key);
if (!$menuItem->isHit()) {
$categories = $em->getRepository(Category::class)->getRoots(5);
$html = $this->renderView('front/modules/menu/cache.html.twig', [
'categories' => $categories
]);
$menuItem->set($html);
$cache->save($menuItem);
}
$menu = $menuItem->get();
return $this->render('front/modules/menu/main.html.twig', [
'cache' => $menu
]);
}
}