exports: fix initiateQuery to always begin from acp entity

This commit is contained in:
Mathieu Jaumotte 2022-08-11 14:48:03 +02:00
parent b8d187c82b
commit c45ef7d74f
5 changed files with 45 additions and 42 deletions

View File

@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -26,15 +27,12 @@ use LogicException;
class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
{ {
/** protected EntityRepository $repository;
* @var EntityManagerInterface
*/
protected $entityManager;
public function __construct( public function __construct(
EntityManagerInterface $em EntityManagerInterface $em
) { ) {
$this->entityManager = $em; $this->repository = $em->getRepository(AccompanyingPeriod::class);
} }
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
@ -88,12 +86,9 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{ {
$qb = $this->entityManager->createQueryBuilder(); $qb = $this->repository->createQueryBuilder('acp');
$expr = $qb->expr();
$qb->select('COUNT(acp.id) AS export_result') $qb->select('COUNT(acp.id) AS export_result');
->from('ChillPersonBundle:AccompanyingPeriod', 'acp')
;
return $qb; return $qb;
} }
@ -105,7 +100,10 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
public function supportsModifiers(): array public function supportsModifiers(): array
{ {
return [Declarations::ACP_TYPE, Declarations::ACP_SHARED]; return [
Declarations::ACP_TYPE,
Declarations::ACP_SHARED
];
} }
public function getGroup(): string public function getGroup(): string

View File

@ -17,12 +17,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountEvaluation implements ExportInterface, GroupedExportInterface class CountEvaluation implements ExportInterface, GroupedExportInterface
{ {
private EntityRepository $acpRepository; private EntityRepository $repository;
public function __construct( public function __construct(
EntityManagerInterface $em EntityManagerInterface $em
) { ) {
$this->acpRepository = $em->getRepository(AccompanyingPeriod::class); $this->repository = $em->getRepository(AccompanyingPeriod::class);
} }
/** /**
@ -103,7 +103,7 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
*/ */
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{ {
$qb = $this->acpRepository->createQueryBuilder('acp') $qb = $this->repository->createQueryBuilder('acp')
->join('acp.works', 'acpw') ->join('acp.works', 'acpw')
->join('acpw.accompanyingPeriodWorkEvaluations', 'eval') ->join('acpw.accompanyingPeriodWorkEvaluations', 'eval')
; ;

View File

@ -16,12 +16,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountHousehold implements ExportInterface, GroupedExportInterface class CountHousehold implements ExportInterface, GroupedExportInterface
{ {
private EntityRepository $acpRepository; private EntityRepository $repository;
public function __construct( public function __construct(
EntityManagerInterface $em EntityManagerInterface $em
) { ) {
$this->acpRepository = $em->getRepository(AccompanyingPeriod::class); $this->repository = $em->getRepository(AccompanyingPeriod::class);
} }
/** /**
@ -102,7 +102,7 @@ class CountHousehold implements ExportInterface, GroupedExportInterface
*/ */
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{ {
$qb = $this->acpRepository->createQueryBuilder('acp') $qb = $this->repository->createQueryBuilder('acp')
->join('acp.participations', 'acppart') ->join('acp.participations', 'acppart')
->join('acppart.person', 'person') ->join('acppart.person', 'person')
->join('person.householdParticipations', 'householdmember') ->join('person.householdParticipations', 'householdmember')

View File

@ -14,9 +14,11 @@ namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface; 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\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -25,11 +27,12 @@ use Symfony\Component\Security\Core\Role\Role;
class CountSocialWorkActions implements ExportInterface, GroupedExportInterface class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
{ {
protected AccompanyingPeriodWorkRepository $socialActionRepository; protected EntityRepository $repository;
public function __construct(AccompanyingPeriodWorkRepository $socialActionRepository) public function __construct(
{ EntityManagerInterface $em
$this->socialActionRepository = $socialActionRepository; ) {
$this->repository = $em->getRepository(AccompanyingPeriod::class);
} }
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
@ -54,7 +57,7 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {
if ('export_count_social_work_actions' !== $key) { if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export"); throw new LogicException("the key {$key} is not used by this export");
} }
@ -68,7 +71,7 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function getQueryKeys($data): array public function getQueryKeys($data): array
{ {
return ['export_count_social_work_actions']; return ['export_result'];
} }
public function getResult($qb, $data) public function getResult($qb, $data)
@ -83,10 +86,11 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{ {
$qb = $this $qb = $this->repository->createQueryBuilder('acp')
->socialActionRepository ->join('acp.works', 'acpw')
->createQueryBuilder('acpw') ;
->select('COUNT(acpw.id) as export_count_social_work_actions');
$qb->select('COUNT(acpw.id) as export_result');
return $qb; return $qb;
} }
@ -99,7 +103,10 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function supportsModifiers(): array public function supportsModifiers(): array
{ {
return [Declarations::SOCIAL_WORK_ACTION_TYPE, Declarations::ACP_SHARED]; return [
Declarations::SOCIAL_WORK_ACTION_TYPE,
Declarations::ACP_SHARED
];
} }
public function getGroup(): string public function getGroup(): string

View File

@ -15,9 +15,11 @@ 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\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -26,15 +28,12 @@ use Symfony\Component\Security\Core\Role\Role;
class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface
{ {
private AccompanyingPeriodRepository $periodRepository; private EntityRepository $repository;
/**
* @param AccompanyingPeriodRepository $periodRepository
*/
public function __construct( public function __construct(
AccompanyingPeriodRepository $periodRepository EntityManagerInterface $em
) { ) {
$this->periodRepository = $periodRepository; $this->repository = $em->getRepository(AccompanyingPeriod::class);
} }
/** /**
@ -118,10 +117,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
*/ */
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{ {
$qb = $this->periodRepository->createQueryBuilder('acp'); $qb = $this->repository->createQueryBuilder('acp');
$expr = $qb->expr();
$force_closingdate = $data['closingdate']; // parameter from buildForm
$qb $qb
->select('AVG( ->select('AVG(
@ -131,7 +127,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
ELSE :force_closingDate ELSE :force_closingDate
END ) - acp.openingDate END ) - acp.openingDate
) AS export_result') ) AS export_result')
->setParameter('force_closingDate', $force_closingdate) ->setParameter('force_closingDate', $data['closingdate'])
; ;
return $qb; return $qb;
@ -150,7 +146,9 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
*/ */
public function supportsModifiers(): array public function supportsModifiers(): array
{ {
return [Declarations::ACP_TYPE]; return [
Declarations::ACP_TYPE
];
} }
public function getGroup(): string public function getGroup(): string