mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 10:05:03 +00:00
Add functionality to find a caller by phone number
Added a new method in PersonRepository to allow querying people by phone number. Also, a new REST API endpoint "/public/api/1.0/ticket/find-caller" was introduced and it can find a caller by their phone number. Accompanied this feature addition with corresponding test cases.
This commit is contained in:
@@ -12,10 +12,12 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Repository;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonPhone;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ObjectRepository;
|
||||
use libphonenumber\PhoneNumber;
|
||||
|
||||
class PersonRepository implements ObjectRepository
|
||||
{
|
||||
@@ -29,6 +31,8 @@ class PersonRepository implements ObjectRepository
|
||||
/**
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function countByPhone(
|
||||
string $phonenumber,
|
||||
@@ -71,6 +75,8 @@ class PersonRepository implements ObjectRepository
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*
|
||||
* @deprecated Use @see{self::findByPhoneNumber} or use a dedicated method in PersonACLAwareRepository
|
||||
*/
|
||||
public function findByPhone(
|
||||
string $phonenumber,
|
||||
@@ -91,6 +97,25 @@ class PersonRepository implements ObjectRepository
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a person which is associated to the given phonenumber, without restrictions
|
||||
* on any.
|
||||
*
|
||||
* @return list<Person
|
||||
*/
|
||||
public function findByPhoneNumber(PhoneNumber $phoneNumber, int $firstResult = 0, int $maxResults = 50): array
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('p');
|
||||
$qb->select('p');
|
||||
|
||||
$this->searchByPhoneNumbers($qb, $phoneNumber);
|
||||
|
||||
$qb->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults);
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
@@ -109,6 +134,20 @@ class PersonRepository implements ObjectRepository
|
||||
}
|
||||
}
|
||||
|
||||
private function searchByPhoneNumbers(QueryBuilder $qb, PhoneNumber $phoneNumber): void
|
||||
{
|
||||
$qb->setParameter('number', $phoneNumber, 'phone_number');
|
||||
|
||||
$orX = $qb->expr()->orX();
|
||||
$orX->add($qb->expr()->eq('p.mobilenumber', ':number'));
|
||||
$orX->add($qb->expr()->eq('p.phonenumber', ':number'));
|
||||
$orX->add(
|
||||
$qb->expr()->exists('SELECT 1 FROM '.PersonPhone::class.' k WHERE k.phonenumber = :number AND k.person = p')
|
||||
);
|
||||
|
||||
$qb->andWhere($orX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
Reference in New Issue
Block a user