mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
php code style fix for SimilarPersonMatcher replacement
This commit is contained in:
parent
bc08719c0c
commit
d7f5de6570
@ -71,13 +71,13 @@ final class PersonController extends AbstractController
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
private PersonACLAwareRepositoryInterface $personACLAwareRepository;
|
||||
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
private PersonACLAwareRepositoryInterface $personACLAwareRepository;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
|
@ -39,6 +39,11 @@ class PersonDuplicateController extends Controller
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var PersonACLAwareRepositoryInterface
|
||||
*/
|
||||
private $personACLAwareRepository;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Actions\Remove\PersonMove
|
||||
*/
|
||||
@ -49,11 +54,6 @@ class PersonDuplicateController extends Controller
|
||||
*/
|
||||
private $personRepository;
|
||||
|
||||
/**
|
||||
* @var PersonACLAwareRepositoryInterface
|
||||
*/
|
||||
private $personACLAwareRepository;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Translation\TranslatorInterface
|
||||
*/
|
||||
@ -246,7 +246,6 @@ class PersonDuplicateController extends Controller
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
|
||||
$duplicatePersons = $this->personACLAwareRepository->findMatchingPersons(
|
||||
$person,
|
||||
0.5,
|
||||
|
@ -14,13 +14,11 @@ namespace Chill\PersonBundle\Repository;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Repository\CountryRepository;
|
||||
use Chill\MainBundle\Search\ParsingException;
|
||||
use Chill\MainBundle\Search\SearchApi;
|
||||
use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
@ -43,11 +41,11 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private Security $security;
|
||||
private PersonNotDuplicateRepository $personNotDuplicateRepository;
|
||||
|
||||
private PersonRender $personRender;
|
||||
|
||||
private PersonNotDuplicateRepository $personNotDuplicateRepository;
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
Security $security,
|
||||
@ -308,6 +306,70 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
|
||||
return $this->fetchQueryPerson($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
* @throws ParsingException
|
||||
*
|
||||
* @return array|Person[]
|
||||
*/
|
||||
public function findMatchingPersons(
|
||||
Person $person,
|
||||
float $precision = 0.15,
|
||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY
|
||||
): array {
|
||||
$query = $this->matchPerson($person, $precision, $orderBy);
|
||||
$authorizedQuery = $this->addAuthorizations($query);
|
||||
|
||||
return $this->fetchQueryPerson($authorizedQuery);
|
||||
}
|
||||
|
||||
public function matchPerson(
|
||||
Person $person,
|
||||
float $precision = 0.15,
|
||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY
|
||||
): SearchApiQuery {
|
||||
$fullName = $this->personRender->renderString($person, []);
|
||||
|
||||
$query = new SearchApiQuery();
|
||||
$query->setFromClause('chill_person_person AS person');
|
||||
$query->andWhereClause(
|
||||
'SIMILARITY(person.fullnameCanonical, UNACCENT(LOWER(?))) >= ?',
|
||||
[$fullName, $precision]
|
||||
);
|
||||
|
||||
if (null !== $person->getId()) {
|
||||
$query->andWhereClause(
|
||||
'person.id != ?',
|
||||
[$person->getId()]
|
||||
);
|
||||
|
||||
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
$query->andWhereClause(
|
||||
'person.id NOT IN (?)',
|
||||
[$notDuplicatePersons]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($orderBy) {
|
||||
case self::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL:
|
||||
$query->setSelectPertinence('person.fullnameCanonical');
|
||||
|
||||
break;
|
||||
|
||||
case self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY:
|
||||
default:
|
||||
$query->setSelectPertinence(
|
||||
'SIMILARITY(person.fullnameCanonical, UNACCENT(LOWER(?)))',
|
||||
[$fullName]
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function addAuthorizations(SearchApiQuery $query): SearchApiQuery
|
||||
{
|
||||
$authorizedCenters = $this->authorizationHelper
|
||||
@ -333,70 +395,4 @@ final class PersonACLAwareRepository implements PersonACLAwareRepositoryInterfac
|
||||
}, $authorizedCenters)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
* @throws ParsingException
|
||||
*
|
||||
* @return array|Person[]
|
||||
*/
|
||||
public function findMatchingPersons(
|
||||
Person $person,
|
||||
float $precision = 0.15,
|
||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY
|
||||
): array {
|
||||
$query = $this->matchPerson($person, $precision, $orderBy);
|
||||
$authorizedQuery = $this->addAuthorizations($query);
|
||||
|
||||
return $this->fetchQueryPerson($authorizedQuery);
|
||||
}
|
||||
|
||||
public function matchPerson(
|
||||
Person $person,
|
||||
float $precision = 0.15,
|
||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY
|
||||
): SearchApiQuery {
|
||||
|
||||
$fullName = $this->personRender->renderString($person, []);
|
||||
|
||||
$query = new SearchApiQuery();
|
||||
$query->setFromClause('chill_person_person AS person');
|
||||
$query->andWhereClause(
|
||||
"SIMILARITY(person.fullnameCanonical, UNACCENT(LOWER(?))) >= ?",
|
||||
[$fullName, $precision]
|
||||
);
|
||||
|
||||
if (null !== $person->getId()) {
|
||||
$query->andWhereClause(
|
||||
"person.id != ?",
|
||||
[$person->getId()]
|
||||
);
|
||||
|
||||
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
$query->andWhereClause(
|
||||
"person.id NOT IN (?)",
|
||||
[$notDuplicatePersons]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($orderBy) {
|
||||
case self::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL:
|
||||
$query->setSelectPertinence('person.fullnameCanonical');
|
||||
break;
|
||||
|
||||
case self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY:
|
||||
default:
|
||||
$query->setSelectPertinence(
|
||||
'SIMILARITY(person.fullnameCanonical, UNACCENT(LOWER(?)))',
|
||||
[$fullName]
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
|
||||
use function count;
|
||||
|
||||
/*
|
||||
* @deprecated
|
||||
*/
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class SimilarPersonMatcher
|
||||
{
|
||||
public const SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL = 'alphabetical';
|
||||
|
Loading…
x
Reference in New Issue
Block a user