<?php

namespace OfficeBrain\CustomBundle\CmsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
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;

/**
 * @author OfficeBrain 5051 <info@officebrain.com>
 *
 * Description : CMS controller class
 *
 * @Route("/{_locale}")
 **/
class CmsFlashMessageController extends Controller
{
    private $request;
    private $session;
    private $translator;
    private $projectSetting;
    private $recordsPerPage;
    private $cmsFlashMessageManager;
    private $responseArray;

    public function __destruct()
    {
        unset($this->request);
        unset($this->session);
        unset($this->translator);
        unset($this->projectSetting);
        unset($this->cmsFlashMessageManager);
        unset($this->responseArray);
    }

    public function initAction()
    {
        $this->request = $this->getRequest();
        $this->session = $this->request->getSession();
        $this->translator = $this->get('translator');
        $this->projectSetting = $this->request->get('project_setting');
        $this->cmsFlashMessageManager = $this->get('office_brain_custom_cms_flash_message_manager');
        $this->responseArray = array();
    }

    /**
     * * @author Employee Id: 5051
     * Description : Get the page content and render page on fronend on home page
     * 	 *
     * @Route("/flash-message", name="office_brain_custombundle_cmsbundle_cmsflash_flashmessage")
     * @Template("OfficeBrainCustomBundleCmsBundle:CmsFlashMessage:flashMessage.html.twig")
     */
    public function flashMessageAction()
    {
        $this->initAction();
        $this->responseArray['data'] = $this->cmsFlashMessageManager->getCmsFlashMessage();
        if (!empty($this->responseArray['error']) && $this->responseArray['error'] == "MESSAGE_NOT_FOUND") {
            //throw $this->createNotFoundException($this->translator->trans('cms.front.flash_message.page_not_found'));
        	$this->responseArray = "";
        }
        return $this->responseArray;
    }
}
