From c401e34d63a93274adfab7fd69c5a83e456ae128 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 11:16:17 +0200 Subject: [PATCH] exports: add new ActiveOneDayBetweenDates filter --- .../Filter/ActiveOneDayBetweenDatesFilter.php | 93 +++++++++++++++++++ .../Export/Filter/OpenBetweenDatesFilter.php | 3 +- .../services/exports_accompanying_period.yaml | 9 +- .../translations/messages.fr.yml | 3 +- 4 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/ActiveOneDayBetweenDatesFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ActiveOneDayBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ActiveOneDayBetweenDatesFilter.php new file mode 100644 index 000000000..6f6ef1197 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ActiveOneDayBetweenDatesFilter.php @@ -0,0 +1,93 @@ +add('date_from', ChillDateType::class, [ + 'data' => new DateTime(), + ]) + ->add('date_to', ChillDateType::class, [ + 'data' => new DateTime(), + ]) + ; + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filtered by active at least one day between dates'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string') + { + return ['Filtered by actives courses: at least one day between %datefrom% and %dateto%', [ + '%datefrom%' => $data['date_from']->format('d-m-Y'), + '%dateto%' => $data['date_to']->format('d-m-Y'), + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->orX( + $qb->expr()->lt('(acp.openingDate + 1)', ':dateto'), + $qb->expr()->andX( + $qb->expr()->lt('acp.openingDate', ':datefrom'), + $qb->expr()->isNull('acp.closingDate') + ), + $qb->expr()->gt('(acp.closingDate - 1)', ':datefrom') + ); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('datefrom', $data['date_from'], Types::DATE_MUTABLE); + $qb->setParameter('dateto', $data['date_to'], Types::DATE_MUTABLE); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/OpenBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/OpenBetweenDatesFilter.php index 2515f4e75..ef829bdfa 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/OpenBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/OpenBetweenDatesFilter.php @@ -2,6 +2,7 @@ namespace Chill\PersonBundle\Export\Filter; +use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Export\Declarations; use Doctrine\DBAL\Types\Types; @@ -10,7 +11,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use DateTime; -class OpenBetweenDatesFilter implements \Chill\MainBundle\Export\FilterInterface +class OpenBetweenDatesFilter implements FilterInterface { /** diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml index 1f98ffd39..20131dc59 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -95,6 +95,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_intensity_filter } + chill.person.export.filter_activeonedaybetweendates: + class: Chill\PersonBundle\Export\Filter\ActiveOneDayBetweenDatesFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_activeonedaybetweendates_filter } + chill.person.export.filter_referrer: class: Chill\PersonBundle\Export\Filter\ReferrerFilter autowire: true @@ -109,6 +116,4 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_openbetweendates_filter } - - ## Aggregators \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index f3e4be1c4..f047a6804 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -425,7 +425,8 @@ Date from: Date de début Date to: Date de fin "Filtered by opening dates: between %datefrom% and %dateto%": "Filtrer les parcours ouverts entre deux dates: entre le %datefrom% et le %dateto%" - +Filtered by active at least one day between dates: Filtrer les parcours actifs au moins un jour dans la période +"Filtered by actives courses: at least one day between %datefrom% and %dateto%": "Filtrer les parcours actifs: au moins un jour entre le %datefrom% et le %dateto%" ## aggregators Group people by nationality: Aggréger les personnes par nationalités