diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php index 115b3489e..96f669524 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPerson.php @@ -15,8 +15,8 @@ use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Export\Declarations; +use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Security\Authorization\PersonVoter; -use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use LogicException; @@ -25,19 +25,18 @@ use Symfony\Component\Security\Core\Role\Role; class CountPerson implements ExportInterface, GroupedExportInterface { - /** - * @var EntityManagerInterface - */ - protected $entityManager; + + protected PersonRepository $personRepository; public function __construct( - EntityManagerInterface $em + PersonRepository $personRepository ) { - $this->entityManager = $em; + $this->personRepository = $personRepository; } public function buildForm(FormBuilderInterface $builder) { + // No form necessary } public function getAllowedFormattersTypes() @@ -47,7 +46,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface public function getDescription() { - return 'Count peoples by various parameters.'; + return 'Count people by various parameters.'; } public function getLabels($key, array $values, $data) @@ -76,7 +75,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface public function getTitle() { - return 'Count peoples'; + return 'Count people'; } public function getType() @@ -95,10 +94,9 @@ class CountPerson implements ExportInterface, GroupedExportInterface return $el['center']; }, $acl); - $qb = $this->entityManager->createQueryBuilder(); + $qb = $this->personRepository->createQueryBuilder('person'); $qb->select('COUNT(person.id) AS export_result') - ->from('ChillPersonBundle:Person', 'person') ->join('person.center', 'center') ->andWhere('center IN (:authorized_centers)') ->setParameter('authorized_centers', $centers); @@ -113,7 +111,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface public function supportsModifiers() { - return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN]; + return [Declarations::PERSON_TYPE, Declarations::PERSON_IMPLIED_IN, Declarations::ACP_SHARED]; } public function getGroup(): string diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php b/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php index bd8347852..309e5f086 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php @@ -31,6 +31,11 @@ final class PersonRepository implements ObjectRepository $this->repository = $entityManager->getRepository(Person::class); } + public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder + { + return $this->repository->createQueryBuilder($alias, $indexBy); + } + /** * @param $centers * diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index f50674e19..b00e6106d 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -2,18 +2,15 @@ services: chill.person.export.count_person: class: Chill\PersonBundle\Export\Export\CountPerson - arguments: - - "@doctrine.orm.entity_manager" + autowire: true + autoconfigure: true tags: - { name: chill.export, alias: count_person } chill.person.export.list_person: class: Chill\PersonBundle\Export\Export\ListPerson - arguments: - - "@doctrine.orm.entity_manager" - - "@translator" - - "@chill.main.helper.translatable_string" - - "@chill.custom_field.provider" + autowire: true + autoconfigure: true tags: - { name: chill.export, alias: list_person }