src/Products/NotificationsBundle/Doctrine/Repository/ProfileContactRepository.php line 24

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Doctrine\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Products\NotificationsBundle\Entity\Profile;
  5. use Products\NotificationsBundle\Entity\ProfileContact;
  6. /**
  7.  * Class ProfileContactRepository
  8.  * @package Products\NotificationsBundle\Doctrine\Repository
  9.  *
  10.  * @method ProfileContact find($id, $lockMode = null, $lockVersion = null)
  11.  * @method ProfileContact findOneBy(array $criteria, array $orderBy = null)
  12.  * @method array|ProfileContact[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. final class ProfileContactRepository extends EntityRepository
  15. {
  16.     /**
  17.      * @param Profile $profile
  18.      * @param bool $active
  19.      * @return array|ProfileContact[]
  20.      */
  21.     public function findByProfile(Profile $profilebool $active true): array
  22.     {
  23.         return $this->createQueryBuilder('contacts')
  24.             ->leftJoin('contacts.recipient''recipient')
  25.             ->addSelect('recipient')
  26.             ->andWhere('recipient.active = :active')
  27.             ->setParameter('active'$active)
  28.             ->andWhere('contacts.profile = :profile')
  29.             ->setParameter('profile'$profile)
  30.             ->addOrderBy('TYPE(recipient)''ASC')
  31.             ->addOrderBy('recipient.contact''ASC')
  32.             ->getQuery()
  33.             ->getResult();
  34.     }
  35. }