<?php
namespace OfficeBrain\CustomBundle\UserBundle\Manager\Extended;

use OfficeBrain\CustomBundle\UserBundle\Manager\AbstractManager\UserAbstract;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use OfficeBrain\Bundle\UserBundle\Entity\User;
use OfficeBrain\Bundle\UserBundle\Form\UserType;
use OfficeBrain\Bundle\UserBundle\Entity\EmployeeInfo;

/**
 *
 * @author Employee Id: 4273
 * OB eCommerce Product - User
 * UserExtended Class Add to override the user process
 */

class UserExtended extends UserAbstract
{
    /**
     * @author Employee Id: 4273
     * Initialize the required variable on class load
     *
    */
   public function __construct($entityManager, $request, $session,$paginatorManager,$userApiManager,$serviceGroupManager,$jmsSerializer,$coreManager, $emailService, $router)
    {
    	parent::__construct($entityManager, $request, $session,$paginatorManager,$userApiManager,$serviceGroupManager,$jmsSerializer,$coreManager, $emailService, $router);
    	$this->request = $request;
    	$this->entityManager = $entityManager;
    	$this->paginatorManager = $paginatorManager;
    	$this->projectSetting = $this->request->get('project_setting');
    	$this->projectUserSetting = $this->request->get('project_user_setting');    	
    	$this->serviceGroupManager = $serviceGroupManager;
    	$this->coreManager = $coreManager;
    	$this->customUserRepositoryManager = $this->entityManager->getRepository('OfficeBrainCustomBundleUserBundle:User');
    	$this->customUserRepositoryManager->setPaginatorService($this->paginatorManager);
    	$this->customUserRepositoryManager->setProjectSetting($this->projectSetting);
    	$this->customUserRepositoryManager->setProjectUserSetting($this->projectUserSetting);
    	$this->customUserRepositoryManager->setServiceGroupService($this->serviceGroupManager);
    	$this->customUserRepositoryManager->setCoreManager($this->coreManager);
    	$this->recordsPerPage = $this->projectSetting['configuration_rule']['site_management']['option']['cms']['option']['cms_page_record_per_page']['status'];
    }
    
    /**
     * @author Employee Id: 4493
     * OB eCommerce Product - findDistributorSite
     * Function created to findDistributorSite
     */
    public function findDistributorSite($page,$recordPerPage,$search_query = '')
    {
    	if($search_query && $search_query!= ''){
    		return $this->customUserRepositoryManager->findDistributorForSubShop($page,$recordPerPage,$search_query);    		
    	}else{
    		return array();
    	}    	 
    }
    
    
    /**
     * @author Employee Id: 4493
     * OB eCommerce Product - Core For Find Distributor Functionality
     * Function created to get state data
     */
    public function getFindDistributorStateData($stateOrCountryCode = '',$callType='')
    {
    	$stateOrCityData=array();
    	$stateOrCityResult=$this->customUserRepositoryManager->getDistributorsStateDetail($stateOrCountryCode ,$callType);
    	foreach ($stateOrCityResult as $key=>$value) {
    		if($callType && $callType=='country_code' ){
    			$stateOrCityData[$value['id']]=$value['stateName'];
    		}else if($callType && $callType=='state_code' ){
    			$stateOrCityData[$value['id']]=$value['cityName'];
    		}
    	}
    	return $stateOrCityData;
    }
    
    /**
     * @author Employee Id: 5497
     * OB eCommerce Product - getActiveUserList
     * Function created to getActiveUserList
     */
    public function getActiveUserList()
    {
    	$data = array();
    	$userAll = array();

    	$userList = $this->customUserRepositoryManager->getAllUserObject();
//     	foreach ($userList as $key => $val) {
//     		$userAll[$val->getId()] = array('name'=>$val->getFirstName()." ".$val->getLastName(),'email'=>$val->getEmail());
//     	}
    	$data['pagination'] = $this->paginatorManager->paginate($userList, $this->request->get('page'), 100, array(), count($promoCoupon));
    	$data['records_per_page'] = 100;
    	$data['page'] = $this->request->get('page');
    	
    	return $data;
    }
    
    /**
     * @author Employee Id: 5497
     * OB eCommerce Product - getAllUserList
     * Function created to getAllUserList
     */
    public function getAllUserList()
    {
    	$couponUsers = $this->customUserRepositoryManager->getAllUserObject();
    	if (count($couponUsers) > 0) {
    		$data['pagination'] = $this->paginatorManager->paginate($couponUsers, $this->request->get('page'), $this->recordsPerPage, array(), count($couponUsers));
    	}
    	
    	$data['records_per_page'] = $this->recordsPerPage;
    	$data['page'] = $this->request->get('page');
    	
    	return $data;
    }
}
