src/OfficeBrain/Bundle/CmsBundle/Controller/CmsPageController.php line 75

Open in your IDE?
  1. <?php
  2. namespace App\OfficeBrain\Bundle\CmsBundle\Controller;
  3. // use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
  13. /**
  14.  * @author OfficeBrain 4494 <info@officebrain.com>
  15.  *
  16.  * Description : CMS controller class
  17.  *
  18.  * @Route("/{_locale}/page")
  19.  **/
  20. class CmsPageController extends AbstractController
  21. {
  22.     private $request;
  23.     private $session;
  24.     private $translator;
  25.     private $projectSetting;
  26.     private $recordsPerPage;
  27.     private $cmsPageManager;
  28.     private $responseArray;
  29.     public function __construct(ContainerInterface $serviceContainerCmsPageService $cmsPageService)
  30.     {
  31.         $this->serviceContainer $serviceContainer;
  32.         $this->cmsPageService $cmsPageService->getCmsPageExtended();
  33.     }
  34.     public function __destruct()
  35.     {
  36.         unset($this->request);
  37.         unset($this->session);
  38.         unset($this->translator);
  39.         unset($this->projectSetting);
  40.         unset($this->cmsPageManager);
  41.         unset($this->responseArray);
  42.         unset($this->serviceContainer);
  43.     }
  44.     public function initAction(Request $request)
  45.     {
  46.         $this->request $request;
  47.         $this->session $this->request->getSession();
  48.         $this->translator $this->serviceContainer->get('translator');
  49.         $this->projectSetting $this->request->get('project_setting');
  50.         // $this->cmsPageManager = $this->serviceContainer->get('office_brain_cms_page_manager');
  51.         $this->cmsPageManager $this->cmsPageService;
  52.         $this->userId $this->projectSetting['user_id'];
  53.         $this->responseArray = array();
  54.     }
  55.     /**
  56.      * * @author Employee Id: 4795
  57.      * Description : Get the page content and render page on fronend
  58.      *      *
  59.      * @Route("/{slug}", name="office_brain_cmsbundle_cmspage_page")
  60.      * @Template("OfficeBrain/Bundle/CmsBundle/CmsPage/page.html.twig")
  61.      */
  62.     public function pageAction(Request $request)
  63.     {
  64.         //echo 'hi';die;
  65.         $this->initAction($request);
  66.         $routeName $this->request->get('_route_params');
  67.       // echo  $routeName['slug'];
  68.         if(($routeName['slug']=='who-is-my-rep'||$routeName['slug']=='distributor-self-promos'|| $routeName['slug']=='tradeshow'||$routeName['slug']=='sample-kits') && $this->userId==0)
  69.         {
  70.         //    echo 'ss';die;
  71. //             return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
  72.             return $this->redirect($this->generateUrl('office_brain_userbundle_login_login',array("redirect_page_slug"=>$routeName['slug'])));
  73.         }
  74.         //die;
  75.         $this->responseArray $this->cmsPageManager->getCmsPageBySlug();
  76.         
  77.         if (!empty($this->responseArray['error']) && $this->responseArray['error'] == "PAGE_NOT_FOUND") {
  78.             throw $this->createNotFoundException($this->translator->trans('cms.front.page_not_found'));
  79.         }
  80.         return $this->responseArray;
  81.     }
  82.   //   48.75
  83.   //   37.50
  84.   // ----------
  85.   //   86.25  
  86.     /**
  87.      * * @author Employee Id: 4465
  88.      * Description : Site Search
  89.      *      *
  90.      * @Route("/search/list", name="office_brain_cmsbundle_cmspage_page_search",
  91.      * options={"expose"=true})
  92.      * 
  93.      * @Method("GET")
  94.      * 
  95.      * @Template("OfficeBrainCmsBundle:CmsPage:pageSearch.html.twig")
  96.      */
  97.     public function pageSearchAction(Request $request)
  98.     {
  99.         $this->initAction($request);
  100.         
  101.         $this->responseArray $this->cmsPageManager->siteSearch($this->request);
  102.         return $this->responseArray;
  103.     }
  104.     
  105.     /**
  106.      * * @author Employee Id: 4465
  107.      * Description : Site Search
  108.      *      *
  109.      * @Route("/search/list", name="office_brain_cmsbundle_cmspage_page_search_ajax",
  110.      * options={"expose"=true})
  111.      *
  112.      * @Method("POST")
  113.      *
  114.      * @Template("OfficeBrainCmsBundle:CmsPage:pageSearchAjax.html.twig")
  115.      */
  116.     public function pageSearchAjaxAction(Request $request)
  117.     {
  118.         $this->initAction($request);
  119.         
  120.         $this->responseArray $this->cmsPageManager->getSiteSearchList($this->request);
  121.         
  122.         return $this->responseArray;
  123.     }
  124.     /**
  125.      * @author Employee Id: 4589
  126.      * Description : save inline edit page
  127.      *
  128.      * @param string slug
  129.      *
  130.      * @return JSON Response
  131.      *
  132.      * @throws NULL
  133.      *
  134.      * @Route("/inline/edit/{slug}", name="office_brain_cmsbundle_cmspage_pageinlineedit",
  135.      * options={"expose"=true})
  136.      *
  137.      * @Method("POST")
  138.      *
  139.      * @return array
  140.      */
  141.     public function pageInlineEditAction(Request $request)
  142.     {
  143.         $this->initAction($request);
  144.         if ($this->cmsPageManager->updateCmsPageInline()) {
  145.             $this->responseArray = array('status' => 'success''success_message' => $this->translator->trans('cms.inline_edit.page_save_success'));
  146.         } else {
  147.             $this->responseArray = array('status' => 'error''error_message' => $this->translator->trans('cms.inline_edit.page_save_error'));
  148.         }
  149.         return new JsonResponse($this->responseArray);
  150.     }
  151.     
  152.     /**
  153.      * @author Employee Id: 4795
  154.      *
  155.      * Description : Preview Template
  156.      *
  157.      * @Route("/cms/preview", name="office_brain_cmsbundle_cmspage_cmspagepreview")
  158.      * @Method("POST")
  159.      * @Template("OfficeBrain/Bundle/CmsBundle/CmsPage/page.html.twig")
  160.      */
  161.     public function cmsPagePreviewAction(Request $request)
  162.     {
  163.         $this->initAction($request);
  164.    
  165.         $this->responseArray $this->cmsPageManager->previewCmsPage();
  166.     
  167.         return $this->responseArray;
  168.     }
  169. }