Merge branch '179-remove-filter-by-center-in-exports' into 'master'

Resolve "Export: permettre de ne pas filtrer les résultats par centre"

Closes #179

See merge request Chill-Projet/chill-bundles!599
This commit is contained in:
Julien Fastré 2023-10-24 13:18:03 +00:00
commit 617d09ab8a
48 changed files with 1168 additions and 412 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: '[export] create a parameter that will force to skip the filtering by center
(ACL) when generating an export'
time: 2023-10-19T17:19:00.51809407+02:00
custom:
Issue: "179"

View File

@ -11,8 +11,8 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Export\Export\LinkedToACP; namespace Chill\ActivityBundle\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Export\Declarations;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\ExportInterface;
@ -21,19 +21,19 @@ use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class AvgActivityDuration implements ExportInterface, GroupedExportInterface class AvgActivityDuration implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, private readonly ActivityRepository $activityRepository,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(Activity::class); $this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) {} public function buildForm(FormBuilderInterface $builder) {}
@ -91,13 +91,14 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
{ {
$centers = array_map(static fn ($el) => $el['center'], $acl); $centers = array_map(static fn ($el) => $el['center'], $acl);
$qb = $this->repository->createQueryBuilder('activity'); $qb = $this->activityRepository->createQueryBuilder('activity');
$qb $qb
->join('activity.accompanyingPeriod', 'acp') ->join('activity.accompanyingPeriod', 'acp')
->select('AVG(activity.durationTime) as export_avg_activity_duration') ->select('AVG(activity.durationTime) as export_avg_activity_duration')
->andWhere($qb->expr()->isNotNull('activity.durationTime')); ->andWhere($qb->expr()->isNotNull('activity.durationTime'));
if ($this->filterStatsByCenters) {
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
@ -108,6 +109,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -24,16 +24,21 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterface class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; protected EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(Activity::class); $this->repository = $em->getRepository(Activity::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
@ -101,6 +106,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
->select('AVG(activity.travelTime) as export_avg_activity_visit_duration') ->select('AVG(activity.travelTime) as export_avg_activity_visit_duration')
->andWhere($qb->expr()->isNotNull('activity.travelTime')); ->andWhere($qb->expr()->isNotNull('activity.travelTime'));
if ($this->filterStatsByCenters) {
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
@ -111,6 +117,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -24,16 +24,21 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountActivity implements ExportInterface, GroupedExportInterface class CountActivity implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; protected EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(Activity::class); $this->repository = $em->getRepository(Activity::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) {} public function buildForm(FormBuilderInterface $builder) {}
@ -95,6 +100,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
->createQueryBuilder('activity') ->createQueryBuilder('activity')
->join('activity.accompanyingPeriod', 'acp'); ->join('activity.accompanyingPeriod', 'acp');
if ($this->filterStatsByCenters) {
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
@ -105,6 +111,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -22,11 +22,21 @@ use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Export\ListInterface;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ListActivity implements ListInterface, GroupedExportInterface class ListActivity implements ListInterface, GroupedExportInterface
{ {
public function __construct(private readonly ListActivityHelper $helper, private readonly EntityManagerInterface $entityManager, private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper) {} private readonly bool $filterStatsByCenters;
public function __construct(
private readonly ListActivityHelper $helper,
private readonly EntityManagerInterface $entityManager,
private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -107,7 +117,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
->join('activity.accompanyingPeriod', 'acp') ->join('activity.accompanyingPeriod', 'acp')
->leftJoin('acp.participations', 'acppart') ->leftJoin('acp.participations', 'acppart')
->leftJoin('acppart.person', 'person') ->leftJoin('acppart.person', 'person')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL');
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 'SELECT 1
@ -117,11 +130,14 @@ class ListActivity implements ListInterface, GroupedExportInterface
' '
) )
) )
->setParameter('authorized_centers', $centers);
}
$qb
// some grouping are necessary // some grouping are necessary
->addGroupBy('acp.id') ->addGroupBy('acp.id')
->addOrderBy('activity.date') ->addOrderBy('activity.date')
->addOrderBy('activity.id') ->addOrderBy('activity.id');
->setParameter('authorized_centers', $centers);
$this->helper->addSelect($qb); $this->helper->addSelect($qb);

View File

@ -24,16 +24,20 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class SumActivityDuration implements ExportInterface, GroupedExportInterface class SumActivityDuration implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; protected EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(Activity::class); $this->repository = $em->getRepository(Activity::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
@ -101,6 +105,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
$qb->select('SUM(activity.durationTime) as export_sum_activity_duration') $qb->select('SUM(activity.durationTime) as export_sum_activity_duration')
->andWhere($qb->expr()->isNotNull('activity.durationTime')); ->andWhere($qb->expr()->isNotNull('activity.durationTime'));
if ($this->filterStatsByCenters) {
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
@ -111,6 +116,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -24,16 +24,20 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class SumActivityVisitDuration implements ExportInterface, GroupedExportInterface class SumActivityVisitDuration implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; protected EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(Activity::class); $this->repository = $em->getRepository(Activity::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
@ -101,6 +105,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
$qb->select('SUM(activity.travelTime) as export_sum_activity_visit_duration') $qb->select('SUM(activity.travelTime) as export_sum_activity_visit_duration')
->andWhere($qb->expr()->isNotNull('activity.travelTime')); ->andWhere($qb->expr()->isNotNull('activity.travelTime'));
if ($this->filterStatsByCenters) {
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
@ -111,6 +116,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -19,11 +19,19 @@ use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountActivity implements ExportInterface, GroupedExportInterface class CountActivity implements ExportInterface, GroupedExportInterface
{ {
public function __construct(protected ActivityRepository $activityRepository) {} private readonly bool $filterStatsByCenters;
public function __construct(
private readonly ActivityRepository $activityRepository,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) {} public function buildForm(FormBuilderInterface $builder) {}
@ -82,12 +90,13 @@ class CountActivity implements ExportInterface, GroupedExportInterface
$qb = $this->activityRepository $qb = $this->activityRepository
->createQueryBuilder('activity') ->createQueryBuilder('activity')
->join('activity.person', 'person') ->join('activity.person', 'person');
->join('person.centerHistory', 'centerHistory');
$qb->select('COUNT(activity.id) as export_count_activity'); $qb->select('COUNT(activity.id) as export_count_activity');
if ($this->filterStatsByCenters) {
$qb $qb
->join('person.centerHistory', 'centerHistory')
->where( ->where(
$qb->expr()->andX( $qb->expr()->andX(
$qb->expr()->lte('centerHistory.startDate', 'activity.date'), $qb->expr()->lte('centerHistory.startDate', 'activity.date'),
@ -99,6 +108,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
) )
->andWhere($qb->expr()->in('centerHistory.center', ':centers')) ->andWhere($qb->expr()->in('centerHistory.center', ':centers'))
->setParameter('centers', $centers); ->setParameter('centers', $centers);
}
return $qb; return $qb;
} }

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
@ -44,8 +45,17 @@ class ListActivity implements ListInterface, GroupedExportInterface
'person_lastname', 'person_lastname',
'person_id', 'person_id',
]; ];
private readonly bool $filterStatsByCenters;
public function __construct(protected EntityManagerInterface $entityManager, protected TranslatorInterface $translator, protected TranslatableStringHelperInterface $translatableStringHelper, private readonly ActivityRepository $activityRepository) {} public function __construct(
protected EntityManagerInterface $entityManager,
protected TranslatorInterface $translator,
protected TranslatableStringHelperInterface $translatableStringHelper,
private readonly ActivityRepository $activityRepository,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -188,9 +198,10 @@ class ListActivity implements ListInterface, GroupedExportInterface
$qb $qb
->from('ChillActivityBundle:Activity', 'activity') ->from('ChillActivityBundle:Activity', 'activity')
->join('activity.person', 'actperson') ->join('activity.person', 'actperson');
->join('actperson.centerHistory', 'centerHistory');
if ($this->filterStatsByCenters) {
$qb->join('actperson.centerHistory', 'centerHistory');
$qb->where( $qb->where(
$qb->expr()->andX( $qb->expr()->andX(
$qb->expr()->lte('centerHistory.startDate', 'activity.date'), $qb->expr()->lte('centerHistory.startDate', 'activity.date'),
@ -202,6 +213,7 @@ class ListActivity implements ListInterface, GroupedExportInterface
) )
->andWhere($qb->expr()->in('centerHistory.center', ':centers')) ->andWhere($qb->expr()->in('centerHistory.center', ':centers'))
->setParameter('centers', $centers); ->setParameter('centers', $centers);
}
foreach ($this->fields as $f) { foreach ($this->fields as $f) {
if (\in_array($f, $data['fields'], true)) { if (\in_array($f, $data['fields'], true)) {

View File

@ -20,6 +20,7 @@ use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
/** /**
@ -30,17 +31,21 @@ use Symfony\Component\Form\FormBuilderInterface;
class StatActivityDuration implements ExportInterface, GroupedExportInterface class StatActivityDuration implements ExportInterface, GroupedExportInterface
{ {
final public const SUM = 'sum'; final public const SUM = 'sum';
private readonly bool $filterStatsByCenters;
/** /**
* @param string $action the stat to perform * @param string $action the stat to perform
*/ */
public function __construct( public function __construct(
private readonly ActivityRepository $activityRepository, private readonly ActivityRepository $activityRepository,
ParameterBagInterface $parameterBag,
/** /**
* The action for this report. * The action for this report.
*/ */
protected string $action = 'sum' protected string $action = 'sum'
) {} ) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) {} public function buildForm(FormBuilderInterface $builder) {}
@ -119,10 +124,11 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface
} }
$qb->select($select) $qb->select($select)
->join('activity.person', 'person') ->join('activity.person', 'person');
->join('person.centerHistory', 'centerHistory');
if ($this->filterStatsByCenters) {
$qb $qb
->join('person.centerHistory', 'centerHistory')
->where( ->where(
$qb->expr()->andX( $qb->expr()->andX(
$qb->expr()->lte('centerHistory.startDate', 'activity.date'), $qb->expr()->lte('centerHistory.startDate', 'activity.date'),
@ -134,6 +140,7 @@ class StatActivityDuration implements ExportInterface, GroupedExportInterface
) )
->andWhere($qb->expr()->in('centerHistory.center', ':centers')) ->andWhere($qb->expr()->in('centerHistory.center', ':centers'))
->setParameter('centers', $centers); ->setParameter('centers', $centers);
}
return $qb; return $qb;
} }

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP; namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityDuration; use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityDuration;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
/** /**
@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class AvgActivityDurationTest extends AbstractExportTest final class AvgActivityDurationTest extends AbstractExportTest
{ {
private AvgActivityDuration $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.avg_activity_duration_linked_to_acp');
} }
public function getExport() public function getExport()
{ {
return $this->export; $activityRepository = self::$container->get(ActivityRepository::class);
yield new AvgActivityDuration($activityRepository, $this->getParameters(true));
yield new AvgActivityDuration($activityRepository, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityVisitDuration; use Chill\ActivityBundle\Export\Export\LinkedToACP\AvgActivityVisitDuration;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class AvgActivityVisitDurationTest extends AbstractExportTest final class AvgActivityVisitDurationTest extends AbstractExportTest
{ {
private AvgActivityVisitDuration $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.avg_activity_visit_duration_linked_to_acp');
} }
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new AvgActivityVisitDuration($em, $this->getParameters(true));
yield new AvgActivityVisitDuration($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Export\Export\LinkedToACP\CountActivity; use Chill\ActivityBundle\Export\Export\LinkedToACP\CountActivity;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class CountActivityTest extends AbstractExportTest final class CountActivityTest extends AbstractExportTest
{ {
private CountActivity $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.count_activity_linked_to_acp');
} }
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new CountActivity($em, $this->getParameters(true));
yield new CountActivity($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityDuration; use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityDuration;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class SumActivityDurationTest extends AbstractExportTest final class SumActivityDurationTest extends AbstractExportTest
{ {
private SumActivityDuration $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.sum_activity_duration_linked_to_acp');
} }
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new SumActivityDuration($em, $this->getParameters(true));
yield new SumActivityDuration($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToACP;
use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityVisitDuration; use Chill\ActivityBundle\Export\Export\LinkedToACP\SumActivityVisitDuration;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -32,7 +33,10 @@ final class SumActivityVisitDurationTest extends AbstractExportTest
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new SumActivityVisitDuration($em, $this->getParameters(true));
yield new SumActivityVisitDuration($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson;
use Chill\ActivityBundle\Export\Export\LinkedToPerson\CountActivity; use Chill\ActivityBundle\Export\Export\LinkedToPerson\CountActivity;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
/** /**
@ -21,18 +22,17 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class CountActivityTest extends AbstractExportTest final class CountActivityTest extends AbstractExportTest
{ {
private CountActivity $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.count_activity_linked_to_person');
} }
public function getExport() public function getExport()
{ {
return $this->export; $activityRepository = self::$container->get(ActivityRepository::class);
yield new CountActivity($activityRepository, $this->getParameters(true));
yield new CountActivity($activityRepository, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -12,8 +12,12 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson;
use Chill\ActivityBundle\Export\Export\LinkedToPerson\ListActivity; use Chill\ActivityBundle\Export\Export\LinkedToPerson\ListActivity;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* @internal * @internal
@ -24,14 +28,12 @@ final class ListActivityTest extends AbstractExportTest
{ {
use ProphecyTrait; use ProphecyTrait;
private ListActivity $export; private readonly ListActivity $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.list_activity_linked_to_person');
$request = $this->prophesize() $request = $this->prophesize()
->willExtend(\Symfony\Component\HttpFoundation\Request::class); ->willExtend(\Symfony\Component\HttpFoundation\Request::class);
@ -43,7 +45,26 @@ final class ListActivityTest extends AbstractExportTest
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
$translator = self::$container->get(TranslatorInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelperInterface::class);
$activityRepository = self::$container->get(ActivityRepository::class);
yield new ListActivity(
$em,
$translator,
$translatableStringHelper,
$activityRepository,
$this->getParameters(true)
);
yield new ListActivity(
$em,
$translator,
$translatableStringHelper,
$activityRepository,
$this->getParameters(false)
);
} }
public function getFormData() public function getFormData()

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson; namespace Chill\ActivityBundle\Tests\Export\Export\LinkedToPerson;
use Chill\ActivityBundle\Export\Export\LinkedToPerson\StatActivityDuration; use Chill\ActivityBundle\Export\Export\LinkedToPerson\StatActivityDuration;
use Chill\ActivityBundle\Repository\ActivityRepository;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
/** /**
@ -23,18 +24,18 @@ use Chill\MainBundle\Test\Export\AbstractExportTest;
*/ */
final class StatActivityDurationTest extends AbstractExportTest final class StatActivityDurationTest extends AbstractExportTest
{ {
private StatActivityDuration $export; private readonly StatActivityDuration $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.activity.export.sum_activity_duration_linked_to_person');
} }
public function getExport() public function getExport()
{ {
return $this->export; $activityRepository = self::$container->get(ActivityRepository::class);
yield new StatActivityDuration($activityRepository, $this->getParameters(true), 'sum');
yield new StatActivityDuration($activityRepository, $this->getParameters(false), 'sum');
} }
public function getFormData(): array public function getFormData(): array

View File

@ -25,7 +25,9 @@ use Symfony\Component\Validator\Exception\LogicException;
class CountCalendars implements ExportInterface, GroupedExportInterface class CountCalendars implements ExportInterface, GroupedExportInterface
{ {
public function __construct(private readonly CalendarRepository $calendarRepository) {} public function __construct(
private readonly CalendarRepository $calendarRepository,
) {}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {

View File

@ -27,6 +27,7 @@ use Chill\MainBundle\Security\Authorization\SavedExportVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
@ -46,6 +47,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/ */
class ExportController extends AbstractController class ExportController extends AbstractController
{ {
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
private readonly ChillRedis $redis, private readonly ChillRedis $redis,
private readonly ExportManager $exportManager, private readonly ExportManager $exportManager,
@ -56,8 +59,11 @@ class ExportController extends AbstractController
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly ExportFormHelper $exportFormHelper, private readonly ExportFormHelper $exportFormHelper,
private readonly SavedExportRepositoryInterface $savedExportRepository, private readonly SavedExportRepositoryInterface $savedExportRepository,
private readonly Security $security private readonly Security $security,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
/** /**
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/exports/download/{alias}", name="chill_main_export_download", methods={"GET"}) * @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/exports/download/{alias}", name="chill_main_export_download", methods={"GET"})
@ -484,9 +490,13 @@ class ExportController extends AbstractController
$alias = $rawData['alias']; $alias = $rawData['alias'];
if ($this->filterStatsByCenters) {
$formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport); $formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], $savedExport);
$formCenters->submit($rawData['centers']); $formCenters->submit($rawData['centers']);
$dataCenters = $formCenters->getData(); $dataCenters = $formCenters->getData();
} else {
$dataCenters = ['centers' => []];
}
$formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters, $savedExport); $formExport = $this->createCreateFormExport($alias, 'generate_export', $dataCenters, $savedExport);
$formExport->submit($rawData['export']); $formExport->submit($rawData['export']);
@ -513,6 +523,14 @@ class ExportController extends AbstractController
*/ */
private function selectCentersStep(Request $request, DirectExportInterface|ExportInterface $export, $alias, SavedExport $savedExport = null) private function selectCentersStep(Request $request, DirectExportInterface|ExportInterface $export, $alias, SavedExport $savedExport = null)
{ {
if (!$this->filterStatsByCenters) {
return $this->redirectToRoute('chill_main_export_new', [
'step' => $this->getNextStep('centers', $export),
'alias' => $alias,
'from_saved' => $request->get('from_saved', ''),
]);
}
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */ /** @var \Chill\MainBundle\Export\ExportManager $exportManager */
$exportManager = $this->exportManager; $exportManager = $this->exportManager;

View File

@ -116,8 +116,12 @@ class Configuration implements ConfigurationInterface
->booleanNode('form_show_centers') ->booleanNode('form_show_centers')
->defaultTrue() ->defaultTrue()
->end() ->end()
->booleanNode('filter_stats_by_center')
->defaultTrue()
->info("if set to false, the exports won't take into account the center of the people")
->end() ->end()
->end() ->end()
->end() // end of 'acl'
->booleanNode('access_global_history') ->booleanNode('access_global_history')
->defaultTrue() ->defaultTrue()
->end() ->end()

View File

@ -11,11 +11,15 @@ declare(strict_types=1);
namespace Chill\MainBundle\Test\Export; namespace Chill\MainBundle\Test\Export;
use Chill\MainBundle\Export\DirectExportInterface;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Test\PrepareClientTrait; use Chill\MainBundle\Test\PrepareClientTrait;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NativeQuery; use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
/** /**
* This class provide a set of tests for exports. * This class provide a set of tests for exports.
@ -94,7 +98,7 @@ abstract class AbstractExportTest extends WebTestCase
/** /**
* Create an instance of the report to test. * Create an instance of the report to test.
* *
* @return \Chill\MainBundle\Export\ExportInterface an instance of the export to test * @return ExportInterface|DirectExportInterface|iterable<ExportInterface>|iterable<DirectExportInterface> an instance of the export to test
*/ */
abstract public function getExport(); abstract public function getExport();
@ -116,12 +120,32 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
abstract public function getModifiersCombination(); abstract public function getModifiersCombination();
protected function getParameters(bool $filterStatsByCenter): ParameterBagInterface
{
return new ParameterBag(['chill_main' => ['acl' => ['filter_stats_by_center' => $filterStatsByCenter]]]);
}
/**
* wrap the results of @see{self::getExports()}, which may be an iterable or an export into an iterble.
*/
private function getExports(): iterable
{
$exports = $this->getExport();
if (is_iterable($exports)) {
return $exports;
}
return [$exports];
}
/** /**
* Test the formatters type are string. * Test the formatters type are string.
*/ */
public function testGetAllowedFormattersType() public function testGetAllowedFormattersType()
{ {
$formattersTypes = $this->getExport()->getAllowedFormattersTypes(); foreach ($this->getExports() as $export) {
$formattersTypes = $export->getAllowedFormattersTypes();
$this->assertContainsOnly( $this->assertContainsOnly(
'string', 'string',
@ -130,14 +154,14 @@ abstract class AbstractExportTest extends WebTestCase
'Test that the method `getAllowedFormattersTypes` returns an array of string' 'Test that the method `getAllowedFormattersTypes` returns an array of string'
); );
} }
}
/** /**
* Test that the description is not empty. * Test that the description is not empty.
*/ */
public function testGetDescription() public function testGetDescription()
{ {
$export = $this->getExport(); foreach ($this->getExports() as $export) {
$this->assertIsString( $this->assertIsString(
$export->getDescription(), $export->getDescription(),
'Assert that the `getDescription` method return a string' 'Assert that the `getDescription` method return a string'
@ -148,6 +172,7 @@ abstract class AbstractExportTest extends WebTestCase
.'string.' .'string.'
); );
} }
}
/** /**
* Test that the query keys are strings. * Test that the query keys are strings.
@ -156,7 +181,8 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
public function testGetQueryKeys(array $data) public function testGetQueryKeys(array $data)
{ {
$queryKeys = $this->getExport()->getQueryKeys($data); foreach ($this->getExports() as $export) {
$queryKeys = $export->getQueryKeys($data);
$this->assertContainsOnly( $this->assertContainsOnly(
'string', 'string',
@ -170,6 +196,7 @@ abstract class AbstractExportTest extends WebTestCase
'test that there are at least one query key returned' 'test that there are at least one query key returned'
); );
} }
}
/** /**
* Test that. * Test that.
@ -187,11 +214,12 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
public function testGetResultsAndLabels($modifiers, $acl, array $data) public function testGetResultsAndLabels($modifiers, $acl, array $data)
{ {
foreach ($this->getExports() as $export) {
// it is more convenient to group the `getResult` and `getLabels` test // it is more convenient to group the `getResult` and `getLabels` test
// due to the fact that testing both methods use the same tools. // due to the fact that testing both methods use the same tools.
$queryKeys = $this->getExport()->getQueryKeys($data); $queryKeys = $export->getQueryKeys($data);
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data); $query = $export->initiateQuery($modifiers, $acl, $data);
// limit the result for the query for performance reason (only for QueryBuilder, // limit the result for the query for performance reason (only for QueryBuilder,
// not possible in NativeQuery) // not possible in NativeQuery)
@ -199,7 +227,7 @@ abstract class AbstractExportTest extends WebTestCase
$query->setMaxResults(1); $query->setMaxResults(1);
} }
$results = $this->getExport()->getResult($query, $data); $results = $export->getResult($query, $data);
$this->assertIsArray( $this->assertIsArray(
$results, $results,
@ -219,6 +247,7 @@ abstract class AbstractExportTest extends WebTestCase
'test that each row in the result is traversable or an array' 'test that each row in the result is traversable or an array'
); );
$i = 0;
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$this->assertContains( $this->assertContains(
$key, $key,
@ -226,7 +255,7 @@ abstract class AbstractExportTest extends WebTestCase
'test that each key is present in `getQueryKeys`' 'test that each key is present in `getQueryKeys`'
); );
$closure = $this->getExport()->getLabels($key, [$value], $data); $closure = $export->getLabels($key, [$value], $data);
$this->assertTrue( $this->assertTrue(
\is_callable($closure, false), \is_callable($closure, false),
@ -242,6 +271,13 @@ abstract class AbstractExportTest extends WebTestCase
sprintf('Test that the callable return by `getLabels` for key %s ' sprintf('Test that the callable return by `getLabels` for key %s '
.'can provide an header', $key) .'can provide an header', $key)
); );
++$i;
if ($i > 15) {
// do not iterate on each result
break;
}
}
} }
} }
@ -250,8 +286,7 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
public function testGetType() public function testGetType()
{ {
$export = $this->getExport(); foreach ($this->getExports() as $export) {
$this->assertIsString( $this->assertIsString(
$export->getType(), $export->getType(),
'Assert that the `getType` method return a string' 'Assert that the `getType` method return a string'
@ -259,6 +294,7 @@ abstract class AbstractExportTest extends WebTestCase
$this->assertNotEmpty($export->getType(), 'Assert that the `getType` method' $this->assertNotEmpty($export->getType(), 'Assert that the `getType` method'
.' does not return an empty string.'); .' does not return an empty string.');
} }
}
/** /**
* test that the query returned is a QueryBuilder or a NativeQuery. * test that the query returned is a QueryBuilder or a NativeQuery.
@ -272,14 +308,15 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
public function testInitiateQuery(mixed $modifiers, mixed $acl, mixed $data) public function testInitiateQuery(mixed $modifiers, mixed $acl, mixed $data)
{ {
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data); foreach ($this->getExports() as $export) {
$query = $export->initiateQuery($modifiers, $acl, $data);
$this->assertTrue( $this->assertTrue(
$query instanceof QueryBuilder || $query instanceof NativeQuery, $query instanceof QueryBuilder || $query instanceof NativeQuery,
sprintf( sprintf(
'Assert that the returned query is an instance of %s or %s', 'Assert that the returned query is an instance of %s or %s',
QueryBuilder::class, QueryBuilder::class,
Query::class NativeQuery::class
) )
); );
@ -302,16 +339,19 @@ abstract class AbstractExportTest extends WebTestCase
); );
} }
} }
}
/** /**
* Test required role is an instance of Role. * Test required role is an instance of Role.
*/ */
public function testRequiredRole() public function testRequiredRole()
{ {
$role = $this->getExport()->requiredRole(); foreach ($this->getExports() as $export) {
$role = $export->requiredRole();
self::assertIsString($role); self::assertIsString($role);
} }
}
/** /**
* Test that supportsModifier return :. * Test that supportsModifier return :.
@ -323,7 +363,7 @@ abstract class AbstractExportTest extends WebTestCase
*/ */
public function testSupportsModifier(mixed $modifiers, mixed $acl, mixed $data) public function testSupportsModifier(mixed $modifiers, mixed $acl, mixed $data)
{ {
$export = $this->getExport(); foreach ($this->getExports() as $export) {
$query = $export->initiateQuery($modifiers, $acl, $data); $query = $export->initiateQuery($modifiers, $acl, $data);
if ($query instanceof QueryBuilder) { if ($query instanceof QueryBuilder) {
@ -342,3 +382,4 @@ abstract class AbstractExportTest extends WebTestCase
} }
} }
} }
}

View File

@ -23,16 +23,20 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
{ {
protected EntityRepository $repository; protected EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(AccompanyingPeriod::class); $this->repository = $em->getRepository(AccompanyingPeriod::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
@ -102,6 +106,10 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
->andWhere('acp.step != :count_acp_step') ->andWhere('acp.step != :count_acp_step')
->leftJoin('acp.participations', 'acppart') ->leftJoin('acp.participations', 'acppart')
->leftJoin('acppart.person', 'person') ->leftJoin('acppart.person', 'person')
->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT);
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -109,8 +117,8 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
' '
) )
) )
->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT)
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -22,11 +22,19 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInterface class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInterface
{ {
public function __construct(protected EntityManagerInterface $em) {} private readonly bool $filterStatsByCenters;
public function __construct(
protected EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
@ -95,7 +103,10 @@ class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInter
->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw') ->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw')
->join('acpw.accompanyingPeriod', 'acp') ->join('acpw.accompanyingPeriod', 'acp')
->join('acp.participations', 'acppart') ->join('acp.participations', 'acppart')
->join('acppart.person', 'person') ->join('acppart.person', 'person');
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -104,6 +115,7 @@ class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInter
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
$qb->select('COUNT(DISTINCT acpw.id) as export_result'); $qb->select('COUNT(DISTINCT acpw.id) as export_result');

View File

@ -21,11 +21,19 @@ 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\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountEvaluation implements ExportInterface, GroupedExportInterface class CountEvaluation implements ExportInterface, GroupedExportInterface
{ {
public function __construct(private readonly EntityManagerInterface $entityManager) {} private readonly bool $filterStatsByCenters;
public function __construct(
private readonly EntityManagerInterface $entityManager,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) {} public function buildForm(FormBuilderInterface $builder) {}
@ -92,7 +100,10 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
->join('workeval.accompanyingPeriodWork', 'acpw') ->join('workeval.accompanyingPeriodWork', 'acpw')
->join('acpw.accompanyingPeriod', 'acp') ->join('acpw.accompanyingPeriod', 'acp')
->join('acp.participations', 'acppart') ->join('acp.participations', 'acppart')
->join('acppart.person', 'person') ->join('acppart.person', 'person');
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -101,6 +112,7 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -23,13 +23,21 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter; use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountHousehold implements ExportInterface, GroupedExportInterface class CountHousehold implements ExportInterface, GroupedExportInterface
{ {
private const TR_PREFIX = 'export.export.nb_household_with_course.'; private const TR_PREFIX = 'export.export.nb_household_with_course.';
private readonly bool $filterStatsByCenters;
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly RollingDateConverterInterface $rollingDateConverter) {} public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly RollingDateConverterInterface $rollingDateConverter,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -112,6 +120,14 @@ class CountHousehold implements ExportInterface, GroupedExportInterface
->join('person.accompanyingPeriodParticipations', 'acppart') ->join('person.accompanyingPeriodParticipations', 'acppart')
->join('acppart.accompanyingPeriod', 'acp') ->join('acppart.accompanyingPeriod', 'acp')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date']));
$qb
->select('COUNT(DISTINCT household.id) AS household_export_result')
->addSelect('COUNT(DISTINCT acp.id) AS acp_export_result');
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -120,12 +136,8 @@ class CountHousehold implements ExportInterface, GroupedExportInterface
) )
) )
->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)')
->setParameter('authorized_centers', $centers) ->setParameter('authorized_centers', $centers);
->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); }
$qb
->select('COUNT(DISTINCT household.id) AS household_export_result')
->addSelect('COUNT(DISTINCT acp.id) AS acp_export_result');
return $qb; return $qb;
} }

View File

@ -20,11 +20,19 @@ use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountPerson implements ExportInterface, GroupedExportInterface class CountPerson implements ExportInterface, GroupedExportInterface
{ {
public function __construct(protected PersonRepository $personRepository) {} private readonly bool $filterStatsByCenters;
public function __construct(
protected PersonRepository $personRepository,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -94,13 +102,17 @@ class CountPerson implements ExportInterface, GroupedExportInterface
$qb = $this->personRepository->createQueryBuilder('person'); $qb = $this->personRepository->createQueryBuilder('person');
$qb->select('COUNT(DISTINCT person.id) AS export_result') $qb->select('COUNT(DISTINCT person.id) AS export_result');
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
return $qb; return $qb;
} }

View File

@ -22,16 +22,20 @@ use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExportInterface class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExportInterface
{ {
private readonly EntityRepository $repository; private readonly EntityRepository $repository;
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(AccompanyingPeriod::class); $this->repository = $em->getRepository(AccompanyingPeriod::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
@ -105,11 +109,13 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor
$qb->join('acppart.person', 'person'); $qb->join('acppart.person', 'person');
} }
if ($this->filterStatsByCenters) {
$qb->andWhere( $qb->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
) )
)->setParameter('authorized_centers', $centers); )->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -26,15 +26,21 @@ use Chill\PersonBundle\Export\Helper\ListAccompanyingPeriodHelper;
use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExportInterface final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExportInterface
{ {
private bool $filterStatsByCenters;
public function __construct( public function __construct(
private EntityManagerInterface $entityManager, private EntityManagerInterface $entityManager,
private RollingDateConverterInterface $rollingDateConverter, private RollingDateConverterInterface $rollingDateConverter,
private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper, private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -102,6 +108,10 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp
$qb $qb
->from(AccompanyingPeriod::class, 'acp') ->from(AccompanyingPeriod::class, 'acp')
->andWhere('acp.step != :list_acp_step') ->andWhere('acp.step != :list_acp_step')
->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT);
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
@ -110,8 +120,8 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp
' '
) )
) )
->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT)
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date']));

View File

@ -44,6 +44,7 @@ use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterface class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterface
@ -78,6 +79,8 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac
'updatedBy', 'updatedBy',
]; ];
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly DateTimeHelper $dateTimeHelper, private readonly DateTimeHelper $dateTimeHelper,
@ -90,8 +93,11 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac
private readonly SocialActionRender $socialActionRender, private readonly SocialActionRender $socialActionRender,
private readonly RollingDateConverterInterface $rollingDateConverter, private readonly RollingDateConverterInterface $rollingDateConverter,
private readonly AggregateStringHelper $aggregateStringHelper, private readonly AggregateStringHelper $aggregateStringHelper,
private readonly SocialActionRepository $socialActionRepository private readonly SocialActionRepository $socialActionRepository,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -214,6 +220,10 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
// get participants at the given date // get participants at the given date
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date']));
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -221,8 +231,8 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac
' '
) )
) )
->setParameter('authorized_centers', $centers) ->setParameter('authorized_centers', $centers);
->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); }
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -37,6 +37,7 @@ use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ListEvaluation implements ListInterface, GroupedExportInterface class ListEvaluation implements ListInterface, GroupedExportInterface
@ -68,7 +69,24 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
'updatedBy', 'updatedBy',
]; ];
public function __construct(private readonly EntityManagerInterface $entityManager, private readonly SocialIssueRender $socialIssueRender, private readonly SocialIssueRepository $socialIssueRepository, private readonly SocialActionRender $socialActionRender, private readonly SocialActionRepository $socialActionRepository, private readonly UserHelper $userHelper, private readonly LabelPersonHelper $personHelper, private readonly DateTimeHelper $dateTimeHelper, private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper, private readonly AggregateStringHelper $aggregateStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {} private readonly bool $filterStatsByCenters;
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly SocialIssueRender $socialIssueRender,
private readonly SocialIssueRepository $socialIssueRepository,
private readonly SocialActionRender $socialActionRender,
private readonly SocialActionRepository $socialActionRepository,
private readonly UserHelper $userHelper,
private readonly LabelPersonHelper $personHelper,
private readonly DateTimeHelper $dateTimeHelper,
private readonly TranslatableStringExportLabelHelper $translatableStringExportLabelHelper,
private readonly AggregateStringHelper $aggregateStringHelper,
private readonly RollingDateConverterInterface $rollingDateConverter,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -190,6 +208,10 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
// get participants at the given date // get participants at the given date
->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)') ->andWhere('acppart.startDate <= :calc_date AND (acppart.endDate > :calc_date OR acppart.endDate IS NULL)')
->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date']));
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -197,8 +219,8 @@ class ListEvaluation implements ListInterface, GroupedExportInterface
' '
) )
) )
->setParameter('authorized_centers', $centers) ->setParameter('authorized_centers', $centers);
->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); }
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -29,6 +29,7 @@ use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
@ -42,14 +43,18 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
'compositionComment', 'compositionComment',
'compositionType', 'compositionType',
]; ];
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
private readonly ExportAddressHelper $addressHelper, private readonly ExportAddressHelper $addressHelper,
private readonly AggregateStringHelper $aggregateStringHelper, private readonly AggregateStringHelper $aggregateStringHelper,
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly RollingDateConverterInterface $rollingDateConverter, private readonly RollingDateConverterInterface $rollingDateConverter,
private readonly TranslatableStringExportLabelHelper $translatableStringHelper private readonly TranslatableStringExportLabelHelper $translatableStringHelper,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -138,6 +143,11 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
->join('person.accompanyingPeriodParticipations', 'acppart') ->join('person.accompanyingPeriodParticipations', 'acppart')
->join('acppart.accompanyingPeriod', 'acp') ->join('acppart.accompanyingPeriod', 'acp')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)')
->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date']));
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -145,9 +155,8 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
' '
) )
) )
->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') ->setParameter('authorized_centers', $centers);
->setParameter('authorized_centers', $centers) }
->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date']));
$this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date']));

View File

@ -29,6 +29,7 @@ use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
@ -40,14 +41,18 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
class ListPerson implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface class ListPerson implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface
{ {
private array $slugs = []; private array $slugs = [];
private readonly bool $filterStatsByCenters;
public function __construct( public function __construct(
private readonly ExportAddressHelper $addressHelper, private readonly ExportAddressHelper $addressHelper,
private readonly CustomFieldProvider $customFieldProvider, private readonly CustomFieldProvider $customFieldProvider,
private readonly ListPersonHelper $listPersonHelper, private readonly ListPersonHelper $listPersonHelper,
private readonly EntityManagerInterface $entityManager, private readonly EntityManagerInterface $entityManager,
private readonly TranslatableStringHelper $translatableStringHelper private readonly TranslatableStringHelper $translatableStringHelper,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -184,16 +189,18 @@ class ListPerson implements ExportElementValidatedInterface, ListInterface, Grou
throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked'); throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked');
} }
$qb = $this->entityManager->createQueryBuilder(); $qb = $this->entityManager->createQueryBuilder()
->from(Person::class, 'person');
if ($this->filterStatsByCenters) {
$qb $qb
->from(Person::class, 'person')
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.Person\PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' 'SELECT 1 FROM '.Person\PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
) )
) )
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
$fields = $data['fields']; $fields = $data['fields'];

View File

@ -17,7 +17,9 @@ use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Export\ListInterface;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
@ -27,6 +29,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Callback;
@ -37,9 +40,19 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
* *
* Details of the accompanying period are not included * Details of the accompanying period are not included
*/ */
class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface final readonly class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterface, ListInterface, GroupedExportInterface
{ {
public function __construct(private readonly ExportAddressHelper $addressHelper, private readonly ListPersonHelper $listPersonHelper, private readonly EntityManagerInterface $entityManager) {} private bool $filterStatsByCenters;
public function __construct(
private ExportAddressHelper $addressHelper,
private ListPersonHelper $listPersonHelper,
private EntityManagerInterface $entityManager,
private RollingDateConverterInterface $rollingDateConverter,
ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -69,10 +82,9 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf
])], ])],
]); ]);
$builder->add('address_date', ChillDateType::class, [ $builder->add('address_date_rolling', PickRollingDateType::class, [
'label' => 'Data valid at this date', 'label' => 'Data valid at this date',
'help' => 'Data regarding center, addresses, and so on will be computed at this date', 'help' => 'Data regarding center, addresses, and so on will be computed at this date',
'input' => 'datetime_immutable',
]); ]);
} }
@ -80,7 +92,7 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf
{ {
$choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS); $choices = array_combine(ListPersonHelper::FIELDS, ListPersonHelper::FIELDS);
return ['fields' => array_values($choices), 'address_date' => new \DateTimeImmutable()]; return ['fields' => array_values($choices), 'address_date_rolling' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getAllowedFormattersTypes() public function getAllowedFormattersTypes()
@ -162,16 +174,20 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf
$qb->from(Person::class, 'person') $qb->from(Person::class, 'person')
->join('person.accompanyingPeriodParticipations', 'acppart') ->join('person.accompanyingPeriodParticipations', 'acppart')
->join('acppart.accompanyingPeriod', 'acp') ->join('acppart.accompanyingPeriod', 'acp')
->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")) ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'"));
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
) )
)->setParameter('authorized_centers', $centers); )->setParameter('authorized_centers', $centers);
}
$fields = $data['fields']; $fields = $data['fields'];
$this->listPersonHelper->addSelect($qb, $fields, $data['address_date']); $this->listPersonHelper->addSelect($qb, $fields, $this->rollingDateConverter->convert($data['address_date_rolling']));
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -28,6 +28,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
/** /**
@ -35,12 +36,17 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInterface, GroupedExportInterface final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInterface, GroupedExportInterface
{ {
private bool $filterStatsByCenters;
public function __construct( public function __construct(
private ListPersonHelper $listPersonHelper, private ListPersonHelper $listPersonHelper,
private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper, private ListAccompanyingPeriodHelper $listAccompanyingPeriodHelper,
private EntityManagerInterface $entityManager, private EntityManagerInterface $entityManager,
private RollingDateConverterInterface $rollingDateConverter, private RollingDateConverterInterface $rollingDateConverter,
) {} ParameterBagInterface $parameterBag,
) {
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
}
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
@ -114,12 +120,16 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte
$qb->from(Person::class, 'person') $qb->from(Person::class, 'person')
->join('person.accompanyingPeriodParticipations', 'acppart') ->join('person.accompanyingPeriodParticipations', 'acppart')
->join('acppart.accompanyingPeriod', 'acp') ->join('acppart.accompanyingPeriod', 'acp')
->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'")) ->andWhere($qb->expr()->neq('acp.step', "'".AccompanyingPeriod::STEP_DRAFT."'"));
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)' 'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
) )
)->setParameter('authorized_centers', $centers); )->setParameter('authorized_centers', $centers);
}
$this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $this->rollingDateConverter->convert($data['address_date'])); $this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $this->rollingDateConverter->convert($data['address_date']));
$this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date'])); $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date']));

View File

@ -15,7 +15,9 @@ use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
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\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
@ -24,28 +26,34 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface final readonly class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportInterface
{ {
private readonly EntityRepository $repository; private readonly EntityRepository $repository;
private bool $filterStatsByCenters;
public function __construct( public function __construct(
EntityManagerInterface $em, EntityManagerInterface $em,
private RollingDateConverterInterface $rollingDateConverter,
ParameterBagInterface $parameterBag,
) { ) {
$this->repository = $em->getRepository(AccompanyingPeriod::class); $this->repository = $em->getRepository(AccompanyingPeriod::class);
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
} }
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
$builder->add('closingdate', ChillDateType::class, [ $builder->add('closingdate_rolling', PickRollingDateType::class, [
'label' => 'Closingdate to apply', 'label' => 'Closingdate to apply',
]); ]);
} }
public function getFormDefaultData(): array public function getFormDefaultData(): array
{ {
return ['closingdate' => new \DateTime('now')]; return ['closingdate_rolling' => new RollingDate(RollingDate::T_TODAY)];
} }
public function getAllowedFormattersTypes(): array public function getAllowedFormattersTypes(): array
@ -118,11 +126,15 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
->addSelect('COUNT(DISTINCT acppart.id) AS count_acppart_export_result') ->addSelect('COUNT(DISTINCT acppart.id) AS count_acppart_export_result')
->addSelect('COUNT(DISTINCT person.id) AS count_pers_export_result') ->addSelect('COUNT(DISTINCT person.id) AS count_pers_export_result')
->addSelect('COUNT(DISTINCT acp.id) AS count_acp_export_result') ->addSelect('COUNT(DISTINCT acp.id) AS count_acp_export_result')
->setParameter('force_closingDate', $data['closingdate']) ->setParameter('force_closingDate', $this->rollingDateConverter->convert($data['closingdate_rolling']))
->leftJoin('acp.participations', 'acppart') ->leftJoin('acp.participations', 'acppart')
->leftJoin('acppart.person', 'person') ->leftJoin('acppart.person', 'person')
->andWhere('acp.step != :count_acp_step') ->andWhere('acp.step != :count_acp_step')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT);
if ($this->filterStatsByCenters) {
$qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person 'SELECT 1 FROM '.PersonCenterHistory::class.' acl_count_person_history WHERE acl_count_person_history.person = person
@ -130,8 +142,8 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
' '
) )
) )
->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT)
->setParameter('authorized_centers', $centers); ->setParameter('authorized_centers', $centers);
}
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);

View File

@ -14,6 +14,7 @@ namespace Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\CountAccompanyingCourse; use Chill\PersonBundle\Export\Export\CountAccompanyingCourse;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -22,18 +23,17 @@ use Chill\PersonBundle\Export\Export\CountAccompanyingCourse;
*/ */
final class CountAccompanyingCourseTest extends AbstractExportTest final class CountAccompanyingCourseTest extends AbstractExportTest
{ {
private CountAccompanyingCourse $export;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get('chill.person.export.count_accompanyingcourse');
} }
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new CountAccompanyingCourse($em, $this->getParameters(true));
yield new CountAccompanyingCourse($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -14,6 +14,7 @@ namespace Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\CountAccompanyingPeriodWork; use Chill\PersonBundle\Export\Export\CountAccompanyingPeriodWork;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -33,7 +34,10 @@ final class CountAccompanyingPeriodWorkTest extends AbstractExportTest
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
yield new CountAccompanyingPeriodWork($em, $this->getParameters(true));
yield new CountAccompanyingPeriodWork($em, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\CountPerson; use Chill\PersonBundle\Export\Export\CountPerson;
use Chill\PersonBundle\Repository\PersonRepository;
/** /**
* Test CountPerson export. * Test CountPerson export.
@ -23,18 +24,17 @@ use Chill\PersonBundle\Export\Export\CountPerson;
*/ */
final class CountPersonTest extends AbstractExportTest final class CountPersonTest extends AbstractExportTest
{ {
private ?object $export = null;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->export = self::$container->get(CountPerson::class);
} }
public function getExport() public function getExport()
{ {
return $this->export; $personRepository = self::$container->get(PersonRepository::class);
yield new CountPerson($personRepository, $this->getParameters(true));
yield new CountPerson($personRepository, $this->getParameters(false));
} }
public function getFormData() public function getFormData()

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\CountPersonWithAccompanyingCourse;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class CountPersonWithAccompanyingCourseTest extends AbstractExportTest
{
protected function setUp(): void
{
self::bootKernel();
}
public function getExport()
{
$em = self::$container->get(EntityManagerInterface::class);
yield new CountPersonWithAccompanyingCourse($em, $this->getParameters(true));
yield new CountPersonWithAccompanyingCourse($em, $this->getParameters(false));
}
public function getFormData()
{
return [[]];
}
public function getModifiersCombination()
{
return [[Declarations::ACP_TYPE]];
}
}

View File

@ -11,43 +11,51 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export; namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListAccompanyingPeriod; use Chill\PersonBundle\Export\Export\ListAccompanyingPeriod;
use Doctrine\ORM\AbstractQuery; use Chill\PersonBundle\Export\Helper\ListAccompanyingPeriodHelper;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
* *
* @coversNothing * @coversNothing
*/ */
class ListAccompanyingPeriodTest extends KernelTestCase class ListAccompanyingPeriodTest extends AbstractExportTest
{ {
private ListAccompanyingPeriod $listAccompanyingPeriod; private readonly ListAccompanyingPeriod $listAccompanyingPeriod;
private CenterRepositoryInterface $centerRepository; private readonly CenterRepositoryInterface $centerRepository;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
self::bootKernel(); self::bootKernel();
$this->listAccompanyingPeriod = self::$container->get(ListAccompanyingPeriod::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
} }
public function testQuery(): void public function getExport()
{ {
$centers = $this->centerRepository->findAll(); $em = self::$container->get(EntityManagerInterface::class);
$rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
$listAccompanyingPeriodHelper = self::$container->get(ListAccompanyingPeriodHelper::class);
$query = $this->listAccompanyingPeriod->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), $exportOpts = ['calc_date' => new RollingDate(RollingDate::T_TODAY)]); yield new ListAccompanyingPeriod($em, $rollingDateConverter, $listAccompanyingPeriodHelper, $this->getParameters(true));
yield new ListAccompanyingPeriod($em, $rollingDateConverter, $listAccompanyingPeriodHelper, $this->getParameters(false));
}
$query->setMaxResults(1); public function getFormData()
{
return [
['calc_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
$actual = $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY); public function getModifiersCombination()
{
self::assertIsArray($actual); return [[Declarations::ACP_TYPE]];
} }
} }

View File

@ -11,40 +11,93 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export; namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Export\Helper\AggregateStringHelper;
use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Export\Helper\DateTimeHelper;
use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
use Chill\MainBundle\Export\Helper\UserHelper;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListAccompanyingPeriodWork; use Chill\PersonBundle\Export\Export\ListAccompanyingPeriodWork;
use Doctrine\ORM\AbstractQuery; use Chill\PersonBundle\Export\Helper\LabelPersonHelper;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Chill\ThirdPartyBundle\Export\Helper\LabelThirdPartyHelper;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
* *
* @coversNothing * @coversNothing
*/ */
class ListAccompanyingPeriodWorkTest extends KernelTestCase class ListAccompanyingPeriodWorkTest extends AbstractExportTest
{ {
private ListAccompanyingPeriodWork $listAccompanyingPeriodWork;
private CenterRepositoryInterface $centerRepository;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
self::bootKernel(); self::bootKernel();
$this->listAccompanyingPeriodWork = self::$container->get(ListAccompanyingPeriodWork::class);
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
} }
public function testQuery(): void public function getExport()
{ {
$centers = $this->centerRepository->findAll(); $entityManager = self::$container->get(EntityManagerInterface::class);
$dateTimeHelper = self::$container->get(DateTimeHelper::class);
$userHelper = self::$container->get(UserHelper::class);
$personHelper = self::$container->get(LabelPersonHelper::class);
$thirdPartyHelper = self::$container->get(LabelThirdPartyHelper::class);
$translatableStringExportLabelHelper = self::$container->get(TranslatableStringExportLabelHelper::class);
$socialIssueRender = self::$container->get(SocialIssueRender::class);
$socialIssueRepository = self::$container->get(SocialIssueRepository::class);
$socialActionRender = self::$container->get(SocialActionRender::class);
$rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
$aggregateStringHelper = self::$container->get(AggregateStringHelper::class);
$socialActionRepository = self::$container->get(SocialActionRepository::class);
$query = $this->listAccompanyingPeriodWork->initiateQuery([], array_map(fn (Center $c) => ['center' => $c], $centers), ['calc_date' => new RollingDate(RollingDate::T_TODAY)]); yield new ListAccompanyingPeriodWork(
$query->setMaxResults(1); $entityManager,
$dateTimeHelper,
$userHelper,
$personHelper,
$thirdPartyHelper,
$translatableStringExportLabelHelper,
$socialIssueRender,
$socialIssueRepository,
$socialActionRender,
$rollingDateConverter,
$aggregateStringHelper,
$socialActionRepository,
$this->getParameters(true),
);
self::assertIsArray($query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY)); yield new ListAccompanyingPeriodWork(
$entityManager,
$dateTimeHelper,
$userHelper,
$personHelper,
$thirdPartyHelper,
$translatableStringExportLabelHelper,
$socialIssueRender,
$socialIssueRepository,
$socialActionRender,
$rollingDateConverter,
$aggregateStringHelper,
$socialActionRepository,
$this->getParameters(false),
);
}
public function getFormData()
{
return [
['calc_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
public function getModifiersCombination()
{
return [[Declarations::ACP_TYPE]];
} }
} }

View File

@ -12,18 +12,30 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export; namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
use Chill\MainBundle\Export\Helper\DateTimeHelper;
use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
use Chill\MainBundle\Export\Helper\UserHelper;
use Chill\MainBundle\Repository\CenterRepositoryInterface; use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListEvaluation; use Chill\PersonBundle\Export\Export\ListEvaluation;
use Chill\PersonBundle\Export\Helper\LabelPersonHelper;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\AbstractQuery;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
* *
* @coversNothing * @coversNothing
*/ */
class ListEvaluationTest extends KernelTestCase class ListEvaluationTest extends AbstractExportTest
{ {
private ListEvaluation $listEvaluation; private ListEvaluation $listEvaluation;
@ -38,6 +50,61 @@ class ListEvaluationTest extends KernelTestCase
$this->centerRepository = self::$container->get(CenterRepositoryInterface::class); $this->centerRepository = self::$container->get(CenterRepositoryInterface::class);
} }
public function getExport()
{
$entityManager = self::$container->get(EntityManagerInterface::class);
$dateTimeHelper = self::$container->get(DateTimeHelper::class);
$userHelper = self::$container->get(UserHelper::class);
$personHelper = self::$container->get(LabelPersonHelper::class);
$translatableStringExportLabelHelper = self::$container->get(TranslatableStringExportLabelHelper::class);
$socialIssueRender = self::$container->get(SocialIssueRender::class);
$socialIssueRepository = self::$container->get(SocialIssueRepository::class);
$socialActionRender = self::$container->get(SocialActionRender::class);
$rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
$aggregateStringHelper = self::$container->get(AggregateStringHelper::class);
$socialActionRepository = self::$container->get(SocialActionRepository::class);
yield new ListEvaluation(
$entityManager,
$socialIssueRender,
$socialIssueRepository,
$socialActionRender,
$socialActionRepository,
$userHelper,
$personHelper,
$dateTimeHelper,
$translatableStringExportLabelHelper,
$aggregateStringHelper,
$rollingDateConverter,
$this->getParameters(true),
);
yield new ListEvaluation(
$entityManager,
$socialIssueRender,
$socialIssueRepository,
$socialActionRender,
$socialActionRepository,
$userHelper,
$personHelper,
$dateTimeHelper,
$translatableStringExportLabelHelper,
$aggregateStringHelper,
$rollingDateConverter,
$this->getParameters(false),
);
}
public function getFormData()
{
return [['calc_date' => new RollingDate(RollingDate::T_TODAY)]];
}
public function getModifiersCombination()
{
return [[Declarations::ACP_TYPE]];
}
public function testQuery(): void public function testQuery(): void
{ {
$centers = $this->centerRepository->findAll(); $centers = $this->centerRepository->findAll();

View File

@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Export\Helper\AggregateStringHelper;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListHouseholdInPeriod;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ListHouseholdInPeriodTest extends AbstractExportTest
{
protected function setUp(): void
{
self::bootKernel();
}
public function getExport()
{
$addressHelper = self::$container->get(ExportAddressHelper::class);
$aggregateStringHelper = self::$container->get(AggregateStringHelper::class);
$entityManager = self::$container->get(EntityManagerInterface::class);
$rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringExportLabelHelper::class);
yield new ListHouseholdInPeriod(
$addressHelper,
$aggregateStringHelper,
$entityManager,
$rollingDateConverter,
$translatableStringHelper,
$this->getParameters(true),
);
yield new ListHouseholdInPeriod(
$addressHelper,
$aggregateStringHelper,
$entityManager,
$rollingDateConverter,
$translatableStringHelper,
$this->getParameters(false),
);
}
public function getFormData()
{
return [['calc_date' => new RollingDate(RollingDate::T_TODAY)]];
}
public function getModifiersCombination()
{
return [[Declarations::PERSON_TYPE]];
}
}

View File

@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListPersonHavingAccompanyingPeriod;
use Chill\PersonBundle\Export\Helper\ListPersonHelper;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ListPersonHavingAccompanyingPeriodTest extends AbstractExportTest
{
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
}
public function getExport()
{
$addressHelper = self::$container->get(ExportAddressHelper::class);
$listPersonHelper = self::$container->get(ListPersonHelper::class);
$entityManager = self::$container->get(EntityManagerInterface::class);
$rollingDateconverter = self::$container->get(RollingDateConverterInterface::class);
yield new ListPersonHavingAccompanyingPeriod(
$addressHelper,
$listPersonHelper,
$entityManager,
$rollingDateconverter,
$this->getParameters(true),
);
yield new ListPersonHavingAccompanyingPeriod(
$addressHelper,
$listPersonHelper,
$entityManager,
$rollingDateconverter,
$this->getParameters(false),
);
}
public function getFormData()
{
return [['address_date_rolling' => new RollingDate(RollingDate::T_TODAY), 'fields' => ListPersonHelper::FIELDS]];
}
public function getModifiersCombination()
{
return [[Declarations::PERSON_TYPE, Declarations::ACP_TYPE]];
}
}

View File

@ -11,8 +11,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Export\Export; namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\MainBundle\Export\Helper\ExportAddressHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Export\ListPerson; use Chill\PersonBundle\Export\Export\ListPerson;
use Chill\PersonBundle\Export\Helper\ListPersonHelper;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
/** /**
@ -45,7 +50,29 @@ final class ListPersonTest extends AbstractExportTest
public function getExport() public function getExport()
{ {
return $this->export; $addressHelper = self::$container->get(ExportAddressHelper::class);
$customFieldProvider = self::$container->get(CustomFieldProvider::class);
$listPersonHelper = self::$container->get(ListPersonHelper::class);
$entityManager = self::$container->get(EntityManagerInterface::class);
$translatableStringHelper = self::$container->get(TranslatableStringHelper::class);
yield new ListPerson(
$addressHelper,
$customFieldProvider,
$listPersonHelper,
$entityManager,
$translatableStringHelper,
$this->getParameters(true),
);
yield new ListPerson(
$addressHelper,
$customFieldProvider,
$listPersonHelper,
$entityManager,
$translatableStringHelper,
$this->getParameters(false),
);
} }
public function getFormData(): iterable public function getFormData(): iterable

View File

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Export;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\ListPersonWithAccompanyingPeriodDetails;
use Chill\PersonBundle\Export\Helper\ListAccompanyingPeriodHelper;
use Chill\PersonBundle\Export\Helper\ListPersonHelper;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ListPersonWithAccompanyingPeriodDetailsTest extends AbstractExportTest
{
protected function setUp(): void
{
parent::setUp();
self::bootKernel();
}
public function getExport()
{
$listPersonHelper = self::$container->get(ListPersonHelper::class);
$listAccompanyingPeriodHelper = self::$container->get(ListAccompanyingPeriodHelper::class);
$entityManager = self::$container->get(EntityManagerInterface::class);
$rollingDateConverter = self::$container->get(RollingDateConverterInterface::class);
yield new ListPersonWithAccompanyingPeriodDetails(
$listPersonHelper,
$listAccompanyingPeriodHelper,
$entityManager,
$rollingDateConverter,
$this->getParameters(true),
);
yield new ListPersonWithAccompanyingPeriodDetails(
$listPersonHelper,
$listAccompanyingPeriodHelper,
$entityManager,
$rollingDateConverter,
$this->getParameters(false),
);
}
public function getFormData()
{
return [
['address_date' => new RollingDate(RollingDate::T_TODAY)],
];
}
public function getModifiersCombination()
{
return [
[Declarations::PERSON_TYPE, Declarations::ACP_TYPE],
];
}
}

View File

@ -11,9 +11,12 @@ declare(strict_types=1);
namespace Export\Export; namespace Export\Export;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Test\Export\AbstractExportTest; use Chill\MainBundle\Test\Export\AbstractExportTest;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration; use Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration;
use Doctrine\ORM\EntityManagerInterface;
/** /**
* @internal * @internal
@ -33,13 +36,17 @@ final class StatAccompanyingCourseDurationTest extends AbstractExportTest
public function getExport() public function getExport()
{ {
return $this->export; $em = self::$container->get(EntityManagerInterface::class);
$rollingDateconverter = self::$container->get(RollingDateConverterInterface::class);
yield new StatAccompanyingCourseDuration($em, $rollingDateconverter, $this->getParameters(true));
yield new StatAccompanyingCourseDuration($em, $rollingDateconverter, $this->getParameters(false));
} }
public function getFormData(): array public function getFormData(): array
{ {
return [ return [
['closingdate' => \DateTime::createFromFormat('Y-m-d', '2022-06-30')], ['closingdate_rolling' => new RollingDate(RollingDate::T_TODAY)],
]; ];
} }