cmtracker/src/Repository/UserRepository.php

109 lines
3.4 KiB
PHP
Raw Normal View History

2024-11-28 11:37:56 -05:00
<?php
namespace App\Repository;
use App\Entity\Company;
2024-11-28 11:37:56 -05:00
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
/**
* @extends ServiceEntityRepository<User>
*/
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* Used to upgrade (rehash) the user's password automatically over time.
*/
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class));
}
$user->setPassword($newHashedPassword);
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
}
public function getCaseManagers(Company $company): array
{
return $this->createQueryBuilder('u')
2024-12-03 00:00:34 -05:00
->andWhere('u.caseManager = :case_manager')
->andWhere('u.company = :company')
2024-12-03 00:00:34 -05:00
->setParameter('case_manager', true)
->setParameter('company', $company->getId()->toBinary())
->getQuery()
->getResult()
;
}
public function getTherapists(Company $company): array
{
return $this->createQueryBuilder('u')
2024-12-03 00:00:34 -05:00
->andWhere('u.therapist = :therapist')
->andWhere('u.company = :company')
2024-12-03 00:00:34 -05:00
->setParameter('therapist', true)
->setParameter('company', $company->getId()->toBinary())
->getQuery()
->getResult()
;
}
public function getAdmins(Company $company): array
2024-11-29 21:47:37 -05:00
{
return $this->createQueryBuilder('u')
2024-12-03 00:00:34 -05:00
->andWhere('u.su = :su')
->andWhere('u.company = :company')
2024-12-03 00:00:34 -05:00
->setParameter('su', true)
->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')
2024-11-29 21:47:37 -05:00
->getQuery()
->getResult()
;
}
2024-11-28 11:37:56 -05:00
// /**
// * @return User[] Returns an array of User objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('u.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?User
// {
// return $this->createQueryBuilder('u')
// ->andWhere('u.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}