diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index ddc90cd..06c01a0 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -2,6 +2,7 @@ namespace App\Repository; +use App\Entity\Company; use App\Entity\User; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -33,11 +34,48 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader $this->getEntityManager()->flush(); } - public function getCaseManagers(): array + public function getCaseManagers(Company $company): array + { + return $this->createQueryBuilder('u') + ->andWhere('u.job != :job') + ->andWhere('u.company = :company') + ->setParameter('job', 'CASE_WORKER') + ->setParameter('company', $company->getId()->toBinary()) + ->getQuery() + ->getResult() + ; + } + + public function getTherapists(Company $company): array { return $this->createQueryBuilder('u') ->andWhere('u.job = :job') - ->setParameter('job', 'CASE_MANAGER') + ->andWhere('u.company = :company') + ->setParameter('job', 'THERAPIST') + ->setParameter('company', $company->getId()->toBinary()) + ->getQuery() + ->getResult() + ; + } + + public function getAdmins(Company $company): array + { + return $this->createQueryBuilder('u') + ->andWhere('u.job = :job') + ->andWhere('u.company = :company') + ->setParameter('job', 'ADMIN') + ->setParameter('company', $company->getId()->toBinary()) + ->getQuery() + ->getResult() + ; + } + + public function getCompanyUsers(Company $company): array + { + return $this->createQueryBuilder('u') + ->andWhere('u.company = :company') + ->setParameter('company', $company->getId()->toBinary()) + ->orderBy('u.name', 'ASC') ->getQuery() ->getResult() ;