mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
List duplicate persons
Signed-off-by: Mathieu Jaumotte <mathieu.jaumotte@champs-libres.coop> Signed-off-by: Mathieu Jaumotte <mathieu.jaumotte@champs-libres.coop>
This commit is contained in:
@@ -61,35 +61,32 @@ class SimilarPersonMatcher
|
||||
}
|
||||
|
||||
|
||||
public function matchPerson(Person $person)
|
||||
public function matchPerson(Person $person, $precision = 0.15)
|
||||
{
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->tokenStorage->getToken()->getUser(),
|
||||
new Role(PersonVoter::SEE)
|
||||
);
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->tokenStorage->getToken()->getUser(),
|
||||
new Role(PersonVoter::SEE)
|
||||
);
|
||||
|
||||
$dql = 'SELECT p from ChillPersonBundle:Person p WHERE'
|
||||
. ' ('
|
||||
. ' UNACCENT(LOWER(p.firstName)) LIKE UNACCENT(LOWER(:firstName)) '
|
||||
. ' OR UNACCENT(LOWER(p.lastName)) LIKE UNACCENT(LOWER(:lastName)) '
|
||||
. ' OR UNACCENT(LOWER(p.firstName)) LIKE UNACCENT(LOWER(:lastName)) '
|
||||
. ' OR UNACCENT(LOWER(p.lastName)) LIKE UNACCENT(LOWER(:firstName)) '
|
||||
. ' OR SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= 0.15 '
|
||||
$dql = 'SELECT p from ChillPersonBundle:Person p '
|
||||
. ' WHERE ('
|
||||
. ' SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision '
|
||||
. ' OR SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullNameInverted))) >= :precision '
|
||||
. ' ) '
|
||||
. ' AND p.center IN (:centers)'
|
||||
. ' AND p.id != :personId'
|
||||
. ' ORDER BY SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) DESC '
|
||||
;
|
||||
;
|
||||
|
||||
$query =
|
||||
$this->em
|
||||
$query = $this->em
|
||||
->createQuery($dql)
|
||||
->setParameter('firstName', $person->getFirstName())
|
||||
->setParameter('lastName', $person->getLastName())
|
||||
->setParameter('fullName', $person->getFirstName() . ' ' . $person->getLastName())
|
||||
->setParameter('fullNameInverted', $person->getLastName() . ' ' . $person->getFirstName())
|
||||
->setParameter('centers', $centers)
|
||||
;
|
||||
|
||||
->setParameter('personId', $person->getId())
|
||||
->setParameter('precision', $precision)
|
||||
;
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user