src/project/OfficeBrain/CustomBundle/PageBundle/Controller/HomePageController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\PageBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use App\OfficeBrain\Bundle\PageBundle\Controller\HomePageController as BaseHomePageController;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
  8. use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use App\OfficeBrain\Bundle\AccessManagementBundle\Entity\InstanceMasterRepository;
  13. use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\BrandApiManager;
  14. use App\OfficeBrain\Bundle\ProductBundle\ApiClient\BrandApiClient;
  15. use App\OfficeBrain\Bundle\ImageBundle\Manager\Service\ApiManager;
  16. use App\OfficeBrain\Bundle\ProductBundle\Entity\BrandMapping;
  17. use App\OfficeBrain\Bundle\ProductBundle\Entity\BrandMappingRepository;
  18. use Symfony\Component\DependencyInjection\ContainerInterface as Container;
  19. use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
  20. use App\project\OfficeBrain\CustomBundle\SearchBundle\Manager\Service\SearchManager as CustomSearchManager;
  21. use App\project\OfficeBrain\CustomBundle\ProductTagBundle\Manager\Service\ProductTagManager;
  22. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
  23. use App\OfficeBrain\Bundle\PageBundle\Manager\Service\NewsletterManager;
  24. use App\OfficeBrain\Bundle\PageBundle\Manager\Service\SiteModuleManager;
  25. class HomePageController extends BaseHomePageController
  26. {
  27.     public function __construct(CmsPageService $cmsPageManagerProductTagManager $productTagManagerRequestStack $requestContainer $containerSearchManager $searchManagerBrandApiManager $brandApiManagerCustomSearchManager $customSearchManagerNewsletterManager $newsLetterSiteModuleManager $siteModuleManager)
  28.     {
  29.         $this->statsh_cache_wrapper RedisCacheService::create();
  30.         $this->cmsPageManager $cmsPageManager->getCmsPageExtended();
  31.         $this->serviceContainer $container;
  32.         // $this->site_module = $this->serviceContainer->get('office_brain_page_site_module');
  33.         $this->site_module $siteModuleManager;
  34.         // $this->newsLetter = $this->serviceContainer->get('office_brain_newsletter_manager');
  35.         $this->newsLetter $newsLetter;
  36.         $this->translator $this->serviceContainer->get('translator');
  37.         // $this->searchManager = $this->serviceContainer->get("office_brain_search_manager_extended");
  38.         $this->searchManager $searchManager->getSolrSearchExtended();
  39.         $this->customSearchManager $customSearchManager->getSolrSearchExtended();
  40.         // $this->productTagManager = $this->serviceContainer->get("office_brain_custombundle_product_tag_manager");
  41.         $this->productTagManager $productTagManager->getProductTagManagerExtended();
  42.         // $this->brandApiManager = new BrandApiManager($brandApi, $imageManager, $brandMappingEntity, $brandMappingRepository, $request);
  43.         $this->brandApiManager $brandApiManager;
  44.         $this->newsLetter $newsLetter;
  45.         $this->siteModuleManager $siteModuleManager;
  46.         // $searchManager = $this->get('office_brain_search_manager_extended'); // symfony 4
  47.     }
  48.     public function __destruct()
  49.     {
  50.         unset($this->statsh_cache_wrapper);
  51.     }
  52.     
  53.     /**
  54.      *
  55.      * @author Employee Id: 4488
  56.      * To Initialize the member variables
  57.      *
  58.      * @return NULL
  59.      */
  60.     public function initAction(Request $request)
  61.     {
  62.         parent::initAction($request);
  63.         $this->newsLetter $this->newsLetter;
  64.         // $this->productDetailManager = $this->get('office_brain_product_detail_manager_custom');
  65.         $this->request $request;
  66.         // $this->searchManager = $this->get('office_brain_custom_bundle_search_manager');
  67.         $this->searchManager $this->customSearchManager;
  68.         $this->twigManager $this->serviceContainer->get('twig');
  69.         // $this->cmsPageManager = $this->get('office_brain_cms_page_manager'); // symfony 4
  70.     }
  71.     /**
  72.      * @Route("/operation/clear_cache",
  73.      *     name="office_brain_page_clear_cache",
  74.      *  options={"expose"=true}
  75.      * )
  76.      *
  77.      */
  78.     public function clearCacheAction(Request $request)
  79.     {
  80.         $appPath $this->serviceContainer->get('kernel')->getRootDir();
  81.         $shPath $appPath."/..";
  82.         $phpPath "/usr/bin/php";
  83.         $webPath $appPath."/../web";
  84.         $identifier $request->get('identifier');
  85.         $identifierUpper strtoupper($identifier);
  86.         
  87.         $commandResponse shell_exec('sh '.$shPath.'/clear_cache.sh '.$appPath.' '.$shPath.' '.$phpPath.' '.$webPath.' '.$identifier.' '.$identifierUpper.' 2>&1; echo $?');
  88.         
  89.         $commandResponse "<pre>$commandResponse</pre>";
  90.         return new response($commandResponse);
  91.     }
  92.     
  93.     /**
  94.      * @Route("/operation/remove_expired_price",
  95.      *     name="office_brain_page_remove_expired_price",
  96.      *  options={"expose"=true}
  97.      * )
  98.      *
  99.      */
  100.     public function removeExpiredPriceAction(Request $request)
  101.     {
  102.         $appPath $this->serviceContainer->get('kernel')->getRootDir();
  103.         $shPath $appPath."/..";
  104.         $phpPath "/usr/bin/php";
  105.         $webPath $appPath."/../web";
  106.         $identifier $request->get('identifier');
  107.         $identifierUpper strtoupper($identifier);
  108.         
  109.         $commandResponse shell_exec('sh '.$shPath.'/remove_expired_price.sh '.$appPath.' '.$shPath.' '.$phpPath.' '.$webPath.' '.$identifier.' '.$identifierUpper.' 2>&1; echo $?');
  110.         
  111.         $commandResponse "<pre>$commandResponse</pre>";
  112.         return new response($commandResponse);
  113.     }
  114.     
  115.     /**
  116.      * @Route("/operation/remove_expired_products_live",
  117.      *     name="office_brain_page_remove_expired_products_live",
  118.      *  options={"expose"=true}
  119.      * )
  120.      *
  121.      */
  122.     public function removeExpiredProductLiveAction(Request $request)
  123.     {
  124.         $commandResponse shell_exec('sh remove_expired_price_live.sh 2>&1; echo $?');
  125.         
  126.         $commandResponse "<pre>$commandResponse</pre>";
  127.         return new response($commandResponse);
  128.     }
  129.     /**
  130.      * @Route("/{slug}",
  131.      *     name="office_brain_page_html_design_view",
  132.      * )
  133.      *
  134.      * @Template("project/OfficeBrain/CustomBundle/PageBundle/HomePage/designHtml.html.twig")
  135.      */
  136.     public function htmlDesignAction(Request $request$slug)
  137.     {
  138.         $this->initAction($request);
  139.         
  140.         if($slug == 'en_us')
  141.         {
  142.             return $this->redirect($this->generateUrl('office_brain_page_homepage'));
  143.         }
  144.         
  145.         //RedirectMatch 301 (?i)/DSP /en_us/flyer/featured-self-promotions
  146.         if(strtolower($slug) == strtolower('Unscripted'))
  147.         {
  148.             return $this->redirect($this->generateUrl('office_brain_page_html_design_view', array('slug' => 'simplicity','source' => 'unscripted')));
  149.         }
  150.         // $this->basePath = $this->container->getParameter('base_path'); // symfony 4
  151.         // $this->baseUrl  = $this->container->getParameter('base_url'); // symfony 4
  152.         $this->basePath $this->projectSetting['basePath'];
  153.         $this->baseUrl  $this->projectSetting['baseUrlContainer'];
  154.         $format 'html';
  155.         if (file_exists(strtolower($this->basePath .'/htmls_dev/'$slug.'.'.$format))) {
  156.             //return new BinaryFileResponse($this->baseUrl .'/htmls/'. $slug.'.'.$format);
  157.             return new Response(file_get_contents(strtolower($this->baseUrl .'/htmls_dev/'$slug.'.'.$format)));
  158.         }
  159.         return;
  160.     }
  161.     /**
  162.      * @Route("/",
  163.      *     name="office_brain_page_homepage",
  164.      *  options={"expose"=true}
  165.      * )
  166.      * @Route("/{_locale}",
  167.      *     name="office_brain_page_homepage_view",
  168.      *  options={"expose"=true}
  169.      * )
  170.      *
  171.      */
  172.     public function indexAction(Request $request)
  173.     {
  174.         $this->initAction($request);
  175.         if ($this->request->getSession()->get('user')) {
  176.             $userObj $this->entityManager->getRepository('App\OfficeBrain\Bundle\UserBundle\Entity\User')->find($this->request->getSession()->get('user')->getId());
  177.             $this->session->remove('user');
  178.             $this->session->set('user'$userObj);
  179.         }
  180.         $this->projectSetting $this->request->get('project_setting');
  181.         $locale=$this->locale;
  182.         $cookies $this->request->cookies;
  183.         $arrLocale=explode("_"$locale);
  184.         $data=array();
  185.         // $data['brandList'] = $this->get("officebrain_brand_api_manager")->getList($arrLocale[0]); // symfony 4
  186.         $data['brandList'] = $this->brandApiManager->getList($arrLocale[0]);
  187.         $data['homePageVisit'] = false;
  188.         
  189.         /* Home Advertisement */
  190.         $data['advertisementUrl'] = $this->serviceContainer->getParameter('client_upload_base_url').'dynamic_blocks_images/';
  191.         $dynamicBlockType 'home_advertisement_1';
  192.         $data['home_advertisement_1'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
  193.         if(!empty($data['home_advertisement_1']) && !empty($data['home_advertisement_1']['fieldData'])){
  194.             $fieldData trim($data['home_advertisement_1']['fieldData'],"'");
  195.             $data['home_advertisement_1']['fieldData'] = json_decode($fieldDatatrue);
  196.         }
  197.         $dynamicBlockType 'home_advertisement_2';
  198.         $data['home_advertisement_2'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
  199.         if(!empty($data['home_advertisement_2']) && !empty($data['home_advertisement_2']['fieldData'])){
  200.             $fieldData trim($data['home_advertisement_2']['fieldData'],"'");
  201.             $data['home_advertisement_2']['fieldData'] = json_decode($fieldDatatrue);
  202.         }
  203.         $brandBlocks $this->serviceContainer->getParameter('dynamic_blocks');
  204.         $data['no_of_brands'] = isset($brandBlocks['brands_blocks']['featured_brands']['number_of_blocks']) && !empty($brandBlocks['brands_blocks']['featured_brands']['number_of_blocks'])?$brandBlocks['brands_blocks']['featured_brands']['number_of_blocks']:1;
  205.         $dynamicBlockType 'featured_brands';
  206.         $data['featured_brands'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
  207.         if(!empty($data['featured_brands']) && !empty($data['featured_brands']['fieldData'])){
  208.             $fieldData trim($data['featured_brands']['fieldData'],"'");
  209.             $data['featured_brands']['fieldData'] = json_decode($fieldDatatrue);
  210.         }
  211.         
  212.         // echo "<pre>";print_r($data['featured_brands']);die;
  213.         /* EO: Home Advertisement */
  214.         if ($cookies->has('homePageVisit')){
  215.             $data['homePageVisit'] = true;
  216.         }
  217.         else {
  218.         
  219.             if(isset($this->projectSetting['is_outside_geofence']) && $this->projectSetting['is_outside_geofence'] != 1){
  220.                 setcookie('homePageVisit'true);
  221.             }
  222.         }
  223.         return $this->render('OfficeBrain/Bundle/PageBundle/HomePage/index.html.twig', [
  224.             'data' => $data,
  225.             // Add more variables as needed
  226.         ]);
  227.         // return $data;
  228.     }
  229.     /**
  230.      * @Route("/{_locale}/get-product-tag-block-data",
  231.      *     name="office_brain_page_homepage_producttag_data",
  232.      * )
  233.      *
  234.      */
  235.     public function getProductTagBlockAction(Request $request)
  236.     {
  237.         $this->initAction($request);
  238.         $locale=$this->projectSetting['culture_code'];
  239.         $cookies $this->request->cookies;
  240.         $arrLocale=explode("_"$locale);
  241.         $data=array();
  242.         $countryId $this->projectSetting['country'][$arrLocale[1]]['id'];
  243.         // $this->container = $this->get('office_brain_custombundle_product_tag_manager'); // symfony 4
  244.         $this->moduleCachePrefix='__ProductTagManagementSpecialProducts__';
  245.         $userType 'guest';
  246.         if ($this->userId 0) {
  247.             $userType 'register';
  248.         }
  249.         if ($cookies->has('CUSTOM_SITE_CULTURE'))
  250.         {
  251.             $changeCountry $cookies->get('CUSTOM_SITE_CULTURE');
  252.             if($changeCountry != $locale){
  253.                 $locale $changeCountry;
  254.             }
  255.             unset($changeCountry);
  256.         }
  257.         /*$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$userType,$locale);
  258.         $cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
  259.         if($cacheData){
  260.             return $cacheData;
  261.         }*/
  262.         $data['tag_icon_url'] = $this->getParameter('private_tag.icon_url').'featured-icon/';
  263.         $data['special_products_private_tag_products'] = $this->productTagManager->getPrivateTagByCategoryId($this->projectSetting['private_tag_category']['special_products_tag_id'], true);
  264.         $response $this->render('project/OfficeBrain/CustomBundle/PageBundle/HomePage/productTag.html.twig'$data);
  265.         
  266.         /* if(!empty($cacheKey))
  267.         {
  268.             RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  269.         } */
  270.         return $response;
  271.     }
  272.     
  273.     /**
  274.      * @Route("/{_locale}/get-bestseller-tag-block-data",
  275.      *     name="office_brain_page_homepage_getbestsellertag_data",
  276.      * )
  277.      *
  278.      */
  279.     public function getBestSellerTagBlockAction(Request $request$slugnull){
  280.         $this->initAction($request);
  281.         $locale=$this->locale;
  282.         // $locale=$this->projectSetting['culture_code'];
  283.         $cookies $this->request->cookies;
  284.         
  285.         $arrLocale=explode("_"$this->locale);
  286.         $data=array();
  287.         $countryId $this->projectSetting['country'][$arrLocale[1]]['id'];
  288.         // $countryId = $this->serviceContainer->getParameter('country')[$arrLocale[1]]['id']; // symfony 4
  289.         // $this->productTagManager = $this->serviceContainer->get('office_brain_custombundle_product_tag_manager'); // symfony 4
  290.         $this->moduleCachePrefix='__ProductTagManagementBestSellerSearchProducts_';
  291.         
  292.         $userType 'guest';
  293.         if ($this->userId 0) {
  294.             $userType 'register';
  295.         }
  296.         if ($cookies->has('CUSTOM_SITE_CULTURE'))
  297.         {
  298.             $changeCountry $cookies->get('CUSTOM_SITE_CULTURE');
  299.             if($changeCountry != $locale){
  300.                 $locale $changeCountry;
  301.             }
  302.             unset($changeCountry);
  303.         }
  304.         $cacheKey $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$userType,$locale);
  305.         
  306.         $cacheData RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
  307.         if($cacheData){
  308.             return $cacheData;
  309.         }
  310.         
  311.         $data['tag_icon_url'] = $this->serviceContainer->getParameter('private_tag.icon_url').'featured-icon/';
  312.         
  313.         $data['bestseller_products_private_tag_products'] = $this->productTagManager->getPrivateTagByCategoryId($this->projectSetting['private_tag_category']['bestseller_products_tag_id'], true);
  314.         
  315.         $response $this->render('project/OfficeBrain/CustomBundle/PageBundle/HomePage/bestSellerTags.html.twig'$data);
  316.         
  317.         if(!empty($cacheKey))
  318.         {
  319.             RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  320.         }
  321.         
  322.         return $response;
  323.     }
  324. }