mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
delegate person matching detection to service SimilarPersonMatcher
This commit is contained in:
@@ -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');
|
||||
|
Reference in New Issue
Block a user