Créer un point d'api de suggestion des usagers pour un ticket

This commit is contained in:
2025-07-01 12:38:02 +00:00
parent 0566ab0910
commit 4f93150874
27 changed files with 1485 additions and 26 deletions

View File

@@ -18,12 +18,15 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;
class ThirdPartyRepository implements ObjectRepository
{
private readonly EntityRepository $repository;
public function __construct(EntityManagerInterface $em, private readonly Connection $connection)
public function __construct(EntityManagerInterface $em, private readonly Connection $connection, private readonly PhoneNumberUtil $phonenumberUtil)
{
$this->repository = $em->getRepository(ThirdParty::class);
}
@@ -122,6 +125,43 @@ class ThirdPartyRepository implements ObjectRepository
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
/**
* Finds third-party records by phone number.
*
* The search is performed agains every phonenumber field (there are two phonenumber on a thirdParty).
*
* @param string|PhoneNumber $phonenumber The phone number to search for. Can be a string or a PhoneNumber object.
* @param int $firstResult the index of the first result to retrieve (pagination start)
* @param int $maxResults the maximum number of results to retrieve (pagination limit)
*
* @return list<ThirdParty> the result set containing matching third-party records
*/
public function findByPhonenumber(string|PhoneNumber $phonenumber, int $firstResult = 0, int $maxResults = 20): array
{
if ('' === $phonenumber) {
return [];
}
$qb = $this->createQueryBuilder('tp');
$qb->select('tp');
$qb->where(
$qb->expr()->orX(
$qb->expr()->eq('t.telephone', ':phonenumber'),
$qb->expr()->eq('t.telephone2', ':phonenumber')
)
);
$qb->setParameter(
'phonenumber',
is_string($phonenumber) ? $phonenumber : $this->phonenumberUtil->format($phonenumber, PhoneNumberFormat::E164)
);
$qb->setFirstResult($firstResult)->setMaxResults($maxResults);
return $qb->getQuery()->getResult();
}
/**
* Search amongst parties associated to $centers, with $terms parameters.
*