mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Remove obsolete documentation, fix typing here and there.
This commit is contained in:
@@ -32,105 +32,88 @@ final class PersonRepository
|
||||
$this->repository = $entityManager->getRepository(Person::class);
|
||||
}
|
||||
|
||||
public function find($id, $lockMode = null, $lockVersion = null)
|
||||
public function find($id, $lockMode = null, $lockVersion = null): ?Person
|
||||
{
|
||||
return $this->repository->find($id, $lockMode, $lockVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phonenumber
|
||||
* @param $centers
|
||||
* @param $firstResult
|
||||
* @param $maxResults
|
||||
* @param array $only
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function findByPhone(
|
||||
string $phonenumber,
|
||||
$centers,
|
||||
string $phonenumber,
|
||||
$centers,
|
||||
$firstResult,
|
||||
$maxResults,
|
||||
array $only = ['mobile', 'phone']
|
||||
) {
|
||||
$qb = $this->repository->createQueryBuilder('p');
|
||||
$qb->select('p');
|
||||
|
||||
|
||||
$this->addByCenters($qb, $centers);
|
||||
$this->addPhoneNumber($qb, $phonenumber, $only);
|
||||
|
||||
|
||||
$qb->setFirstResult($firstResult)
|
||||
->setMaxResults($maxResults)
|
||||
;
|
||||
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $phonenumber
|
||||
* @param $centers
|
||||
* @param array $only
|
||||
* @return int
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function countByPhone(
|
||||
string $phonenumber,
|
||||
$centers,
|
||||
string $phonenumber,
|
||||
$centers,
|
||||
array $only = ['mobile', 'phone']
|
||||
): int
|
||||
{
|
||||
): int {
|
||||
$qb = $this->repository->createQueryBuilder('p');
|
||||
$qb->select('COUNT(p)');
|
||||
|
||||
|
||||
$this->addByCenters($qb, $centers);
|
||||
$this->addPhoneNumber($qb, $phonenumber, $only);
|
||||
|
||||
|
||||
return $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param string $phonenumber
|
||||
* @param array $only
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only)
|
||||
protected function addPhoneNumber(QueryBuilder $qb, string $phonenumber, array $only): void
|
||||
{
|
||||
if (count($only) === 0) {
|
||||
throw new \Exception("No array field to search");
|
||||
}
|
||||
|
||||
|
||||
$phonenumber = $this->parsePhoneNumber($phonenumber);
|
||||
|
||||
|
||||
$orX = $qb->expr()->orX();
|
||||
|
||||
|
||||
if (\in_array('mobile', $only)) {
|
||||
$orX->add($qb->expr()->like("REPLACE(p.mobilenumber, ' ', '')", ':phonenumber'));
|
||||
}
|
||||
if (\in_array('phone', $only)) {
|
||||
$orX->add($qb->expr()->like("REPLACE(p.phonenumber, ' ', '')", ':phonenumber'));
|
||||
}
|
||||
|
||||
|
||||
$qb->andWhere($orX);
|
||||
|
||||
|
||||
$qb->setParameter('phonenumber', '%'.$phonenumber.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $phonenumber
|
||||
* @return string
|
||||
*/
|
||||
protected function parsePhoneNumber($phonenumber): string
|
||||
|
||||
protected function parsePhoneNumber(string $phonenumber): string
|
||||
{
|
||||
return \str_replace(' ', '', $phonenumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param array $centers
|
||||
*/
|
||||
protected function addByCenters(QueryBuilder $qb, array $centers)
|
||||
|
||||
protected function addByCenters(QueryBuilder $qb, array $centers): void
|
||||
{
|
||||
if (count($centers) > 0) {
|
||||
$qb->andWhere($qb->expr()->in('p.center', ':centers'));
|
||||
|
Reference in New Issue
Block a user