<?php
namespace App\OfficeBrain\Bundle\CmsBundle\Controller;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsPageService;
/**
* @author OfficeBrain 4494 <info@officebrain.com>
*
* Description : CMS controller class
*
* @Route("/{_locale}/page")
**/
class CmsPageController extends AbstractController
{
private $request;
private $session;
private $translator;
private $projectSetting;
private $recordsPerPage;
private $cmsPageManager;
private $responseArray;
public function __construct(ContainerInterface $serviceContainer, CmsPageService $cmsPageService)
{
$this->serviceContainer = $serviceContainer;
$this->cmsPageService = $cmsPageService->getCmsPageExtended();
}
public function __destruct()
{
unset($this->request);
unset($this->session);
unset($this->translator);
unset($this->projectSetting);
unset($this->cmsPageManager);
unset($this->responseArray);
unset($this->serviceContainer);
}
public function initAction(Request $request)
{
$this->request = $request;
$this->session = $this->request->getSession();
$this->translator = $this->serviceContainer->get('translator');
$this->projectSetting = $this->request->get('project_setting');
// $this->cmsPageManager = $this->serviceContainer->get('office_brain_cms_page_manager');
$this->cmsPageManager = $this->cmsPageService;
$this->userId = $this->projectSetting['user_id'];
$this->responseArray = array();
}
/**
* * @author Employee Id: 4795
* Description : Get the page content and render page on fronend
* *
* @Route("/{slug}", name="office_brain_cmsbundle_cmspage_page")
* @Template("OfficeBrain/Bundle/CmsBundle/CmsPage/page.html.twig")
*/
public function pageAction(Request $request)
{
//echo 'hi';die;
$this->initAction($request);
$routeName = $this->request->get('_route_params');
// echo $routeName['slug'];
if(($routeName['slug']=='who-is-my-rep'||$routeName['slug']=='distributor-self-promos'|| $routeName['slug']=='tradeshow'||$routeName['slug']=='sample-kits') && $this->userId==0)
{
// echo 'ss';die;
// return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
return $this->redirect($this->generateUrl('office_brain_userbundle_login_login',array("redirect_page_slug"=>$routeName['slug'])));
}
//die;
$this->responseArray = $this->cmsPageManager->getCmsPageBySlug();
if (!empty($this->responseArray['error']) && $this->responseArray['error'] == "PAGE_NOT_FOUND") {
throw $this->createNotFoundException($this->translator->trans('cms.front.page_not_found'));
}
return $this->responseArray;
}
// 48.75
// 37.50
// ----------
// 86.25
/**
* * @author Employee Id: 4465
* Description : Site Search
* *
* @Route("/search/list", name="office_brain_cmsbundle_cmspage_page_search",
* options={"expose"=true})
*
* @Method("GET")
*
* @Template("OfficeBrainCmsBundle:CmsPage:pageSearch.html.twig")
*/
public function pageSearchAction(Request $request)
{
$this->initAction($request);
$this->responseArray = $this->cmsPageManager->siteSearch($this->request);
return $this->responseArray;
}
/**
* * @author Employee Id: 4465
* Description : Site Search
* *
* @Route("/search/list", name="office_brain_cmsbundle_cmspage_page_search_ajax",
* options={"expose"=true})
*
* @Method("POST")
*
* @Template("OfficeBrainCmsBundle:CmsPage:pageSearchAjax.html.twig")
*/
public function pageSearchAjaxAction(Request $request)
{
$this->initAction($request);
$this->responseArray = $this->cmsPageManager->getSiteSearchList($this->request);
return $this->responseArray;
}
/**
* @author Employee Id: 4589
* Description : save inline edit page
*
* @param string slug
*
* @return JSON Response
*
* @throws NULL
*
* @Route("/inline/edit/{slug}", name="office_brain_cmsbundle_cmspage_pageinlineedit",
* options={"expose"=true})
*
* @Method("POST")
*
* @return array
*/
public function pageInlineEditAction(Request $request)
{
$this->initAction($request);
if ($this->cmsPageManager->updateCmsPageInline()) {
$this->responseArray = array('status' => 'success', 'success_message' => $this->translator->trans('cms.inline_edit.page_save_success'));
} else {
$this->responseArray = array('status' => 'error', 'error_message' => $this->translator->trans('cms.inline_edit.page_save_error'));
}
return new JsonResponse($this->responseArray);
}
/**
* @author Employee Id: 4795
*
* Description : Preview Template
*
* @Route("/cms/preview", name="office_brain_cmsbundle_cmspage_cmspagepreview")
* @Method("POST")
* @Template("OfficeBrain/Bundle/CmsBundle/CmsPage/page.html.twig")
*/
public function cmsPagePreviewAction(Request $request)
{
$this->initAction($request);
$this->responseArray = $this->cmsPageManager->previewCmsPage();
return $this->responseArray;
}
}