<?php

namespace OfficeBrain\Bundle\PageBundle\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 Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
 *
 * @author Employee Id: 410175
 *
 * Desciption: Core Mobile API
 *
 * @param NULL
 *
 * @return NULL
 *
 * @throws NULL
 *
 * @Route("/api/v1/")
 *
 */
class HomePageMobileController extends Controller
{
	
/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Define member variables with thier default value
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL 
	 */
	public function __construct()
	{
		$this->request = null;
		$this->cultureCode = null;
		$this->projectSetting = null;
		$this->coreManager = null;
	}
	
	/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Unset member variables
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function __destruct()
	{
		unset($this->request);
		unset($this->cultureCode);
		unset($this->projectSetting);
		unset($this->coreManager);
	}
	
	/**
	 *
	 * @author Employee Id: 410175
	 *
	 * Desciption: Create and initialize various required object and member variables
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function initAction()
	{
		$this->request = $this->getRequest();
		$this->projectSetting = $this->request->get('project_setting');
		$this->cultureCode = $this->projectSetting['culture_code'];
		$this->bannerManager = $this->get('office_brain_banner_manager');
		$this->mobileAppManager = $this->get('office_brain_mobileapp_manager');
		$this->bannerBaseUrl = $this->getParameter('banner.image_url');
		$this->mobileAppBannerTypeId = $this->getParameter('mobile_app.banner_type_id');
	}
	/**
     *
     * @author Employee Id: 410175
     * Description : Fetch Active Banners
     *
     * @param : null
     *
     * @return null
     *
     * @throws null
     *
     * @Route("{_locale}/get-home-page-listing", name="office_brain_corebundle_homepagelisting_api")
     * 
     * @ApiDoc(
     *      resource=true,
     *      section="Home Page",
     *      description="Get Banner/Top Category/Best Deal Listing",
     *      requirements = {
     *      	{"name"="_locale", "default"="en_us","dataType"="string"},
     *      	{"name"="access_token", "dataType"="string", "required"=false, "description"="valid access token"},
     *      	{"name"="countryId", "dataType"="integer", "description"="Country Id "},
     *      },
     *      statusCodes={
     *              1="Returned when success",
     *              403="Returned when the user is not authorized to see this link",
     *              0="Returned when form validation is failed",
     *      }
     * )
     * 
     * @Method("GET")
     * 
     * @Template()
     *
     **/
    public function getHomePageListingAction()
    {	    	
        $this->initAction();
        $pageList = array();
        
        $bannerList = $this->bannerManager->fetchActiveMobileApiBanner($this->mobileAppBannerTypeId,$this->bannerBaseUrl);
        
        $pageList = $this->mobileAppManager->getHomePageListing();
        
        if( count($bannerList)<=0){
        	$bannerList = null;
        }
        $pageList['banner_list'] = $bannerList;
        
        return  array('status'=>'success','status_code'=>1,'data'=>$pageList);
    } 
}
