<?php

namespace OfficeBrain\Bundle\RequestInfoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use OfficeBrain\Bundle\RequestInfoBundle\Form\RequestInfoType;
use OfficeBrain\Bundle\RequestInfoBundle\Form\CommentRequestInfoType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use OfficeBrain\Bundle\RequestInfoBundle\Entity\GuestUser;
use OfficeBrain\Bundle\RequestInfoBundle\Entity\RequestInfo;
use OfficeBrain\Bundle\RequestInfoBundle\Entity\CommentRequestInfo;
use OfficeBrain\Bundle\RequestInfoBundle\Form\GuestUserType;

/**
 *
 * @author Employee Id: 4203
 * 
 * OB eCommerce Product - Request Info
 * 
 * - Do inquiry of Product
 * @Route("", defaults={"rule_service"="rule_charges"})
 * 
 */
class RequestInfoController extends Controller
{
	protected $user;
	protected $form;
	protected $request;
	protected $formData;
	protected $responseArray;
	protected $erpIntegration;
	protected $queueApiManager;
	protected $commonLibraryManager;

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 * Desciption: Define member variables with thier default value
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function __construct()
	{
		$this->user = null;
		$this->form = null;
		$this->request = null;
		$this->formData = null;
		$this->erpIntegration = null;
        $this->responseArray = array();
        $this->queueApiManager = null;
        $this->commonLibraryManager = null;
        $this->locale = null;
        $this->productId = null;
        $this->productSlug = null;
        $this->userManager = null;
        $this->page = null;
        $this->recordsPerPage = null;
	}

	/**
	 *
	 * @author Employee Id: 4203
	 *
	 * Desciption: Unset member variables
	 *
	 * @param NULL
	 *
	 * @return NULL
	 *
	 * @throws NULL
	 *
	 */
	public function __destruct() 
	{
		unset($this->user);
		unset($this->form);
		unset($this->request);
		unset($this->formData);
		unset($this->erpIntegration);
        unset($this->queueApiManager);
        unset($this->commonLibraryManager);
        unset($this->productId);
        unset($this->productSlug);
        unset($this->locale);
        unset($this->productId);
        unset($this->productSlug);
        unset($this->locale);
        unset($this->userManager);
        unset($this->page);
        unset($this->recordsPerPage);
	}
	
	/**
	 *
	 * @author Employee Id: 4203
	 *
	 * 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->userId = $this->projectSetting['user_id'];
		$this->projectUserSetting =$this->request->get('project_user_setting')['user_data'];
		if($this->userId>0){
			$this->userType=$this->projectUserSetting->getUserType();
		}else{
			$this->userType='end_user';
		}
		$this->productId = $this->request->get('product_id',null);
		$this->productSlug = $this->request->get('product_slug',null);
		$this->cultureId = $this->projectSetting['culture_id'];
		$this->locale = $this->projectSetting['culture_code'];
		$this->responseArray = array();
		$this->configurationRule = $this->projectSetting['configuration_rule']['transaction']['request_info'];
		$this->requestInfoManager = $this->get('office_brain_request_info_manager');
		$this->commonLibraryManager = $this->get('office_brain_common_library');
		$this->coreManager = $this->get('office_brain_core_manager');
		$this->erpIntegration = $this->projectSetting['configuration_rule']['erp_integration'];
		$this->page = $this->request->get('page', '1');
		$this->recordsPerPage = $this->request->get('records_per_page', $this->configurationRule['list_front']['option']['no_of_product']);
		//$this->recordsPerPage = "2";
		if ($this->has('office_brain_queue_api_manager')) {
			$this->request->attributes->set('object', 'RequestInfo');
			$this->queueApiManager = $this->get('office_brain_queue_api_manager');
		}
		$this->userManager = $this->get('office_brain_user_manager');
	}
	
	/**
	 * @author Employee Id: 4203
	 * 
	 * Description : Use to render request info section.
	 * 
	 * @param 1 : No paramater
	 * 
	 * @return type : Form view.
	 * 
	 * @throws Exception: Null
	 *
	 * @Route("/{_locale}/request-info/{product_slug}",
	 * name="office_brain_requestinfobundle_requestinfo_productdetailrequestinfo",
	 * options={"expose"=true}
	 * )
	 * @Template("OfficeBrainRequestInfoBundle:RequestInfo:productDetailRequestInfo.html.twig")
	 * @Method({"GET"})
	 */
	public function productDetailRequestInfoAction()
	{
		$this->initAction();
		return $this->requestInfoManager->getProductDetailBySlug($this->productSlug, $this->locale);
	}
	
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to render request info form. 
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
	 * 
     * @Route("/{_locale}/add-request-info/{product_id}",
     *  name="office_brain_requestinfobundle_requestinfo_addrequestinfo"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addRequestInfo.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
	public function addRequestInfoAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new RequestInfoType($this->configurationRule, $this->coreManager), new RequestInfo());
    	$this->responseArray['form'] = $this->form->createView();
    	$this->responseArray['product_id'] = $this->productId;
    	if(isset($this->configurationRule['preferred_distributor']) && $this->configurationRule['preferred_distributor']['status']==1 && in_array($this->userType,$this->configurationRule['preferred_distributor']['option']['user_type'])){
    		$this->responseArray['distributor_show'] = $this->configurationRule['preferred_distributor']['option']['show'];
    	}
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit request info form. 
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-request-info",
     *  name="office_brain_requestinfobundle_requestinfo_processrequestinfosubmit"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addRequestInfo.html.twig")
     * 
     * @Method({"POST"})
     * 
     */
    public function addRequestInfoSubmitAction()
    {
    	$option = null;	
        $this->initAction();
        /*$stateId = $this->request->get('state');
        $option['distributor'] = $this->getStateWiseDistributors(array('state_id'=>$stateId));*/
    	$this->form = $this->createForm(new RequestInfoType($this->configurationRule, $this->coreManager, $option), new RequestInfo());
    	$this->form->handleRequest($this->request);
    	$productId = $this->form->getData()->product_id;
    	if ($this->form->isValid()) {
    		$result = $this->requestInfoManager->setRequestInfo($this->form->getData());
			switch ($result['status']) {
    			case 'ADD_SUCCESS_IN_SESSION':
    				$this->responseArray['status'] = 'success';
    				break;
    			case 'ALLREADY_IN_SESSION':
    				$this->responseArray['status'] = 'error';
    				break;
    			case 'ADD_SUCCESS_SINGLE_GUEST':
    				if ($this->request->isXmlHttpRequest()) {
    					$this->responseArray['status'] = 'success';
    					$this->responseArray['popup_url'] = $this->generateUrl('office_brain_userbundle_login_login_popup',array('refer_url'=>'office_brain_requestinfobundle_requestinfo_addgguestuser'));
    				}
    				break;
    			case 'ADD_RECORD_SUCCESSFULLY':
    				if ($this->request->isXmlHttpRequest()) {
    					$requestInfoObj = $result['data'];
                        if (is_array($this->erpIntegration) && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
                            if ($requestInfoObj->getGuestId() == 0) {
                                $this->queueApiManager->mapQueue("create", $requestInfoObj);
                            }
                        }//dump($requestInfoObj);exit;
                        $this->requestInfoManager->sendRequestInfoEmail($requestInfoObj);
                        $this->responseArray['status'] = 'success';
                        $this->responseArray['goto_url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_thankupage');
                        unset($requestInfoObj);
    				}
    				break;
    		}
    		unset($result);
    		unset($requestInfo);
    		
    		return new JsonResponse($this->responseArray);
	    } elseif ($this->request->isXmlHttpRequest()) {
	        return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
	    }

    	return array('form' => $this->form->createView(), 'product_id'=>$productId);
    }
    
    private function getStateWiseDistributors($stateId){
    	$returnDistributors = array();
    	
    	$tempDistributors = $this->userManager->getDistributors(array('state_id'=>$stateId));
    	foreach ($tempDistributors as $dist){
    		$returnDistributors[$dist['id']] = $dist['firstName'].' '.$dist['lastName'];
    	}
    	
    	return $returnDistributors;
    }
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit request info form. 
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-guest-user",
     *  name="office_brain_requestinfobundle_requestinfo_addgguestuser"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addGuestUser.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function addGuestUserAction()
    {
    	$this->initAction();
    	$this->form = $this->createForm(new GuestUserType(), new GuestUser());
		return array('form'=>$this->form->createView());
    }
    
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-guest-user",
     *  name="office_brain_requestinfobundle_requestinfo_processaddgguestusersubmit"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addGuestUser.html.twig")
     * 
     * @Method({"POST"})
     * 
     */
    public function processAddGuestUserAction()
    {
        $this->initAction();

    	$this->form = $this->createForm(new GuestUserType(), new GuestUser());
    	$this->form->handleRequest($this->request);

    	if ($this->form->isValid()){
    		$result = $this->requestInfoManager->setGuestInfo($this->form->getData());
    		$requestInfoObj = $result['data'];
    		switch ($result['status']) {
    			case 'ADD_RECORD_SUCCESSFULLY':
                    
                    /*if(is_array($this->erpIntegration) && $this->erpIntegration['orderManagement'] == 1 && !empty($this->queueApiManager)) {
                        $this->queueApiManager->mapQueue("create", $requestInfoObj);
                    }*/
                    $this->requestInfoManager->sendRequestInfoEmail($requestInfoObj);
                    $this->responseArray['status'] = 'success';
                    $this->responseArray['goto_url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_thankupage');
                    
                    return new JsonResponse($this->responseArray);
    			}
    		}
    		else if ($this->request->isXmlHttpRequest ()) {
    			return new JsonResponse($this->commonLibraryManager->prepareFormJsonError($this->form));
    		}
    }
    
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/list-request-info",
     *  name="office_brain_requestinfobundle_requestinfo_listrequestinfo"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:listRequestInfo.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function listRequestInfoAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->responseArray['page'] = $this->page;
    	$this->responseArray['records_per_page'] = $this->recordsPerPage;
    	$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoList($this->page,$this->recordsPerPage);
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     * 
     * @Route("/{_locale}/my-inquiries-list",
     *  name="office_brain_requestinfobundle_requestinfo_myinquirylist",
     *  options={"expose"=true}
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:myInquiryList.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function myInquiryListAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->responseArray['user_type'] = $this->userType;
    	$this->responseArray['page'] = $this->page;
    	$this->responseArray['records_per_page'] = $this->recordsPerPage;
    	$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoList($this->page,$this->recordsPerPage);
    	
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/detail-request-info/{request_info_id}",
     *  name="office_brain_requestinfobundle_requestinfo_detailrequestinfo"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:detailRequestInfo.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function detailRequestInfoAction()
    {	
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route'),array('request_info_id'=>$this->request->get('request_info_id'))));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$this->responseArray['data'] = $this->requestInfoManager->getRequestInfoDetailById();
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-comment-request-info/{request_id}/{user_id}",
     *  name="office_brain_requestinfobundle_requestinfo_addcommentrequestinfo"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addCommentRequestInfo.html.twig")
     * @Method({"GET"})
     */
    public function addCommentRequestInfoAction()
    {
    	$this->initAction();
    	$userDetail = $this->requestInfoManager->getUserDetail($this->request->get('user_id'),'user');
    	$this->form=$this->createForm(new CommentRequestInfoType(), new CommentRequestInfo() );
    	$this->responseArray['form']=$this->form->createView ();
    	$this->responseArray['request_id'] = $this->request->get('request_id');
    	$this->responseArray['user_name'] = $userDetail->getFirstName().' '.$userDetail->getLastName();
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/add-comment-request-info",
     *  name="office_brain_requestinfobundle_requestinfo_processcommnentrequestinfosubmit"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:addCommentRequestInfo.html.twig")
     * 
     * @Method({"POST"})
     * 
     */
    public function addCommentRequestInfoSubmitAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	} 
    	$this->form = $this->createForm(new CommentRequestInfoType(), new CommentRequestInfo());
    	$this->form->handleRequest($this->request);
    	$requestId = $this->form->getData ()->requestInfoId;
    	if ($this->form->isValid()){
    		$result=$this->requestInfoManager->setCommentRequestInfo($this->form->getData());
    		switch ($result['status']) {
    			case 'COMMENT_ADDED_SUCESSFULLY':
    				if ($this->request->isXmlHttpRequest ()) {
    		    
    					$this->responseArray['status'] = 'success';
    					$this->responseArray['success_message'] = $this->get('translator')->trans('request_info.comment_added_successfully');
    					$this->responseArray['url'] = $this->generateUrl('office_brain_requestinfobundle_requestinfo_listcommentrequestinfo',array('request_info_id'=>$requestId));
    					return new JsonResponse ( $this->responseArray );
    				}
    				break;
    		}
    	}
    	else if ($this->request->isXmlHttpRequest ()) {
    		 
    		return new JsonResponse ( $this->commonLibraryManager->prepareFormJsonError($this->form) );
    	}
    	return array (
    			'form' => $this->form->createView (),
    			'request_id'=>$requestId
    	);
    }
    
    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/list-comment-request-info/{request_info_id}",
     *  name="office_brain_requestinfobundle_requestinfo_listcommentrequestinfo"
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:listCommentRequestInfo.html.twig")
     *  
     */
    public function listCommentRequestInfoAction()
    {
    	$this->initAction();
    	$this->responseArray['data'] = $this->requestInfoManager->getCommentRequestInfoList();
    	return $this->responseArray;
    }

    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: product thank you page
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/request-info-thank-you",
     * 	name="office_brain_requestinfobundle_requestinfo_thankupage"
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:thankYouRequestInfo.html.twig")
     * 
     */
    public function thankYouRequestInfoAction()
    {
    	$this->initAction();
    	$this->requestInfoManager->setContinueProdDetailURL($this->commonLibraryManager->getRefererRouteName(), $this->commonLibraryManager->getRefererUrl());
    	return array();
    }    
    
    /**
     *
     * @author Employee Id: 4074
     *
     * Desciption: This function allow user go back to page from where he/she came to Request Info.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/continue-request-info-from-product-detail",
     * 	name="office_brain_requestinfobundle_continue_request_info"
     * )
     *
     * @Method({"GET"})
     *
     */
    public function continueRequestInfoAction()
    {
    	/* $this->initAction();
    	return $this->redirect($this->requestInfoManager->getContinueProdDetailURL()); */
    	return $this->redirect($this->generateUrl('office_brain_searchbundle_search_continueshopping'));
    }
    
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to dalete a record
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/delete-request-info/{request_info_id}",
     *  name="office_brain_requestinfobundle_requestinfo_deleterequestinfo"
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template()
     * 
     */
    public function deleteRequestInfoAction()
    {
    	$this->initAction();
    	if( $this->userId==0){
    		if ($this->request->isXmlHttpRequest()) {
    			$this->responseArray['status'] = 'error';
    			$this->responseArray['error_type'] = 'loginError';
    			$this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
    			return new JsonResponse($this->responseArray);
    		}else{
    			$this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route'),array('request_info_id'=>$this->request->get('request_info_id'))));
    			return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
    		}
    	}
    	$requestInfoDetail = $this->requestInfoManager->deleteRequestInfoDetailById();
    	switch ($requestInfoDetail['status']) {
    		case 'ERROR_NOT_FOUND':
    			$this->responseArray['error_message'] = $this->get('translator')->trans('request_info.no_record');
    			break;
    		case 'SUCCESS':
    			$this->responseArray['status'] = 'success';
    			$this->responseArray['inquiry_list'] = 'inquiry_info';
    			$this->responseArray['success_message'] = $this->get('translator')->trans('request_info.remove_success_message');
    			break;
    	}
    	if ($this->request->isXmlHttpRequest()) {
    		return new JsonResponse($this->responseArray);
    	}
    }
    
    /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit Commemt Request Info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/customer-detail/{user_id}/{user_type}",
     *  name="office_brain_requestinfobundle_requestinfo_customerdetailinfo"
     * )
     * 
     * @Method({"GET"})
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:customerDetailInfo.html.twig") 
     * 
     */
    public function customerDetailInfoAction()
    {
    	$this->initAction();
    	$this->responseArray['user_detail'] = $this->requestInfoManager->getUserDetail($this->request->get('user_id'), $this->request->get('user_type'));
    	return $this->responseArray;
    }
    
    /**
     *
     * @author Employee Id: 410175
     *
     * Desciption: get All state wise distributors
     *
     * @param NULL
     *
     * @return Html Response
     *
     * @throws NULL
     *
     * @Route("/{_locale}/select-distributors",
     *  name="office_brain_requestinfobundle_requestinfo_selectdistributors",
     *  options={"expose"=true}
     * )
     *
     * @Method({"POST"})
     *
     * @Template()
     *
     */
    public function selectDistributorsAction()
    {
    	$this->initAction();
    	$filter['stateId'] = $this->request->get('stateId');
    	$data['distributors'] = $this->userManager->getDistributors($filter);
    	if ($this->request->isXmlHttpRequest()) {
    		return new JsonResponse($data);
    	}
    	return $data;
    }

    /**
     *
     * @author Employee Id: 4248
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     * 
     * @Route("/{_locale}/my-request-sample-list",
     *  name="office_brain_requestinfobundle_requestinfo_myrequestsamplelist",
     *  options={"expose"=true}
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:myRequestSampleList.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function myRequestSampleListAction()
    {  
        $this->initAction();
        if( $this->userId==0){
            if ($this->request->isXmlHttpRequest()) {
                $this->responseArray['status'] = 'error';
                $this->responseArray['error_type'] = 'loginError';
                $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
                return new JsonResponse($this->responseArray);
            }else{
                $this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
                return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
            }
        }
        $this->responseArray['user_type'] = $this->userType;
        $this->responseArray['page'] = $this->page;
        $this->responseArray['records_per_page'] = $this->recordsPerPage;
        $this->responseArray['data'] = $this->requestInfoManager->getRequestSampleList($this->page,$this->recordsPerPage);
        return $this->responseArray;
    }

        /**
     *
     * @author Employee Id: 4203
     *
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/list-request-sample",
     *  name="office_brain_requestinfobundle_requestinfo_listrequestsample"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:listRequestSample.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function listRequestsampleAction()
    {   
        $this->initAction();
        if( $this->userId==0){
            if ($this->request->isXmlHttpRequest()) {
                $this->responseArray['status'] = 'error';
                $this->responseArray['error_type'] = 'loginError';
                $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
                return new JsonResponse($this->responseArray);
            }else{
                $this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
                return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
            }
        }
        $this->responseArray['page'] = $this->page;
        $this->responseArray['records_per_page'] = $this->recordsPerPage;
        $this->responseArray['data'] = $this->requestInfoManager->getRequestSampleList($this->page,$this->recordsPerPage);
        return $this->responseArray;
    }

     /**
     *
     * @author Employee Id: 4203
     *
     * Desciption: Use to submit guest user info form.
     *
     * @param NULL
     *
     * @return Html Response 
     *
     * @throws NULL
     *
     * @Route("/{_locale}/list-ask-question",
     *  name="office_brain_requestinfobundle_requestinfo_listaskquestioninfo"
     * )
     * 
     * @Template("OfficeBrainRequestInfoBundle:RequestInfo:listAskQuestion.html.twig")
     * 
     * @Method({"GET"})
     * 
     */
    public function listAskQuestionInfoAction()
    {
        $this->initAction();
        if( $this->userId==0){
            if ($this->request->isXmlHttpRequest()) {
                $this->responseArray['status'] = 'error';
                $this->responseArray['error_type'] = 'loginError';
                $this->responseArray['page_url'] = $this->generateUrl('office_brain_userbundle_login_login');
                return new JsonResponse($this->responseArray);
            }else{
                $this->get('session')->set('_security.main.target_path', $this->generateUrl($this->request->get('_route')));
                return $this->redirect($this->generateUrl('office_brain_userbundle_login_login'));
            }
        }
        $this->responseArray['page'] = $this->page;
        $this->responseArray['records_per_page'] = $this->recordsPerPage;
        $this->responseArray['data'] = $this->requestInfoManager->getAskQuestionList($this->page,$this->recordsPerPage);
        return $this->responseArray;
    }
}
