src/OfficeBrain/Bundle/CmsBundle/Controller/CmsMenuController.php line 143

Open in your IDE?
  1. <?php
  2. namespace App\OfficeBrain\Bundle\CmsBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  7. use App\OfficeBrain\Bundle\SearchBundle\Form\Type\ProductSearchType;
  8. use App\OfficeBrain\Bundle\SearchBundle\Form\Data\ProductSearchData;
  9. use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use App\OfficeBrain\Bundle\SearchBundle\Manager\Extended\SolrSearchExtended;
  14. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  15. use Doctrine\ORM\EntityManagerInterface;
  16. use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
  17. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\ProductDetailService;
  18. use App\OfficeBrain\Bundle\CategoryBundle\Manager\ApiManager as CategoryApiManager;
  19. use App\OfficeBrain\Bundle\CoreBundle\Service\SessionManager;
  20. use Knp\Component\Pager\PaginatorInterface;
  21. use Symfony\Component\Routing\RouterInterface;
  22. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
  23. use App\OfficeBrain\Bundle\CmsBundle\Manager\Extended\CmsMenuExtended;
  24. use App\OfficeBrain\Bundle\ProductTagBundle\Manager\Service\ProductTagManager;
  25. use App\OfficeBrain\Bundle\CmsBundle\Repository\CmsMenuMasterRepository;
  26. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMenuService;
  27. /**
  28.  * @author OfficeBrain 4494 <info@officebrain.com>
  29.  *
  30.  * Description : CMS Menu controller class
  31.  *
  32.  * @Route("/{_locale}/cms/menu")
  33.  **/
  34. class CmsMenuController extends AbstractController
  35. {
  36.     protected $request;
  37.     protected $projectSetting;
  38.     protected $cmsMenuManager;
  39.     protected $responseArray;
  40.     
  41.     protected $searchManager;
  42.     
  43.     protected $languageId;
  44.     
  45.     protected $entityManager;
  46.     public function __construct(EntityManagerInterface $entityManagerRequestStack $requestSearchManager $solrManagerProductDetailService $productDetailManagerSessionManager $sessionManagerPaginatorInterface $paginatorManagerContainer $serviceContainerCmsPageService $cmsPageManagerRouterInterface $routerManagerProductTagManager $productTagManager$countries$languages$cmsMenuMediaUploadLocation$userTypeCategoryApiManager $categoryManagerCmsMenuService $CmsMenuService)
  47.     {
  48.         $this->request null;
  49.         $this->projectSetting = array();
  50.         $this->responseArray = array();
  51.         $this->serviceContainer $serviceContainer;
  52.         // $this->cmsMenuManager = $this->serviceContainer->get('office_brain_cms_menu_extended');
  53.         $this->CmsMenuService $CmsMenuService->getCmsMenuExtended();
  54.         // $this->searchManager = $this->serviceContainer->get('office_brain_search_manager_extended');
  55.         $this->searchManager $solrManager->getSolrSearchExtended();
  56.         $this->languageId null;
  57.         $this->entityManager null;
  58.         $this->statsh_cache_wrapper=RedisCacheService::create();
  59.     }
  60.     public function __destruct()
  61.     {
  62.         unset($this->request);
  63.         unset($this->projectSetting);
  64.         unset($this->cmsMenuManager);
  65.         unset($this->responseArray);
  66.         unset($this->searchManager);
  67.         unset($this->languageId);
  68.         unset($this->entityManager);
  69.         unset($this->statsh_cache_wrapper);
  70.     }
  71.     public function initAction(Request $request)
  72.     {
  73.         $this->request $request;
  74.         $this->projectSetting $this->request->get('project_setting');
  75.         // $this->cmsMenuManager = $this->get('office_brain_cms_menu_manager'); // symfony 4
  76.         $this->cmsMenuManager $this->CmsMenuService;
  77.         $this->responseArray = array();
  78.         // $this->searchManager = $this->get('office_brain_search_manager');
  79.         $this->searchManager $this->searchManager;
  80.         $this->languageId $this->searchManager->getLanguageId(); // symfony 4
  81.         $this->entityManager $this->getDoctrine()->getManager();
  82.     }
  83.     /**
  84.      * @author Employee Id: 4464
  85.      * Description : get product list page as per search criteria.
  86.      *
  87.      * @param 1 :id
  88.      *
  89.      * @return type : Data.
  90.      *
  91.      * @throws Exception: Null
  92.      *
  93.      * @Route("/search-criteria-product-list/{id}", name="office_brain_cmsbundle_cmsmenu_searchcriteriaproductlist",
  94.      * requirements={"id"="\d+"}
  95.      * )
  96.      *
  97.      * @Method("GET")
  98.      * @Template("OfficeBrainSearchBundle:Search:search.html.twig")
  99.      */
  100.     public function searchCriteriaProductListAction(Request $request)
  101.     {
  102.         $this->initAction($request);
  103.         
  104.         $criteria $this->cmsMenuManager->getSearchCriteria();
  105.         $productSearchData = new ProductSearchData($this->entityManager$this->languageId);
  106.         $productSearchForm = new ProductSearchType();
  107.          
  108.         $this->form $this->createForm($productSearchForm$productSearchData, array('csrf_protection' => false));
  109.         $this->form->bind($criteria);
  110.         $this->responseArray $this->searchManager->searchResult($this->form->getData());
  111.     
  112.         return $this->responseArray;
  113.     }
  114.     /**
  115.      * @author Employee Id: 4494
  116.      * Description : menu detail.
  117.      *
  118.      * @param 1 :Menu slug
  119.      *
  120.      * @return type : Data.
  121.      *
  122.      * @throws Exception: Null
  123.      *
  124.      * @Route("/{slug}/{allow_override}", name="office_brain_cmsbundle_cmsmenu_menu",
  125.      * defaults={"slug"="header-menu", "allow_override"=0},
  126.      * options={"expose"=true}
  127.      * )
  128.      *
  129.      * @Method("GET")
  130.      * @Template("OfficeBrain/Bundle/CmsBundle/CmsMenu/menu.html.twig")
  131.      */
  132.     public function menuAction(Request $request)
  133.     {
  134.         $this->initAction($request);
  135.         $locale=$this->request->getLocale();
  136.         // -----------------------------------------------------------------------
  137.         $this->moduleCachePrefix '__MenuManagement__';
  138.         // $this->statsh_cache_wrapper->removeCacheByPrefix($this->moduleCachePrefix);
  139.         $cacheMenuKey = array('prepareMenu',$this->request->get('slug'),$locale,$this->projectSetting['menu_user_type'],$this->projectSetting['instance_id'],$this->serviceContainer->getParameter('kernel.environment'));
  140.         // $cacheMenuKey = array('prepareMenu',$this->request->get('slug'),$locale,$this->projectSetting['menu_user_type'],$this->projectSetting['instance_id'],$this->projectSetting['kernelEnvironment']);
  141.         $this->moduleCachePrefix='__MenuManagement__:'.$this->request->get('slug');
  142.         $cacheKey $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheMenuKey);
  143.         $cacheData RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
  144.         if($cacheData){
  145.             return $cacheData;
  146.         }
  147.         // -----------------------------------------------------------------------
  148.     
  149.         if ($this->request->get('slug') == 'header-menu' && $this->request->get('allow_override') == 1) {
  150.             $slug 'header-menu';
  151.         } else {
  152.             $slug $this->request->get('slug');
  153.         }
  154.         $this->responseArray $this->cmsMenuManager->prepareMenu(falsefalsetruetrue$slug$this->request->get('allow_override'));
  155.         $response $this->render('OfficeBrain/Bundle/CmsBundle/CmsMenu/menu.html.twig'$this->responseArray);
  156.         
  157.         if(!empty($cacheKey))
  158.         {
  159.             RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  160.         }
  161.         
  162.         return $this->responseArray;
  163.     }
  164.     
  165.     
  166. }