<?php
namespace App\OfficeBrain\Bundle\CmsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use App\OfficeBrain\Bundle\SearchBundle\Form\Type\ProductSearchType;
use App\OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\SolrSearchExtended;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use Doctrine\ORM\EntityManagerInterface;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
use App\OfficeBrain\Bundle\CategoryBundle\Manager\ApiManager as CategoryApiManager;
use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\Routing\RouterInterface;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Extended\CmsMenuExtended;
use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
use App\OfficeBrain\Bundle\CmsBundle\Repository\CmsMenuMasterRepository;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMenuService;
/**
* @author OfficeBrain 4494 <info@officebrain.com>
*
* Description : CMS Menu controller class
*
* @Route("/{_locale}/cms/menu")
**/
class CmsMenuController extends AbstractController
{
protected $request;
protected $projectSetting;
protected $cmsMenuManager;
protected $responseArray;
protected $searchManager;
protected $languageId;
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager, RequestStack $request, SearchManager $solrManager, ProductDetailService $productDetailManager, SessionManager $sessionManager, PaginatorInterface $paginatorManager, Container $serviceContainer, CmsPageService $cmsPageManager, RouterInterface $routerManager, ProductTagManager $productTagManager, $countries, $languages, $cmsMenuMediaUploadLocation, $userType, CategoryApiManager $categoryManager, CmsMenuService $CmsMenuService)
{
$this->request = null;
$this->projectSetting = array();
$this->responseArray = array();
$this->serviceContainer = $serviceContainer;
// $this->cmsMenuManager = $this->serviceContainer->get('office_brain_cms_menu_extended');
$this->CmsMenuService = $CmsMenuService->getCmsMenuExtended();
// $this->searchManager = $this->serviceContainer->get('office_brain_search_manager_extended');
$this->searchManager = $solrManager->getSolrSearchExtended();
$this->languageId = null;
$this->entityManager = null;
$this->statsh_cache_wrapper=RedisCacheService::create();
}
public function __destruct()
{
unset($this->request);
unset($this->projectSetting);
unset($this->cmsMenuManager);
unset($this->responseArray);
unset($this->searchManager);
unset($this->languageId);
unset($this->entityManager);
unset($this->statsh_cache_wrapper);
}
public function initAction(Request $request)
{
$this->request = $request;
$this->projectSetting = $this->request->get('project_setting');
// $this->cmsMenuManager = $this->get('office_brain_cms_menu_manager'); // symfony 4
$this->cmsMenuManager = $this->CmsMenuService;
$this->responseArray = array();
// $this->searchManager = $this->get('office_brain_search_manager');
$this->searchManager = $this->searchManager;
$this->languageId = $this->searchManager->getLanguageId(); // symfony 4
$this->entityManager = $this->getDoctrine()->getManager();
}
/**
* @author Employee Id: 4464
* Description : get product list page as per search criteria.
*
* @param 1 :id
*
* @return type : Data.
*
* @throws Exception: Null
*
* @Route("/search-criteria-product-list/{id}", name="office_brain_cmsbundle_cmsmenu_searchcriteriaproductlist",
* requirements={"id"="\d+"}
* )
*
* @Method("GET")
* @Template("OfficeBrainSearchBundle:Search:search.html.twig")
*/
public function searchCriteriaProductListAction(Request $request)
{
$this->initAction($request);
$criteria = $this->cmsMenuManager->getSearchCriteria();
$productSearchData = new ProductSearchData($this->entityManager, $this->languageId);
$productSearchForm = new ProductSearchType();
$this->form = $this->createForm($productSearchForm, $productSearchData, array('csrf_protection' => false));
$this->form->bind($criteria);
$this->responseArray = $this->searchManager->searchResult($this->form->getData());
return $this->responseArray;
}
/**
* @author Employee Id: 4494
* Description : menu detail.
*
* @param 1 :Menu slug
*
* @return type : Data.
*
* @throws Exception: Null
*
* @Route("/{slug}/{allow_override}", name="office_brain_cmsbundle_cmsmenu_menu",
* defaults={"slug"="header-menu", "allow_override"=0},
* options={"expose"=true}
* )
*
* @Method("GET")
* @Template("OfficeBrain/Bundle/CmsBundle/CmsMenu/menu.html.twig")
*/
public function menuAction(Request $request)
{
$this->initAction($request);
$locale=$this->request->getLocale();
// -----------------------------------------------------------------------
$this->moduleCachePrefix = '__MenuManagement__';
// $this->statsh_cache_wrapper->removeCacheByPrefix($this->moduleCachePrefix);
$cacheMenuKey = array('prepareMenu',$this->request->get('slug'),$locale,$this->projectSetting['menu_user_type'],$this->projectSetting['instance_id'],$this->serviceContainer->getParameter('kernel.environment'));
// $cacheMenuKey = array('prepareMenu',$this->request->get('slug'),$locale,$this->projectSetting['menu_user_type'],$this->projectSetting['instance_id'],$this->projectSetting['kernelEnvironment']);
$this->moduleCachePrefix='__MenuManagement__:'.$this->request->get('slug');
$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheMenuKey);
$cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
if($cacheData){
return $cacheData;
}
// -----------------------------------------------------------------------
if ($this->request->get('slug') == 'header-menu' && $this->request->get('allow_override') == 1) {
$slug = 'header-menu';
} else {
$slug = $this->request->get('slug');
}
$this->responseArray = $this->cmsMenuManager->prepareMenu(false, false, true, true, $slug, $this->request->get('allow_override'));
$response = $this->render('OfficeBrain/Bundle/CmsBundle/CmsMenu/menu.html.twig', $this->responseArray);
if(!empty($cacheKey))
{
RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
}
return $this->responseArray;
}
}