<?php
namespace Products\NotificationsBundle\Doctrine\Repository;
use Doctrine\ORM\EntityRepository;
use Products\NotificationsBundle\Entity\Profile;
use Products\NotificationsBundle\Entity\ProfileContact;
/**
* Class ProfileContactRepository
* @package Products\NotificationsBundle\Doctrine\Repository
*
* @method ProfileContact find($id, $lockMode = null, $lockVersion = null)
* @method ProfileContact findOneBy(array $criteria, array $orderBy = null)
* @method array|ProfileContact[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
final class ProfileContactRepository extends EntityRepository
{
/**
* @param Profile $profile
* @param bool $active
* @return array|ProfileContact[]
*/
public function findByProfile(Profile $profile, bool $active = true): array
{
return $this->createQueryBuilder('contacts')
->leftJoin('contacts.recipient', 'recipient')
->addSelect('recipient')
->andWhere('recipient.active = :active')
->setParameter('active', $active)
->andWhere('contacts.profile = :profile')
->setParameter('profile', $profile)
->addOrderBy('TYPE(recipient)', 'ASC')
->addOrderBy('recipient.contact', 'ASC')
->getQuery()
->getResult();
}
}