Use repositories as services.

This commit is contained in:
Pol Dellaiera 2021-05-12 15:33:18 +02:00
parent 3fc6c0c479
commit aebeefcf80
4 changed files with 10 additions and 11 deletions

View File

@ -38,6 +38,7 @@ use Symfony\Component\Translation\TranslatorInterface;
use Chill\MainBundle\Search\SearchProvider; use Chill\MainBundle\Search\SearchProvider;
use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\Validator\ValidatorInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -290,7 +291,7 @@ final class PersonController extends AbstractController
return $errors; return $errors;
} }
public function reviewAction(Request $request) public function reviewAction(Request $request, PersonNotDuplicateRepository $personNotDuplicateRepository)
{ {
if ($request->getMethod() !== 'POST') { if ($request->getMethod() !== 'POST') {
$r = new Response("You must send something to review the creation of a new Person"); $r = new Response("You must send something to review the creation of a new Person");
@ -342,8 +343,7 @@ final class PersonController extends AbstractController
$this->em->persist($person); $this->em->persist($person);
$alternatePersons = $this->similarPersonMatcher $alternatePersons = $this->similarPersonMatcher->matchPerson($person, $personNotDuplicateRepository);
->matchPerson($person);
if (count($alternatePersons) === 0) { if (count($alternatePersons) === 0) {
return $this->forward('ChillPersonBundle:Person:create'); return $this->forward('ChillPersonBundle:Person:create');

View File

@ -19,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface;
use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\Activity;
use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\EventBundle\Entity\Participation; use Chill\EventBundle\Entity\Participation;
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
use Chill\TaskBundle\Entity\SingleTask; use Chill\TaskBundle\Entity\SingleTask;
class PersonDuplicateController extends Controller class PersonDuplicateController extends Controller
@ -62,7 +63,7 @@ class PersonDuplicateController extends Controller
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
} }
public function viewAction($person_id) public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository)
{ {
$person = $this->_getPerson($person_id); $person = $this->_getPerson($person_id);
if ($person === null) { if ($person === null) {
@ -76,8 +77,7 @@ class PersonDuplicateController extends Controller
$duplicatePersons = $this->similarPersonMatcher-> $duplicatePersons = $this->similarPersonMatcher->
matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL);
$notDuplicatePersons = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person);
->findNotDuplicatePerson($person);
return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [ return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [
'person' => $person, 'person' => $person,

View File

@ -62,7 +62,7 @@ class SimilarPersonMatcher
$this->tokenStorage = $tokenStorage; $this->tokenStorage = $tokenStorage;
} }
public function matchPerson(Person $person, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY) public function matchPerson(Person $person, PersonNotDuplicateRepository $personNotDuplicateRepository, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY)
{ {
$centers = $this->authorizationHelper->getReachableCenters( $centers = $this->authorizationHelper->getReachableCenters(
$this->tokenStorage->getToken()->getUser(), $this->tokenStorage->getToken()->getUser(),
@ -77,8 +77,7 @@ class SimilarPersonMatcher
. ' AND p.id != :personId ' . ' AND p.id != :personId '
; ;
$notDuplicatePersons = $this->em->getRepository(PersonNotDuplicate::class) $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person);
->findNotDuplicatePerson($person);
if (count($notDuplicatePersons)) { if (count($notDuplicatePersons)) {
$dql .= ' AND p.id not in (:notDuplicatePersons)'; $dql .= ' AND p.id not in (:notDuplicatePersons)';

View File

@ -45,7 +45,7 @@ class PersonListWidget implements WidgetInterface
/** /**
* Repository for persons * Repository for persons
* *
* @var EntityRepository * @var PersonRepository
*/ */
protected $personRepository; protected $personRepository;
@ -76,7 +76,7 @@ class PersonListWidget implements WidgetInterface
protected $user; protected $user;
public function __construct( public function __construct(
EntityRepository $personRepostory, PersonRepository $personRepostory,
EntityManager $em, EntityManager $em,
AuthorizationHelper $authorizationHelper, AuthorizationHelper $authorizationHelper,
TokenStorage $tokenStorage TokenStorage $tokenStorage