adjust countperson to make it work again

This commit is contained in:
Julie Lenaerts 2022-08-02 13:44:28 +02:00
parent ea12c60154
commit c72dc83c06
3 changed files with 19 additions and 19 deletions

View File

@ -15,8 +15,8 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException; use LogicException;
@ -25,19 +25,18 @@ use Symfony\Component\Security\Core\Role\Role;
class CountPerson implements ExportInterface, GroupedExportInterface class CountPerson implements ExportInterface, GroupedExportInterface
{ {
/**
* @var EntityManagerInterface protected PersonRepository $personRepository;
*/
protected $entityManager;
public function __construct( public function __construct(
EntityManagerInterface $em PersonRepository $personRepository
) { ) {
$this->entityManager = $em; $this->personRepository = $personRepository;
} }
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
// No form necessary
} }
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
@ -47,7 +46,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
public function getDescription() public function getDescription()
{ {
return 'Count peoples by various parameters.'; return 'Count people by various parameters.';
} }
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
@ -76,7 +75,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
public function getTitle() public function getTitle()
{ {
return 'Count peoples'; return 'Count people';
} }
public function getType() public function getType()
@ -95,10 +94,9 @@ class CountPerson implements ExportInterface, GroupedExportInterface
return $el['center']; return $el['center'];
}, $acl); }, $acl);
$qb = $this->entityManager->createQueryBuilder(); $qb = $this->personRepository->createQueryBuilder('person');
$qb->select('COUNT(person.id) AS export_result') $qb->select('COUNT(person.id) AS export_result')
->from('ChillPersonBundle:Person', 'person')
->join('person.center', 'center') ->join('person.center', 'center')
->andWhere('center IN (:authorized_centers)') ->andWhere('center IN (:authorized_centers)')
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
@ -113,7 +111,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
public function supportsModifiers() 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 public function getGroup(): string

View File

@ -31,6 +31,11 @@ final class PersonRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Person::class); $this->repository = $entityManager->getRepository(Person::class);
} }
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
/** /**
* @param $centers * @param $centers
* *

View File

@ -2,18 +2,15 @@ services:
chill.person.export.count_person: chill.person.export.count_person:
class: Chill\PersonBundle\Export\Export\CountPerson class: Chill\PersonBundle\Export\Export\CountPerson
arguments: autowire: true
- "@doctrine.orm.entity_manager" autoconfigure: true
tags: tags:
- { name: chill.export, alias: count_person } - { name: chill.export, alias: count_person }
chill.person.export.list_person: chill.person.export.list_person:
class: Chill\PersonBundle\Export\Export\ListPerson class: Chill\PersonBundle\Export\Export\ListPerson
arguments: autowire: true
- "@doctrine.orm.entity_manager" autoconfigure: true
- "@translator"
- "@chill.main.helper.translatable_string"
- "@chill.custom_field.provider"
tags: tags:
- { name: chill.export, alias: list_person } - { name: chill.export, alias: list_person }