<?php

namespace OfficeBrain\Bundle\CmsBundle\Entity;

/**
 * ContactUsRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ContactUsRepository extends \Doctrine\ORM\EntityRepository
{
	protected $projectSetting;
	protected $instanceId;
	protected $instanceType;
	protected $cultureId;
	protected $cultureCode;
	protected $userId;
	protected $projectId;
	
	/**
	 * @author Employee Id: 4571
	 *
	 * Description : This function is used to set project settings
	 *
	 * @param 1: $projectSetting
	 *
	 * @return: NULL
	 *
	 * @throws Exception: Null
	 */
	public function setProjectSetting($projetSetting)
	{
		$this->projectSetting = $projetSetting;
		$this->prepareProjectSettingData();
	}
	
	/**
	 * @author Employee Id: 4571
	 *
	 * Description : This function is used to get project settings
	 *
	 * @param : None
	 *
	 * @return: project setting array
	 *
	 * @throws Exception: Null
	 */
	public function getProjectSetting()
	{
		return $this->projetSetting;
	}
	
	/**
	 * @author Employee Id: 4571
	 *
	 * Description : This function is used to set member variables default value
	 *
	 * @param : None
	 *
	 * @return: NULL
	 *
	 * @throws Exception: Null
	 */
	public function prepareProjectSettingData()
	{
		$this->projectId = $this->projectSetting['project_id'];
		$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'];
		$this->userId = $this->projectSetting['user_id'];
	}
	
	/**
	 * @author Employee Id: 4571
	 *
	 * Description : This function is used to save contact us page details in db
	 *
	 * @param : None
	 *
	 * @return: NULL
	 *
	 * @throws Exception: Null
	 */
	public function addContacts($contactsObj)
	{		
		$contactsObj->setCreatedUid($this->userId);
        $contactsObj->setInstanceId($this->instanceId);
        $contactsObj->setInstanceType($this->instanceType);
        $contactsObj->setCreatedAt(new \DateTime());
       	$this->_em->persist($contactsObj);
        $this->_em->flush();
		
		return $contactsObj;
	}
}
