<?php

namespace OfficeBrain\Bundle\QuoteBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * QuoteUserContactMappingRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class QuoteUserContactMappingRepository extends EntityRepository
{
	protected $projectSetting;
	protected $instanceId;
	protected $instanceType;
	protected $cultureId;
	protected $cultureCode;
	protected $projectSettingService;
	protected $projectUserSetting;
	

	public function getProjectSetting()
	{
		return $this->paginatorService;
	}
	
	/**
	 * @author Employee Id: 4493
	 * OB eCommerce Product - setProjectSetting
	 * Function created to set Project Setting
	 */
	public function setProjectSetting($projectSetting)
	{
		$this->projectSetting = $projectSetting;
		$this->prepareProjectSettingData();
	}
	
	public function setProjectUserSetting($projectUserSetting)
	{
		$this->projectUserSetting = $projectUserSetting;
		$this->prepareProjectUserSettingData();
	}
	
	public function getProjectUserSetting()
	{
		return $this->projectUserSetting;
	}
	
	public function prepareProjectSettingData()
	{
		$this->userId = $this->projectSetting['user_id'];
		$this->createdUid = $this->upatedUid = $this->userId;
		$this->instanceId = $this->projectSetting['instance_id'];
		$this->instanceType = $this->projectSetting['instance_type'];
		$this->cultureId = $this->projectSetting['culture_id'];
		$this->cultureCode = $this->projectSetting['culture_code'];
	}
	public function prepareProjectUserSettingData()
	{
		$this->user = $this->projectUserSetting['user_data'];
	}
	
	

	/**
	 * @author Employee Id: 4493
	 * OB eCommerce Product - Quote User Contact Mapping
	 * Function created for Quote User Contact Mapping
	 */
	
	public function addQuoteUserContact($addQuoteUserContact)
	{			
		$this->getEntityManager()->persist($addQuoteUserContact);
		$this->getEntityManager()->flush();	
		return $addQuoteUserContact;
		
	}
	

	/**
	 * @author Employee Id: 4493
	 * OB eCommerce Product - Quote User Contact Info Exist Check
	 * Function created for Quote User Contact Info
	 */
	
	public function isExistQuoteUserContact($quoteId,$contactId)
	{
		$query=$this->createQueryBuilder('qu');
		$query->select('count(qu.id)');
		$query->where("qu.quoteMasterId =:quoteId")->setParameter('quoteId',$quoteId);
		$query->andWhere("qu.contactbookId =:contactId")->setParameter('contactId',$contactId);
		return $query->getQuery()->getSingleScalarResult();
	
	}
	

	/**
	 * @author Employee Id: 4493
	 * OB eCommerce Product - Quote User Contact Info
	 * Function created for Quote User Contact Info
	 */
	
	public function getQuoteUserContact($quoteId,$contactFlag='')
	{
		$query=$this->createQueryBuilder('qu');
		$query->where("qu.quoteMasterId =:quoteId")->setParameter('quoteId',$quoteId);
		if($contactFlag ==''){
			$query->andWhere("qu.contactbookId ==0");
		}
		return $query->getQuery()->getResult();
	
	}
	
	public function isExistQuoteUserContactId($contactId)
	{
		$query=$this->createQueryBuilder('qu');
		$query->where("qu.id =:contact_id")->setParameter('contact_id',$contactId);
		return $query->getQuery()->getOneOrNullResult();
	}
	

	public function getQuoteUserContactByQuoteMaster($quoteId)
	{
		$query=$this->createQueryBuilder('qu');
		$query->where("qu.quoteMasterId =:quoteId")->setParameter('quoteId',$quoteId);
		return $query->getQuery()->getOneOrNullResult();
	
	}
	
	public function deleteQuoteUserContactAdmin($contactObj){
		$this->_em->remove($contactObj);
		$this->_em->flush();
		return 'SUCCESS';
		
		
	}
	
	public function editQuoteUserContact($quoteUserObj,$userPhoto)
	{
		$quoteUserObj->setPhoto($userPhoto);
		$this->getEntityManager()->persist($quoteUserObj);
		$this->getEntityManager()->flush();
		return $quoteUserObj;
	
	}
	
	/**
	 * @author Employee Id: 4493
	 * OB eCommerce Product - Quote User Contact Mapping
	 * Function created for Quote User Contact Mapping
	 */
	
	public function addQuoteDistributorContact($addQuoteUserContact)
	{
		$this->getEntityManager()->persist($addQuoteUserContact);
		$this->getEntityManager()->flush();
		return $addQuoteUserContact;
	
	}
	
}
