delegate person matching detection to service SimilarPersonMatcher

This commit is contained in:
2018-05-14 17:58:00 +02:00
parent db00a0d265
commit 983ed7a50d
6 changed files with 128 additions and 40 deletions

View File

@@ -30,9 +30,21 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\PersonBundle\Search\SimilarPersonMatcher;
class PersonController extends Controller
{
/**
*
* @var SimilarPersonMatcher
*/
protected $similarPersonMatcher;
public function __construct(SimilarPersonMatcher $similarPersonMatcher)
{
$this->similarPersonMatcher = $similarPersonMatcher;
}
public function getCFGroup()
{
$cFGroup = null;
@@ -266,35 +278,8 @@ class PersonController extends Controller
$this->get('logger')->info('Person created without errors');
}
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery();
$dql = 'SELECT p from ChillPersonBundle:Person p WHERE '
. 'LOWER(p.firstName) LIKE LOWER(:firstName)'
. ' OR LOWER(p.lastName) LIKE LOWER(:lastName)'
. ' OR LOWER(p.firstName) LIKE LOWER(:lastName)'
. ' OR LOWER(p.lastName) LIKE LOWER(:firstName)';
$query->setParameter('firstName', $form['firstName']->getData())
->setParameter('lastName', $form['lastName']->getData());
if ($this->container
->getParameter('cl_chill_person.search.use_double_metaphone')) {
$dql .= ' OR DOUBLEMETAPHONE(p.lastName) LIKE DOUBLEMETAPHONE(:lastName) ';
}
// add authorized centers
$centers = $this->get('chill.main.security.authorization.helper')
->getReachableCenters($this->getUser(), new Role(PersonVoter::SEE));
$dql.=' and p.center IN (:centers) ';
$query->setParameter('centers', $centers);
// run query
$query->setDql($dql);
$alternatePersons = $query->getResult();
$alternatePersons = $this->similarPersonMatcher
->matchPerson($person);
if (count($alternatePersons) === 0) {
return $this->forward('ChillPersonBundle:Person:create');