mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 01:53:49 +00:00
Créer un point d'api de suggestion des usagers pour un ticket
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user