<?php

namespace AppBundle\Entity\Message\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * Description of TemplateSystemRepository
 *
 * @author sebastienhupin
 */
class TemplateSystemRepository extends EntityRepository {

    /**
     * @param string $templateName
     * @param int $organizationId
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findByTemplateName(string $templateName, int $organizationId) {
        $queryBuilder = $this->createQueryBuilder('o');
        $queryBuilder
            ->innerJoin('o.organization', 'organization')
            ->andWhere('o.template = :template')
            ->andWhere('organization.id = :orgnizationId')
            ->setParameter('template', $templateName)
            ->setParameter('orgnizationId', $organizationId)
        ;
        return $queryBuilder->getQuery()->getOneOrNullResult();
    }
}
