mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix double person creation + button for creating accompanying course on creation + simplification person create
The controller now register data from a previous post on the form, and register it in the session. The next post compare the data with previous one and, if yes, show a review page if there are "alternate persons.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
namespace Chill\PersonBundle\Search;
|
||||
|
||||
use Chill\PersonBundle\Entity\PersonNotDuplicate;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
@@ -53,35 +54,54 @@ class SimilarPersonMatcher
|
||||
*/
|
||||
protected $tokenStorage;
|
||||
|
||||
protected PersonNotDuplicateRepository $personNotDuplicateRepository;
|
||||
|
||||
protected PersonRender $personRender;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage
|
||||
TokenStorageInterface $tokenStorage,
|
||||
PersonNotDuplicateRepository $personNotDuplicateRepository,
|
||||
PersonRender $personRender
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->personNotDuplicateRepository = $personNotDuplicateRepository;
|
||||
$this->personRender = $personRender;
|
||||
}
|
||||
|
||||
public function matchPerson(Person $person, PersonNotDuplicateRepository $personNotDuplicateRepository, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY)
|
||||
{
|
||||
public function matchPerson(
|
||||
Person $person,
|
||||
float $precision = 0.15,
|
||||
string $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY,
|
||||
bool $addYearComparison = false
|
||||
) {
|
||||
$centers = $this->authorizationHelper->getReachableCenters(
|
||||
$this->tokenStorage->getToken()->getUser(),
|
||||
new Role(PersonVoter::SEE)
|
||||
);
|
||||
$query = $this->em->createQuery();
|
||||
|
||||
$dql = 'SELECT p from ChillPersonBundle:Person p '
|
||||
. ' WHERE ('
|
||||
. ' SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) >= :precision '
|
||||
. ' ) '
|
||||
. ' AND p.center IN (:centers)'
|
||||
. ' AND p.id != :personId '
|
||||
|
||||
;
|
||||
|
||||
$notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
if ($person->getId() !== NULL) {
|
||||
$dql .= ' AND p.id != :personId ';
|
||||
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
$dql .= ' AND p.id not in (:notDuplicatePersons)';
|
||||
$query->setParameter('personId', $person->getId());
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
$dql .= ' AND p.id not in (:notDuplicatePersons)';
|
||||
$query->setParameter('notDuplicatePersons', $notDuplicatePersons);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($orderBy) {
|
||||
@@ -93,18 +113,13 @@ class SimilarPersonMatcher
|
||||
$dql .= ' ORDER BY SIMILARITY(p.fullnameCanonical, UNACCENT(LOWER(:fullName))) DESC ';
|
||||
}
|
||||
|
||||
$query = $this->em
|
||||
->createQuery($dql)
|
||||
->setParameter('fullName', $person->getFirstName() . ' ' . $person->getLastName())
|
||||
$query = $query
|
||||
->setDQL($dql)
|
||||
->setParameter('fullName', $this->personRender->renderString($person, []))
|
||||
->setParameter('centers', $centers)
|
||||
->setParameter('personId', $person->getId())
|
||||
->setParameter('precision', $precision)
|
||||
;
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
$query->setParameter('notDuplicatePersons', $notDuplicatePersons);
|
||||
}
|
||||
|
||||
return $query->getResult();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user