<?php
namespace OfficeBrain\Bundle\EcatalogueBundle\Manager\AbstractManager;;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use OfficeBrain\Bundle\EcatalogueBundle\Entity\EcatalogueLanguage;

/**
 * @author Employee Id: 4488
 */
abstract class EcatalogueAbstract
{
	/**
	 * @author Employee Id: 4488
	 */
	
	protected $countryId;
	protected $countryCode;
	
	protected $languageId;
	protected $languageCode;
	
	protected $culture;
	protected $cultureAjax;
	protected $translatorManager;
	protected $translator;
	protected $paginationManager;
	protected $prioritizeEcatalogueRepository;
	protected $ecatalogueRepositoryManager;
	protected $emailManager;
	protected $projectSetting;
	protected $coreManager;
	protected $requestCopyCountry;
	protected $requestCopyStatus;
	protected $ecataloguefileParameter;
	protected $ecatalogueImageParameter;
	public function __construct($entityManager, $request, $sessionManager, $paginationManager, $country, $language, $transalatorManager,$emailManager,$coreManager)
	{
		$this->entityManager = $entityManager;
		$this->request= $request;
		$this->sessionManager = $sessionManager;
		$this->paginationManager=$paginationManager;
		$this->country=$country;
		$this->language=$language;
		$this->ecatalogueRepositoryManager = $this->entityManager->getRepository('OfficeBrainEcatalogueBundle:Ecatalogue');
		$this->projectSetting = $this->request->get('project_setting');
		$this->projectUserSetting = $this->request->get('project_user_setting');
		$this->instanceId = $this->projectSetting['instance_id'];
		$this->instanceType = $this->projectSetting['instance_type'];
		$this->userId = $this->projectSetting['user_id'];
		$this->cultureId = $this->projectSetting['culture_id'];
		$this->cultureCode = $this->projectSetting['culture_code'];
		if ($this->request->get('instance_id') > 0)
		{
			$this->ecatalogueRepositoryManager->setSubshopInstanceId($this->instanceId);
			$this->projectSetting['instance_id'] = $this->request->get('instance_id');
			$this->projectSetting['instance_type'] = $this->entityManager->getRepository('OfficeBrainAccessManagementBundle:InstanceMaster')->find($this->request->get('instance_id'))->getInstanceType();
		}
		$this->prioritizeEcatalogueRepository = $this->entityManager->getRepository('OfficeBrainEcatalogueBundle:PrioritizeCatalogue');
		$this->prioritizeEcatalogueRepository->setProjectSetting($this->projectSetting);
		$this->prioritizeEcatalogueRepository->setProjectUserSetting($this->projectUserSetting);
		$this->ecatalogueRepositoryManager->setProjectSetting($this->projectSetting);
		$this->ecatalogueRepositoryManager->setProjectSetting($this->projectSetting);
		$this->ecatalogueRepositoryManager->setProjectUserSetting($this->projectUserSetting);
		$this->culture = $this->request->get('_locale');
		$this->cultureAjax = $this->request->get('culture');
		$this->cultureSearchAjax = $this->request->get('culture');
		$this->getCultureValue();
		$this->translator = $transalatorManager;
		$this->ecatalogueRepositoryManager->setPaginatorService($this->paginationManager);
		$this->ecatalogue_per_page=$this->projectSetting['configuration_rule']['promo_discount']['option']['ecatalogue']['no_of_record_per_page'];
		$this->ecatalogueRecordsPerPage = $this->request->get('records_per_page', $this->ecatalogue_per_page);
		$this->emailManager = $emailManager;
		$this->coreManager=$coreManager;
		$this->ecataloguefileParameter=$this->projectSetting['configuration_rule']['promo_discount']['option']['ecatalogue']['ecatalogue_file_upload_parameter'];
		$this->ecatalogueImageParameter=$this->projectSetting['configuration_rule']['promo_discount']['option']['ecatalogue']['ecatalogue_image_upload_parameter'];
		$this->requestCopyCountry=$this->request->get('make_copy_country',null);
		$this->requestCopyStatus=$this->request->get('make_copy_status',null);
	}
	
	/**
	 * @author Employee Id: 4571
	 * 
	 * Description : Fetching id wise ecatalog details
	 *
	 * @param $id
	 *
	 * @return result
	 *
	 * @throws null
	 *
	 **/
	public function getEcatalogue2($id)
	{
		return $this->ecatalogueRepositoryManager->findById($id);
	
	}
	
	/**
	 *
	 * @author Employee Id: 4571
	 * Description : seprate culture with language and country.
	 *
	 * @param : null
	 *
	 * @return null
	 *
	 * @throws null
	 *
	 **/
	public function getCultureValue()
	{
		$cultures = array();
		if (isset($this->culture) && $this->culture != "") {
			list($this->languageCode, $this->countryCode) = explode("_", $this->culture);
		}
		return $cultures;
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : get Country wise collection
	 *
	 * @param : null
	 *
	 * @return ecatalogue object
	 *
	 * @throws null
	 *
	 **/
	
	public function getCountry()
	{
		$countryConfiguration=array();
		foreach ($this->country as $key=>$value) {
			$countryConfiguration[$value['id']]=$value['name']; // short_name
		}
		return $countryConfiguration;
	}
	/**
	 * @author Employee Id: 4488
	 * Description : get language wise collection
	 *
	 * @param 1 : Ecatalogue object
	 *
	 * @return Ecatalogue object
	 *
	 * @throws null
	 *
	 **/
	public function getLanguage($ecatalogue)
	{
		$language = $this->language;
		foreach ($language as $key => $value) {
			$langid = $value['id'];
			$ecatalogueLang = new EcatalogueLanguage();
			$ecatalogueLang->setLanguageId($langid);
			$ecatalogue->getEcatalogueLanguage()[] = $ecatalogueLang;
		}
		return $ecatalogue;
	}
	
	public function getAllSupplier()
	{
		$supplierData=array();
		$data= $this->ecatalogueRepositoryManager->getAllSupplier();
		foreach ($data as $key=>$value) {
			$supplierData[$value['id']]=$value['firstName'].' '.$value['lastName'];
		}
		return $supplierData;
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : Filter Form data
	 *
	 * @param 1 : null
	 *
	 * @return object
	 *
	 * @throws null
	 *
	 **/
	public function filterFormData($form,$isedit='')
	{
		$ecatalogueGroup = $form->getData();
		$countryId = $ecatalogueGroup->getCountryId();
		if ($countryId) {
			$countryCode = $this->getCountryField($countryId, 'id', 'code');
			
			foreach ($ecatalogueGroup->getEcatalogueLanguage()as $index=>$language) {
				if (!in_array($language->getLanguageId(), $this->country[$countryCode]["language"])) {
					unset($ecatalogueGroup->getEcatalogueLanguage()[$index]); // $language->getLanguageId()
				}else {
                     if ($ecatalogueGroup->getEcatalogueLanguage()[$index]->getEcatalogueTitle() == '') {
                        $form->get('ecatalogueLanguage')[$index]->get('ecatalogueTitle')->addError(new \Symfony\Component\Form\FormError($this->translator->trans('admin.ecatalogue.title.not_blank')));
                    }
                    if ($ecatalogueGroup->getEcatalogueLanguage()[$index]->getCatalogueImage() == '' && $isedit =='') {
                    	$form->get('ecatalogueLanguage')[$index]->get('catalogueImage')->addError(new \Symfony\Component\Form\FormError($this->translator->trans('admin.ecatalogue.image.not_blank')));
                    }
                    /* if ($ecatalogueGroup->getEcatalogueLanguage()[$index]->getCatalogueFile() == '' && $isedit =='') {
                    	$form->get('ecatalogueLanguage')[$index]->get('catalogueFile')->addError(new \Symfony\Component\Form\FormError($this->translator->trans('admin.ecatalogue.ecatalogfile.valid_file')));
                    } */ 
                    
                }
			}
		}
		return $form;
	}
	/**
	 * @author Employee Id: 4571
	 * Description : Get country field
	 *
	 * @param 1 : $culture
	 * @param 2 : String Search Field
	 * @param 3:  string key
	 *
	 * @return object
	 *
	 * @throws null
	 *
	 **/
	public function getCountryField($culture, $searchField, $returnField)
	{
		foreach ($this->country as $key => $country) {
			if ($culture == $country[$searchField]) {
				if ($returnField != 'code') {
					return $country[$returnField];
				} else {
					return $key;
				}
			}
		}
	}
	public function addEcatalogue($ecatalogueData='')
	{
		$start1 = strtotime($ecatalogueData->getStartDate()->format('Y-m-d'));
		$end1 = strtotime($ecatalogueData->getEndDate()->format('Y-m-d'));
			
		$flag = false;
		if($start1 > $end1){
			return $this->responseArray = 'INVALID_DATE';
		}
		foreach($ecatalogueData->getEcatalogueLanguage() as $key=>$value)
		 {
			 $imageData=$ecatalogueData->getEcatalogueLanguage()[$key]->getCatalogueImage();
			 $imageFlag=$this->coreManager->uploadImage($this->ecatalogueImageParameter, $imageData, 'ecatalogue');
			 if($imageFlag!='SUCCESS')
				 return $imageFlag;
			 $fileData=$ecatalogueData->getEcatalogueLanguage()[$key]->getCatalogueFile();
			 if($fileData!='')
			 {
			 	$fileFlag=$this->coreManager->uploadFile($this->ecataloguefileParameter, $fileData, 'ecatalogue');
			 	if($fileFlag!='SUCCESS')
			 		return $fileFlag;
			 }
			 
		} 
		$this->ecatalogue=$this->ecatalogueRepositoryManager->saveEcatalogue($ecatalogueData);
		if($this->ecatalogue->getId() && ($this->requestCopyCountry !='' || $this->requestCopyStatus !='')){
			$this->copyEcatalogueGroup($this->ecatalogue->getId(),$this->requestCopyCountry,$this->requestCopyStatus,'add');
		}
		if ($this->ecatalogue) {
			return 'SUCCESS';
		}
		return 'FAIL'; 
	}
	/**
	 * @author Employee Id: 4488
	 * OB eCommerce Product - ecatalogue
	 * Function created for edit ecatalogue
	 */
	public function editEcatalogue($ecatalogueData='',$ecatalogueLanguageData='')
	{
		$start1 = strtotime($ecatalogueData->getStartDate()->format('Y-m-d'));
		$end1 = strtotime($ecatalogueData->getEndDate()->format('Y-m-d'));
			
		$flag = false;
		if($start1 > $end1){
			return $this->responseArray = 'INVALID_DATE';
		}
		$imageData='';
		foreach($ecatalogueData->getEcatalogueLanguage() as $key=>$value)
		{
			$imageData=$ecatalogueData->getEcatalogueLanguage()[$key]->getCatalogueImage();
		 	if($imageData !='')
		 	{
		 		$imageFlag=$this->coreManager->uploadImage($this->ecatalogueImageParameter, $imageData, 'ecatalogue');
		 		if($imageFlag!='SUCCESS')
		 			return $imageFlag;
		 			
		 	}
			$fileData=$ecatalogueData->getEcatalogueLanguage()[$key]->getCatalogueFile();
			if($fileData!='')
			{
				$fileFlag=$this->coreManager->uploadFile($this->ecataloguefileParameter, $fileData, 'ecatalogue');
				if($fileFlag!='SUCCESS')
					return $fileFlag;
			} 
		}
		
		$this->ecatalogue=$this->ecatalogueRepositoryManager->editEcatalogue($ecatalogueData,$ecatalogueLanguageData);
		if ($this->ecatalogue) {
			return 'SUCCESS';
		}
		return 'FAIL'; 
	}
	public function getEcatalogueList($userId,$countFlagForStatus='',$searchParameterArray='',$page,$recordsPerPage,$status='',$option='',$keywords='',$categoryOption='')
	{
		$adminUser = false;
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}
		$this->getCultureValueAjaxSearch();
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		if ($this->languageCode) {
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		}
		if($countFlagForStatus == 1)
		{
			$this->ecatalogueData=$this->ecatalogueRepositoryManager->getEcatalogueRecordSetCount($userId,$countFlagForStatus,$this->countryId,$this->languageId,$adminUser,$page,$recordsPerPage,$option,$keywords,$categoryOption);
		}
		else
		{
			$this->ecatalogueData=$this->ecatalogueRepositoryManager->getEcatalogueRecordSet($userId,$countFlagForStatus,$this->countryId,$this->languageId,$adminUser,$page,$recordsPerPage);
		}
			return $this->ecatalogueData;	
	}
	
	/**
	 * @author Employee Id: 4571
	 * Description : fetch ecatalogue list for prioritizing
	 *
	 * @param  : null
	 *
	 * @return data
	 *
	 * @throws null
	 *
	 * */
	public function prioritizeEcatalogueList()
	{		
		$adminUser = false;
		
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}		 
		
		$locale = $this->request->get('_locale');
		 
		@list($localeCulture,$localeCountry) = explode("_", $locale);
		$langId =  $this->getLanguageIdByCode($localeCulture);
		$countryId = $this->getCountryIdByCode(strtolower($localeCountry));	
		
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getAllEcatalogue($langId, $countryId, $adminUser);
		
		
		return $this->ecatalogueData;
		
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : get culture code
	 *
	 * @param 1 : string $cultureCode
	 *
	 * @return int $countryId
	 *
	 * @throws null
	 *
	 * */
	public function getCountryIdByCode($cultureCode)
	{
		$countries = $this->country;
		foreach ($countries as $key => $country) {
			if ($cultureCode == $country['short_name']) {  // $country['short_name'] // $key
				return $country['id'];
			}
		}
	}
	/**
	 * @author Employee Id: 4488
	 * Description : get culture code by Ajax
	 *
	 * @param 1 : string $cultureCode
	 *
	 * @return int $countryId
	 *
	 * @throws null
	 *
	 * */
	public function getCountryIdByCodeBYAjax($cultureCode)
	{
		$countries = $this->country;
		foreach ($countries as $key => $country) {
			 if ($cultureCode == $country['short_name']) {  // $country['short_name'] // $key
			 	return $country['id'];
			} 
		}
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : Get Language id by Code
	 *
	 * @param 1 : string $languageCode
	 *
	 * @return lang id
	 *
	 * @throws null
	 *
	 **/
	public function getLanguageIdByCode($languageCode)
	{
		foreach ($this->language as $key => $lan) {
			if ($languageCode == $key) {
				return $lan['id'];
			}
		}
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Get Ecatalogue Search List
	 *
	 * @param null
	 *
	 * @return Data Array
	 *
	 * @throws null
	 *
	 **/
	public function getEcatalogueSearchListAjax($userId,$countFlagForStatus ,$searchParameterArray, $page, $recordsPerPage,$option,$keywords,$countryCode,$categoryOption)
	{
		$adminUser = false;
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}
		$this->getCultureValueAjaxSearch();
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getEcatalogueSearchRecordSet($userId,$countFlagForStatus,$this->countryId,$option,$keywords,$adminUser,$categoryOption,$page, $recordsPerPage);
		return $this->ecatalogueData;
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : Get Ecatalogue List
	 *
	 * @param null
	 *
	 * @return Data Array
	 *
	 * @throws null
	 *
	 **/
	public function getEcatalogueListAjax($userId, $countFlagForStatus ,$searchParameterArray, $page, $recordsPerPage, $requestStatus,$option='',$keywords='',$categoryOption='')
	{
		$adminUser = false;
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}
		$this->getCultureValueAjax();
		if ($this->countryCode) {
			$this->countryId = $this->getCountryIdByCode($this->countryCode);
		}
		if ($this->languageCode) {
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		}
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getEcatalogueRecordSet($userId,$countFlagForStatus,$this->countryId,$this->languageId,$adminUser,$page,$recordsPerPage,$option,$keywords,$categoryOption);
		return $this->ecatalogueData;
	}
	/**
	 *
	 * @author Employee Id: 4488
	 * Description : seprate culture with language and country.
	 *
	 * @param : null
	 *
	 * @return null
	 *
	 * @throws null
	 *
	 **/
	public function getCultureValueAjax()
	{
		$cultures = array();
		$this->cultureAjax = $this->request->get('culture');
		if (isset($this->cultureAjax) && $this->cultureAjax != "") {
			list($this->languageCode, $this->countryCode) = explode("_", $this->cultureAjax);
		}
		return $cultures;
	}
	
	public function getCultureValueAjaxSearch()
	{
		$cultures = array();
		$this->cultureSearchAjax = $this->request->get('culturecountry');
		if (isset($this->cultureSearchAjax) && $this->cultureSearchAjax != "") {
			list($this->languageCode, $this->countryCode) = explode("_", $this->cultureSearchAjax);
		}
		return $cultures;
	}
	
	/**
	 * @author Employee Id: 4488
	 * Description : Make a copy manage from list view
	 *
	 * @param null
	 *
	 * @return true/false
	 *
	 * @throws null
	 *
	 **/
	public function copyEcatalogueGroup($ecatalogueGroupId,$copyCountry,$copyStatus,$makecopy)
	{
		if ($ecatalogueGroupId) {
            $ecatalogueGroup = $this->getEcatalogue($ecatalogueGroupId);
            if ($ecatalogueGroup) {
                foreach ($copyCountry as $countryId=>$value) {
                	
                    if (isset($copyStatus[$countryId])) {
                        $this->makeCopyEcatalogueGroup(clone $ecatalogueGroup, $countryId, true,$makecopy);
                    } else {
                        $this->makeCopyEcatalogueGroup(clone $ecatalogueGroup, $countryId, false,$makecopy);
                    }
                }
                $this->entityManager->flush();
            }
            return true;
        }
        return false;
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Make a Copy of Ecatalogue from Object
	 *
	 * @param 1: obj $ecatalogue1,
	 * @param 2: int $countryId
	 * @param 3: int $isActive
	 *
	 * @return object
	 *
	 * @throws null
	 *
	 **/
	public function makeCopyEcatalogueGroup($ecatalogueObj, $countryId, $isActive,$makecopy)
	{
		$ecatalogueObj->setId(null);
		if ($countryId) {
			$ecatalogueObj->setStatus($isActive);
			$ecatalogueObj->setCountryId($countryId);
			$countryCode = $this->getCountryField($countryId, 'id', 'code');
			$ecatalogueLanguageObj=$ecatalogueObj->getEcatalogueLanguage();
			$copiedLang = array();
			foreach ($this->country[$countryCode]["language"] as $languageId) {
				
// 					 if ($languageId == $ecatalogueLanguageObj[0]->getLanguageId()) {
					 	$lang = clone $ecatalogueLanguageObj[0];
						$lang->setEcatalogueId($ecatalogueObj);
						$lang->setLanguageId($languageId);
						$lang->setEcatalogueTitle("copy of ".$ecatalogueLanguageObj[0]->getEcatalogueTitle());
						$ecatalogueObj->addEcatalogueLanguage($lang);
						
						
						$copiedLang[] = $lang->getLanguageId();
					/* } elseif (!in_array($ecatalogueLanguageObj[0]->getLanguageId(), $copiedLang)) {
						$ecatalogueObj->removeEcatalogueLanguage($ecatalogueLanguageObj);
					} */ 
			}
			$this->ecatalogueRepositoryManager->set($ecatalogueObj);
		}
	}
	/**
	 * @author Employee Id: 4488
	 * Description : Fetching id wise repository details
	 *
	 * @param $id
	 *
	 * @return result
	 *
	 * @throws null
	 *
	 **/
	public function getEcatalogue($id)
	{
		return $this->ecatalogueRepositoryManager->find($id);
	}
	public function getEcatalogueListById($ecatalogueId)
	{
		if($ecatalogueId)
		return $this->ecatalogueRepositoryManager->getEcatalogueDetailsById($ecatalogueId);
	}
	public function getEcatalogueEditListById($ecatalogueId)
	{
		if($ecatalogueId)
			return $this->ecatalogueRepositoryManager->getEcatalogueEditDetailsById($ecatalogueId);
	}
	public function getEcatalogueBy($ecatalogueId)
	{
		if($ecatalogueId)
			return $this->ecatalogueRepositoryManager->find($ecatalogueId);
	}
	public function deleteEcatalogue($requestEcatalogueId)
	{
		$isDeletObj=$this->ecatalogueRepositoryManager->getEcatalogueDetailsById($requestEcatalogueId);
		if (count($isDeletObj)) {
			$ecatalogueObj=$this->ecatalogueRepositoryManager->deleteEcatalogue($requestEcatalogueId);
			if ($ecatalogueObj) {
				return array('status'=>'SUCCESS','data'=>$ecatalogueObj);
			} else {
				return array('status'=>'FAIL');
			}
		}
		return array('status'=>'ISEXIST');
	}
	public function updateStatus($ecatalogueId)
	{
		$ecatalogueObj = $this->getEcatalogueBy($ecatalogueId);
		$status = $ecatalogueObj->getStatus();
		if (isset($status) and $status==1) { $status = 0 ; } else { $status=1;}
		$ecatalogueObj->setStatus($status);
		$resultarray = $this->ecatalogueRepositoryManager->updateStatus($ecatalogueObj);
		return $resultarray;
	}
	
	public function getCategoryEcatalogueList($userId,$ecatalogueCategoryId)
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$this->ecatalogueCategoryData=$this->ecatalogueRepositoryManager->getCategoryEcatalogueRecordSet($userId,$ecatalogueCategoryId,$this->languageId,$this->countryId);
		return $this->ecatalogueCategoryData;
	}
	public function getSupplierEcatalogueList($userId,$ecatalogueSupplierId)
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$this->ecatalogueSuuplierData=$this->ecatalogueRepositoryManager->getSupplierEcatalogueRecordSet($userId,$ecatalogueSupplierId,$this->languageId,$this->countryId);
		return $this->ecatalogueSuuplierData;
	}
	public function getActiveEcatalogueList($userId)
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getActiveEcatalogueRecordSet($userId,$this->countryId,$this->languageId);
		return $this->ecatalogueData;
	}
	public function getActiveLatestFiveEcatalogueList()
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
			if ($this->countryCode)
				$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
				$this->ecatalogueData=$this->ecatalogueRepositoryManager->getActiveLatestFiveEcatalogueRecordSet($this->countryId,$this->languageId);
				return $this->ecatalogueData;
	}
	public function getMappingEcatalogueCategory()
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$category=array();
		$mappingCategory=array();
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getMappingEcatalogueCategory($this->countryId,$this->languageId);
		foreach ($this->ecatalogueData as $key=>$value)
		{
			if($this->ecatalogueData[$key]['category']!='')
				$mappingCategory[]=explode(',', $this->ecatalogueData[$key]['category']);
		}
		if(!empty($mappingCategory))
		{
			foreach ($mappingCategory as $key=>$value)
			{
				foreach ($mappingCategory[$key] as $mapkey=>$mapvalue)
					$category[]=$mappingCategory[$key][$mapkey];
			}
		}
		$category=array_unique($category);
		return $category;
	}
	public function getMappingEcatalogueSupplier($userManager)
	{
		if ($this->languageCode)
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$supplierData=array();
		$this->ecatalogueData= $this->ecatalogueRepositoryManager->getMappingEcatalogueSupplier($this->countryId,$this->languageId);
		foreach ($this->ecatalogueData as $key=>$value) {
			$supplierData[$value['id']]= $value['companyName']; // $value['firstName'].' '.$value['lastName'];
		}
		return $supplierData;
	}
	
	public function setPriorityForEcatalog($allPostCatalogues)
	{
		$position = '';
		$id = '';
		
		foreach($allPostCatalogues as $key=>$val)
		{
			$id = $key;
			$position = $val;
			$this->prioritizeEcatalogueRepository->setValues($id, $position, $this->userId);
			
		}
		
	}
	
	/**
	 * @author Employee Id: 4571
	 * 
	 * Description : Get Ecatalogue List
	 *
	 * @param null
	 *
	 * @return Data Array
	 *
	 * @throws null
	 *
	 **/
	public function getCustomEcatalogueListAjax($userId) //  $countFlagForStatus ,$searchParameterArray, $page, $recordsPerPage, $requestStatus
	{
		$adminUser = false;
		
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}
		$this->getCultureValueAjax();
		if ($this->countryCode) {
			$this->countryId = $this->getCountryIdByCode($this->countryCode);
		}
		if ($this->languageCode) {
			$this->languageId = $this->getLanguageIdByCode($this->languageCode);
		}
		//echo $this->countryId." >> ".$this->languageId; die;
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getCustomEcatalogueRecordSet($userId,$this->countryId,$this->languageId,$adminUser);
		return $this->ecatalogueData;
	}
	
	/**
	 * @author Employee Id: 4571
	 *
	 * Description : Remove priority
	 *
	 * @param null
	 *
	 * @return Data 
	 *
	 * @throws null
	 *
	 **/
	
	public function removePrioritiy()
	{
		//return $this->ecatalogueRepositoryManager->resetPriority($this->userId);
		return $this->prioritizeEcatalogueRepository->resetPriority($this->userId);
	}
	
	public function getUserContactBook($userId)
	{
		return $this->ecatalogueOrderRepositoryManager->getUserContactBookData($userId);
	}
	public function getUserSubShop($userId='')
	{
		return $this->ecatalogueRepositoryManager->getUserSubShop($userId);
	}
	
	public function getStatusCountList($userId,$countFlagForStatus ,$searchParameterArray, $page, $recordsPerPage,$option,$keywords,$countryCode,$categoryOption,$status)
	{
		
		$adminUser = false;
		$isAdmin = $this->ecatalogueRepositoryManager->findAdminUser();
		if($isAdmin!="" && sizeof($isAdmin)>0){
			$adminUser = true;
		}
		$this->getCultureValueAjaxSearch();
		if ($this->countryCode)
			$this->countryId = $this->getCountryIdByCodeBYAjax($this->countryCode);
		$this->ecatalogueData=$this->ecatalogueRepositoryManager->getStatusCountListRepository($userId,$countFlagForStatus,$this->countryId,$option,$keywords,$adminUser,$categoryOption,$page, $recordsPerPage,$status);
		return $this->ecatalogueData;
		
		
	}
}