<?php

namespace OfficeBrain\Bundle\EmailBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 *
 * @author OfficeBrain 4795 <info@officebrain.com>
 *
 * EmailTemplateLanguageRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class EmailTemplateLanguageRepository extends EntityRepository
{
    protected $projectSetting;
    protected $instanceId;
    protected $instanceType;
    protected $cultureId;
    protected $cultureCode;
    
    public function setProjectSetting($projetSetting)
    {
        $this->projectSetting = $projetSetting;
        $this->prepareProjectSettingData();
    }
    
    public function getProjectSetting()
    {
        return $this->projetSetting;
    }
    
    public function prepareProjectSettingData()
    {
        $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'];
    }
    
    /**
     * @author Employee Id: 4795
     *
     * Description : Find template content by language
     */
    public function findTemplateContentByLanguage($templateId, $languageId)
    {
        return $this->createQueryBuilder('eh')
        ->select('eh.templateContent')
        ->where('eh.templateId = :templateId')
        ->andWhere('eh.languageId = :languageId')
        ->setParameter(':templateId', $templateId)
        ->setParameter(':languageId', $languageId)
        ->getQuery()
        ->getOneOrNullResult();
    }
}
