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\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');

View File

@ -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,

View File

@ -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)';

View File

@ -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