<?php

namespace OfficeBrain\Bundle\BannerBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use OfficeBrain\Bundle\BannerBundle\Entity\Banner;
use OfficeBrain\Bundle\BannerBundle\Entity\BannerLanguage;
//use OfficeBrain\Bundle\BannerBundle\Entity\BannerCountry;
use OfficeBrain\Bundle\BannerBundle\Form\BannerType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Validator\Constraints\Count;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;

/**
 *
 * @author OfficeBrain 4571 <info@officebrain.com>
 *
 * Description: Front Controller used to Display Banner in front
 *
 * @Route("/api/v1", defaults={"_format" = "json"})
 *
 */
class ApiBannerController extends BannerController
{
	const SUCCESS = 'success';
	const ERROR = 'error';
	const SUCCESS_CODE = 1;
	const ERROR_CODE = 0;
	
    private $translator;
    private $request;
    private $projectSetting;
    private $manager;
    private $isAjax;
    private $session;
    private $responseArray;
    
    /**
     *
     * @author Employee Id: 4571
     * Description : To initialize variables
     *
     * @param  : null
     *
     * @return null
     *
     * @throws null
     *
     **/
    public function __construct()
    {
    	parent::__construct();        
    }
    
    /**
     *
     * @author Employee Id: 4571
     * Description : To unset member variables
     *
     * @param  : null
     *
     * @return null
     *
     * @throws null
     *
     **/
    public function __destruct()
    {
    	parent::__destruct();
    }
    
    /**
     *
     * @author Employee Id: 4571
     * Description : to initialize request and services
     *
     * @param : null
     *
     * @return null
     *
     * @throws null
     *
     **/
    public function initAction()
    {
    	parent::initAction();
    	$this->request = $this->getRequest();
        $this->manager = $this->get('office_brain_banner_manager');
        $this->translator = $this->get('translator');
        $this->session = $this->request->getSession();
        $this->isAjax = $this->request->isXmlHttpRequest();
        $this->projectSetting = $this->request->get('project_setting');
    }
    
    /**
     *
     * @author Employee Id: 4571
     * Description : Fetch Active Banners
     *
     * @param : null
     *
     * @return null
     *
     * @throws null
     *
     * @Route("/{_locale}/banner/get-banners", name="office_brain_bannerbundle_banner_getallactivebanner_api")
     * 
     * @ApiDoc(
     *      resource=true,
     *      section="Banner",
     *      description="Get All Active Banner List.",
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      },
     *      requirements={     
     *             {"name"="_locale", "dataType"="string", "required"=true, "default"="en_us"},
     *             {"name"="access_token", "dataType"="string", "required"=true, "description"="valid access token"},
     *             {"name"="instance_id", "dataType"="integer", "required"=true, "description"="valid instance_id"},
     *             {"name"="instance_type", "dataType"="string", "required"=true, "description"="valid instance_type"},
     *             {"name"="displayOn", "dataType"="string", "required"=true, "description"=""},
     *             {"name"="searchQuery", "dataType"="string", "required"=true, "description"=""},
     *             {"name"="categoryFilter", "dataType"="string", "required"=true, "description"=""},
     *             {"name"="slug", "dataType"="string", "required"=true, "description"="valid product slug"},
     *      },
     * )
     * 
     * @Template()
     * @Method("GET")
     *
     **/
    public function getAllActiveBannerAction()
    {
    	$this->initAction();
    	$directory = $this->getParameter('banner.image_url');
    	$this->responseArray['banner_list'] = $this->manager->fetchActiveBanner();
    	$this->responseArray['image_path'] = $directory;
    
    	return $this->responseArray;
    }
       
}
