<?php
namespace App\project\OfficeBrain\CustomBundle\PageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use App\OfficeBrain\Bundle\PageBundle\Controller\HomePageController as BaseHomePageController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\OfficeBrain\Bundle\AccessManagementBundle\Entity\InstanceMasterRepository;
use App\OfficeBrain\Bundle\ProductBundle\Manager\Service\BrandApiManager;
use App\OfficeBrain\Bundle\ProductBundle\ApiClient\BrandApiClient;
use App\OfficeBrain\Bundle\ImageBundle\Manager\Service\ApiManager;
use App\OfficeBrain\Bundle\ProductBundle\Entity\BrandMapping;
use App\OfficeBrain\Bundle\ProductBundle\Entity\BrandMappingRepository;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use App\OfficeBrain\Bundle\SearchBundle\Manager\Service\SearchManager;
use App\project\OfficeBrain\CustomBundle\SearchBundle\Manager\Service\SearchManager as CustomSearchManager;
use App\project\OfficeBrain\CustomBundle\ProductTagBundle\Manager\Service\ProductTagManager;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
use App\OfficeBrain\Bundle\PageBundle\Manager\Service\NewsletterManager;
use App\OfficeBrain\Bundle\PageBundle\Manager\Service\SiteModuleManager;
class HomePageController extends BaseHomePageController
{
public function __construct(CmsPageService $cmsPageManager, ProductTagManager $productTagManager, RequestStack $request, Container $container, SearchManager $searchManager, BrandApiManager $brandApiManager, CustomSearchManager $customSearchManager, NewsletterManager $newsLetter, SiteModuleManager $siteModuleManager)
{
$this->statsh_cache_wrapper = RedisCacheService::create();
$this->cmsPageManager = $cmsPageManager->getCmsPageExtended();
$this->serviceContainer = $container;
// $this->site_module = $this->serviceContainer->get('office_brain_page_site_module');
$this->site_module = $siteModuleManager;
// $this->newsLetter = $this->serviceContainer->get('office_brain_newsletter_manager');
$this->newsLetter = $newsLetter;
$this->translator = $this->serviceContainer->get('translator');
// $this->searchManager = $this->serviceContainer->get("office_brain_search_manager_extended");
$this->searchManager = $searchManager->getSolrSearchExtended();
$this->customSearchManager = $customSearchManager->getSolrSearchExtended();
// $this->productTagManager = $this->serviceContainer->get("office_brain_custombundle_product_tag_manager");
$this->productTagManager = $productTagManager->getProductTagManagerExtended();
// $this->brandApiManager = new BrandApiManager($brandApi, $imageManager, $brandMappingEntity, $brandMappingRepository, $request);
$this->brandApiManager = $brandApiManager;
$this->newsLetter = $newsLetter;
$this->siteModuleManager = $siteModuleManager;
// $searchManager = $this->get('office_brain_search_manager_extended'); // symfony 4
}
public function __destruct()
{
unset($this->statsh_cache_wrapper);
}
/**
*
* @author Employee Id: 4488
* To Initialize the member variables
*
* @return NULL
*/
public function initAction(Request $request)
{
parent::initAction($request);
$this->newsLetter = $this->newsLetter;
// $this->productDetailManager = $this->get('office_brain_product_detail_manager_custom');
$this->request = $request;
// $this->searchManager = $this->get('office_brain_custom_bundle_search_manager');
$this->searchManager = $this->customSearchManager;
$this->twigManager = $this->serviceContainer->get('twig');
// $this->cmsPageManager = $this->get('office_brain_cms_page_manager'); // symfony 4
}
/**
* @Route("/operation/clear_cache",
* name="office_brain_page_clear_cache",
* options={"expose"=true}
* )
*
*/
public function clearCacheAction(Request $request)
{
$appPath = $this->serviceContainer->get('kernel')->getRootDir();
$shPath = $appPath."/..";
$phpPath = "/usr/bin/php";
$webPath = $appPath."/../web";
$identifier = $request->get('identifier');
$identifierUpper = strtoupper($identifier);
$commandResponse = shell_exec('sh '.$shPath.'/clear_cache.sh '.$appPath.' '.$shPath.' '.$phpPath.' '.$webPath.' '.$identifier.' '.$identifierUpper.' 2>&1; echo $?');
$commandResponse = "<pre>$commandResponse</pre>";
return new response($commandResponse);
}
/**
* @Route("/operation/remove_expired_price",
* name="office_brain_page_remove_expired_price",
* options={"expose"=true}
* )
*
*/
public function removeExpiredPriceAction(Request $request)
{
$appPath = $this->serviceContainer->get('kernel')->getRootDir();
$shPath = $appPath."/..";
$phpPath = "/usr/bin/php";
$webPath = $appPath."/../web";
$identifier = $request->get('identifier');
$identifierUpper = strtoupper($identifier);
$commandResponse = shell_exec('sh '.$shPath.'/remove_expired_price.sh '.$appPath.' '.$shPath.' '.$phpPath.' '.$webPath.' '.$identifier.' '.$identifierUpper.' 2>&1; echo $?');
$commandResponse = "<pre>$commandResponse</pre>";
return new response($commandResponse);
}
/**
* @Route("/operation/remove_expired_products_live",
* name="office_brain_page_remove_expired_products_live",
* options={"expose"=true}
* )
*
*/
public function removeExpiredProductLiveAction(Request $request)
{
$commandResponse = shell_exec('sh remove_expired_price_live.sh 2>&1; echo $?');
$commandResponse = "<pre>$commandResponse</pre>";
return new response($commandResponse);
}
/**
* @Route("/{slug}",
* name="office_brain_page_html_design_view",
* )
*
* @Template("project/OfficeBrain/CustomBundle/PageBundle/HomePage/designHtml.html.twig")
*/
public function htmlDesignAction(Request $request, $slug)
{
$this->initAction($request);
if($slug == 'en_us')
{
return $this->redirect($this->generateUrl('office_brain_page_homepage'));
}
//RedirectMatch 301 (?i)/DSP /en_us/flyer/featured-self-promotions
if(strtolower($slug) == strtolower('Unscripted'))
{
return $this->redirect($this->generateUrl('office_brain_page_html_design_view', array('slug' => 'simplicity','source' => 'unscripted')));
}
// $this->basePath = $this->container->getParameter('base_path'); // symfony 4
// $this->baseUrl = $this->container->getParameter('base_url'); // symfony 4
$this->basePath = $this->projectSetting['basePath'];
$this->baseUrl = $this->projectSetting['baseUrlContainer'];
$format = 'html';
if (file_exists(strtolower($this->basePath .'/htmls_dev/'. $slug.'.'.$format))) {
//return new BinaryFileResponse($this->baseUrl .'/htmls/'. $slug.'.'.$format);
return new Response(file_get_contents(strtolower($this->baseUrl .'/htmls_dev/'. $slug.'.'.$format)));
}
return;
}
/**
* @Route("/",
* name="office_brain_page_homepage",
* options={"expose"=true}
* )
* @Route("/{_locale}",
* name="office_brain_page_homepage_view",
* options={"expose"=true}
* )
*
*/
public function indexAction(Request $request)
{
$this->initAction($request);
if ($this->request->getSession()->get('user')) {
$userObj = $this->entityManager->getRepository('App\OfficeBrain\Bundle\UserBundle\Entity\User')->find($this->request->getSession()->get('user')->getId());
$this->session->remove('user');
$this->session->set('user', $userObj);
}
$this->projectSetting = $this->request->get('project_setting');
$locale=$this->locale;
$cookies = $this->request->cookies;
$arrLocale=explode("_", $locale);
$data=array();
// $data['brandList'] = $this->get("officebrain_brand_api_manager")->getList($arrLocale[0]); // symfony 4
$data['brandList'] = $this->brandApiManager->getList($arrLocale[0]);
$data['homePageVisit'] = false;
/* Home Advertisement */
$data['advertisementUrl'] = $this->serviceContainer->getParameter('client_upload_base_url').'dynamic_blocks_images/';
$dynamicBlockType = 'home_advertisement_1';
$data['home_advertisement_1'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
if(!empty($data['home_advertisement_1']) && !empty($data['home_advertisement_1']['fieldData'])){
$fieldData = trim($data['home_advertisement_1']['fieldData'],"'");
$data['home_advertisement_1']['fieldData'] = json_decode($fieldData, true);
}
$dynamicBlockType = 'home_advertisement_2';
$data['home_advertisement_2'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
if(!empty($data['home_advertisement_2']) && !empty($data['home_advertisement_2']['fieldData'])){
$fieldData = trim($data['home_advertisement_2']['fieldData'],"'");
$data['home_advertisement_2']['fieldData'] = json_decode($fieldData, true);
}
$brandBlocks = $this->serviceContainer->getParameter('dynamic_blocks');
$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;
$dynamicBlockType = 'featured_brands';
$data['featured_brands'] = $this->cmsPageManager->getDynamicBlockByType($dynamicBlockType);
if(!empty($data['featured_brands']) && !empty($data['featured_brands']['fieldData'])){
$fieldData = trim($data['featured_brands']['fieldData'],"'");
$data['featured_brands']['fieldData'] = json_decode($fieldData, true);
}
// echo "<pre>";print_r($data['featured_brands']);die;
/* EO: Home Advertisement */
if ($cookies->has('homePageVisit')){
$data['homePageVisit'] = true;
}
else {
if(isset($this->projectSetting['is_outside_geofence']) && $this->projectSetting['is_outside_geofence'] != 1){
setcookie('homePageVisit', true);
}
}
return $this->render('OfficeBrain/Bundle/PageBundle/HomePage/index.html.twig', [
'data' => $data,
// Add more variables as needed
]);
// return $data;
}
/**
* @Route("/{_locale}/get-product-tag-block-data",
* name="office_brain_page_homepage_producttag_data",
* )
*
*/
public function getProductTagBlockAction(Request $request)
{
$this->initAction($request);
$locale=$this->projectSetting['culture_code'];
$cookies = $this->request->cookies;
$arrLocale=explode("_", $locale);
$data=array();
$countryId = $this->projectSetting['country'][$arrLocale[1]]['id'];
// $this->container = $this->get('office_brain_custombundle_product_tag_manager'); // symfony 4
$this->moduleCachePrefix='__ProductTagManagementSpecialProducts__';
$userType = 'guest';
if ($this->userId > 0) {
$userType = 'register';
}
if ($cookies->has('CUSTOM_SITE_CULTURE'))
{
$changeCountry = $cookies->get('CUSTOM_SITE_CULTURE');
if($changeCountry != $locale){
$locale = $changeCountry;
}
unset($changeCountry);
}
/*$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$userType,$locale);
$cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
if($cacheData){
return $cacheData;
}*/
$data['tag_icon_url'] = $this->getParameter('private_tag.icon_url').'featured-icon/';
$data['special_products_private_tag_products'] = $this->productTagManager->getPrivateTagByCategoryId($this->projectSetting['private_tag_category']['special_products_tag_id'], true);
$response = $this->render('project/OfficeBrain/CustomBundle/PageBundle/HomePage/productTag.html.twig', $data);
/* if(!empty($cacheKey))
{
RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
} */
return $response;
}
/**
* @Route("/{_locale}/get-bestseller-tag-block-data",
* name="office_brain_page_homepage_getbestsellertag_data",
* )
*
*/
public function getBestSellerTagBlockAction(Request $request, $slug= null){
$this->initAction($request);
$locale=$this->locale;
// $locale=$this->projectSetting['culture_code'];
$cookies = $this->request->cookies;
$arrLocale=explode("_", $this->locale);
$data=array();
$countryId = $this->projectSetting['country'][$arrLocale[1]]['id'];
// $countryId = $this->serviceContainer->getParameter('country')[$arrLocale[1]]['id']; // symfony 4
// $this->productTagManager = $this->serviceContainer->get('office_brain_custombundle_product_tag_manager'); // symfony 4
$this->moduleCachePrefix='__ProductTagManagementBestSellerSearchProducts_';
$userType = 'guest';
if ($this->userId > 0) {
$userType = 'register';
}
if ($cookies->has('CUSTOM_SITE_CULTURE'))
{
$changeCountry = $cookies->get('CUSTOM_SITE_CULTURE');
if($changeCountry != $locale){
$locale = $changeCountry;
}
unset($changeCountry);
}
$cacheKey = $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$userType,$locale);
$cacheData = RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
if($cacheData){
return $cacheData;
}
$data['tag_icon_url'] = $this->serviceContainer->getParameter('private_tag.icon_url').'featured-icon/';
$data['bestseller_products_private_tag_products'] = $this->productTagManager->getPrivateTagByCategoryId($this->projectSetting['private_tag_category']['bestseller_products_tag_id'], true);
$response = $this->render('project/OfficeBrain/CustomBundle/PageBundle/HomePage/bestSellerTags.html.twig', $data);
if(!empty($cacheKey))
{
RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
}
return $response;
}
}