src/OfficeBrain/Bundle/BannerBundle/Controller/BannerController.php line 136

Open in your IDE?
  1. <?php
  2. namespace App\OfficeBrain\Bundle\BannerBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Contracts\Service\Attribute\Required;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use App\OfficeBrain\Bundle\BannerBundle\Entity\Banner;
  8. use App\OfficeBrain\Bundle\BannerBundle\Entity\BannerLanguage;
  9. //use OfficeBrain\Bundle\BannerBundle\Entity\BannerCountry;
  10. use App\OfficeBrain\Bundle\BannerBundle\Form\BannerType;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\File\UploadedFile;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\Validator\Constraints\Count;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  18. use App\OfficeBrain\Bundle\CoreBundle\Cache\RedisCacheService;
  19. // use Symfony\Component\Translation\TranslatorInterface;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. use Knp\Component\Pager\PaginatorInterface;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use App\OfficeBrain\Bundle\BannerBundle\Manager\Extended\BannerExtended;
  24. use Symfony\Component\DependencyInjection\ContainerInterface;
  25. /**
  26.  *
  27.  * @author OfficeBrain 4571 <info@officebrain.com>
  28.  *
  29.  * Description: Front Controller used to Display Banner in front
  30.  *
  31.  * @Route("{_locale}")
  32.  *
  33.  */
  34. class BannerController extends AbstractController
  35. {
  36.     private $translator;
  37.     private $request;
  38.     private $projectSetting;
  39.     private $manager;
  40.     private $isAjax;
  41.     private $session;
  42.     private $responseArray;
  43.     
  44.     /**
  45.      *
  46.      * @author Employee Id: 4571
  47.      * Description : To initialize variables
  48.      *
  49.      * @param  : null
  50.      *
  51.      * @return null
  52.      *
  53.      * @throws null
  54.      *
  55.      **/
  56.     public function __construct(EntityManagerInterface $entityManagerRequestStack $requestStackTranslatorInterface $translatorPaginatorInterface $knpPaginatorBannerExtended $bannerExtendedContainerInterface $container)
  57.     {
  58.         $this->request null;
  59.         $this->requestStack $requestStack->getCurrentRequest();
  60.         $this->manager $bannerExtended;
  61.         $this->responseArray = array();
  62.         $this->projectSetting null;
  63.         $this->session null;
  64.         $this->isAjax null;
  65.         $this->translator null;
  66.         $this->statsh_cache_wrapper=RedisCacheService::create();
  67.         $this->entityManager $entityManager;
  68.         $this->translator $translator;
  69.         $this->knpPaginator $knpPaginator;
  70.         $this->container $container;
  71.     }
  72.     
  73.     /**
  74.      *
  75.      * @author Employee Id: 4571
  76.      * Description : To unset member variables
  77.      *
  78.      * @param  : null
  79.      *
  80.      * @return null
  81.      *
  82.      * @throws null
  83.      *
  84.      **/
  85.     public function __destruct()
  86.     {
  87.         unset($this->request);
  88.         unset($this->manager);
  89.         unset($this->responseArray);
  90.         unset($this->projectSetting);
  91.         unset($this->session);
  92.         unset($this->isAjax);
  93.         unset($this->translator);
  94.         unset($this->statsh_cache_wrapper);
  95.     }
  96.     
  97.     /**
  98.      *
  99.      * @author Employee Id: 4571
  100.      * Description : to initialize request and services
  101.      *
  102.      * @param : null
  103.      *
  104.      * @return null
  105.      *
  106.      * @throws null
  107.      *
  108.      **/
  109.     public function initAction(Request $request)
  110.     {
  111.         $this->request $request;
  112.         // $this->manager = $this->get('office_brain_banner_manager');
  113.         // $this->translator = $this->get('translator'); // symfony 4
  114.         $this->session $this->request->getSession();
  115.         $this->isAjax $this->request->isXmlHttpRequest();
  116.         $this->projectSetting $this->request->get('project_setting');
  117.     }
  118.     
  119.     /**
  120.      *
  121.      * @author Employee Id: 4571
  122.      * Description : Fetch Active Banners
  123.      *
  124.      * @param : null
  125.      *
  126.      * @return null
  127.      *
  128.      * @throws null
  129.      *
  130.      * @Route("/banner/get-banners", name="office_brain_bannerbundle_banner_getallactivebanner")
  131.      * @Template("OfficeBrain/Bundle/BannerBundle/Banner/getAllActiveBanner.html.twig")
  132.      *
  133.      **/
  134.     public function getAllActiveBannerAction(Request $request)
  135.     {    
  136.         $this->initAction($request);
  137.         $locale=$this->request->getLocale();
  138.         $displayon=$this->request->get('displayOn');
  139.         $searchQuery $this->request->get('searchQuery');
  140.         $categoryFilter $this->request->get('categoryFilter');
  141.         // -----------------------------------------------------------------------
  142.         $cacheSiteKey = array('Banner',$displayon,$searchQuery,json_encode($categoryFilter),$locale,$this->projectSetting['instance_id'],$this->projectSetting['kernelEnvironment']);
  143.         $this->moduleCachePrefix='__BannerHomePage__:';
  144.         $cacheKey $this->moduleCachePrefix.RedisCacheService::generateKey($this->statsh_cache_wrapper,$cacheSiteKey);
  145.         $cacheData RedisCacheService::getCacheData($this->statsh_cache_wrapper,$cacheKey);
  146.         if($cacheData){
  147. //             print_r($cacheData);exit;
  148.             return $cacheData;
  149.         }
  150.         // -----------------------------------------------------------------------
  151.         
  152.         $directory $this->getParameter('banner.image_url');
  153. //         echo $directory;exit;
  154.         $this->responseArray['displayon'] = $displayon;
  155.         $this->responseArray['banner_list'] = $this->manager->fetchActiveBanner();
  156.         $this->responseArray['image_path'] = $directory;
  157.         
  158.        
  159.      /*   echo "<pre>";
  160.        \Doctrine\Common\Util\Debug::dump($this->responseArray['banner_list']);  
  161.        die;
  162.       */
  163.        foreach($this->responseArray['banner_list'] as $val){
  164.            $this->responseArray['banner'][$val['bannerCategory']][] = $val;
  165.        }
  166.        
  167.        
  168.        $response $this->render('OfficeBrain/Bundle/BannerBundle/Banner/getAllActiveBanner.html.twig'$this->responseArray);
  169.         if(!empty($cacheKey))
  170.         {
  171.             RedisCacheService::saveCacheData($this->statsh_cache_wrapper,$cacheKey,$response);
  172.         }
  173.         
  174.         return $this->responseArray;
  175.     }
  176.     
  177.     /**
  178.      *
  179.      * @author Employee Id: 4571
  180.      * Description : Fetch Banner Transitions
  181.      *
  182.      * @param : null
  183.      *
  184.      * @return js output
  185.      *
  186.      * @throws null
  187.      *
  188.      * @Route("/assets/js/banner-trans.js/{display}", name="office_brain_bannerbundle_banner_findbannertrans")
  189.      *
  190.      * @Method("GET")
  191.      * @Template()
  192.      *
  193.      **/
  194.     public function findBannerTransAction(Request $request$display)
  195.     {
  196.         $this->initAction($request);
  197.       
  198.         $this->responseArray['banner_transition'] = $this->manager->findBannerTransition($display);
  199.                 
  200.         $response = new Response();
  201.         $response->headers->set('Content-Type''text/javascript');
  202.         
  203.         return $this->render(
  204.                 'OfficeBrain/Bundle/BannerBundle/Banner/bannerCustomJs.html.twig',
  205.                 $this->responseArray,
  206.                 $response
  207.         );
  208.     }    
  209.     
  210.      /**
  211.      *
  212.      * @author Employee Id: 4835
  213.      * Description : details save in db for anayltics
  214.      *
  215.      * @param : $id banner id
  216.      *
  217.      * @return null
  218.      *
  219.      * @throws null
  220.      *
  221.      * @Route("/banner/linkajax/{id}", name="office_brain_bannerbundle_banner_linkajax",options={"expose"=true})
  222.      *
  223.      **/
  224.     public function linkAjaxAction(Request $request$id)
  225.     {
  226.         $this->initAction($request);
  227.        
  228.         $bannerServiceLog=$this->get("office_brain_activity_api_manager");
  229.         $bannerUrl=$this->manager->fetchBannerDetail($bannerServiceLog$id);
  230.       
  231.         return new JsonResponse($bannerUrl);
  232.     }
  233. }