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:
2021-08-23 17:42:08 +02:00
parent c798b1290c
commit 8fb4a7110e
8 changed files with 217 additions and 338 deletions

View File

@@ -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();
}
}