From aebeefcf8099cb73db536f2f9b595e492ae0e4ee Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 12 May 2021 15:33:18 +0200 Subject: [PATCH] Use repositories as services. --- .../ChillPersonBundle/Controller/PersonController.php | 6 +++--- .../Controller/PersonDuplicateController.php | 6 +++--- .../ChillPersonBundle/Search/SimilarPersonMatcher.php | 5 ++--- src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index bfb32654e..abba491b1 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -38,6 +38,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\MainBundle\Search\SearchProvider; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Symfony\Component\Validator\Validator\ValidatorInterface; use Doctrine\ORM\EntityManagerInterface; @@ -290,7 +291,7 @@ final class PersonController extends AbstractController return $errors; } - public function reviewAction(Request $request) + public function reviewAction(Request $request, PersonNotDuplicateRepository $personNotDuplicateRepository) { if ($request->getMethod() !== 'POST') { $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); - $alternatePersons = $this->similarPersonMatcher - ->matchPerson($person); + $alternatePersons = $this->similarPersonMatcher->matchPerson($person, $personNotDuplicateRepository); if (count($alternatePersons) === 0) { return $this->forward('ChillPersonBundle:Person:create'); diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index aa2e2768a..48654134d 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -19,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\ActivityBundle\Entity\Activity; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\EventBundle\Entity\Participation; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Chill\TaskBundle\Entity\SingleTask; class PersonDuplicateController extends Controller @@ -62,7 +63,7 @@ class PersonDuplicateController extends Controller $this->eventDispatcher = $eventDispatcher; } - public function viewAction($person_id) + public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository) { $person = $this->_getPerson($person_id); if ($person === null) { @@ -76,8 +77,7 @@ class PersonDuplicateController extends Controller $duplicatePersons = $this->similarPersonMatcher-> matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); - $notDuplicatePersons = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [ 'person' => $person, diff --git a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php index 956f9a4d2..c220e62e8 100644 --- a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php +++ b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php @@ -62,7 +62,7 @@ class SimilarPersonMatcher $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( $this->tokenStorage->getToken()->getUser(), @@ -77,8 +77,7 @@ class SimilarPersonMatcher . ' AND p.id != :personId ' ; - $notDuplicatePersons = $this->em->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); if (count($notDuplicatePersons)) { $dql .= ' AND p.id not in (:notDuplicatePersons)'; diff --git a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php index e885e0a26..2dcbb8230 100644 --- a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php +++ b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php @@ -45,7 +45,7 @@ class PersonListWidget implements WidgetInterface /** * Repository for persons * - * @var EntityRepository + * @var PersonRepository */ protected $personRepository; @@ -76,7 +76,7 @@ class PersonListWidget implements WidgetInterface protected $user; public function __construct( - EntityRepository $personRepostory, + PersonRepository $personRepostory, EntityManager $em, AuthorizationHelper $authorizationHelper, TokenStorage $tokenStorage