From 6cdb3033dbba36887b2524677d354602cb80352c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 23 Sep 2022 21:51:26 +0200 Subject: [PATCH 1/9] [export][person] Fixed: filter per person's age: use calculatio non year interval --- .../Export/Filter/PersonFilters/AgeFilter.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php index bada59a8d..eb83f3ff0 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php @@ -34,17 +34,20 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface $where = $qb->getDQLPart('where'); $min = null !== $data['min_age'] ? $data['min_age'] : 0; - $max = null !== $data['max_age'] ? $data['max_age'] : 200; + $max = null !== $data['max_age'] ? $data['max_age'] : 3000; $calc = $data['date_calc']; + $minDate = $calc->sub(new \DateInterval('P' . $max . 'Y')); + $maxDate = $calc->sub(new \DateInterval('P' . $min . 'Y')); + $clause = $qb->expr()->andX( $qb->expr()->gte( - 'DATE_DIFF(:calc_date, person.birthdate)/365', - ':min_age' + 'person.birthdate', + ':min_date' ), $qb->expr()->lte( - 'DATE_DIFF(:calc_date, person.birthdate)/365', - ':max_age' + 'person.birthdate', + ':max_date' ) ); @@ -55,9 +58,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface } $qb->add('where', $where); - $qb->setParameter('min_age', $min); - $qb->setParameter('max_age', $max); - $qb->setParameter('calc_date', $calc); + $qb->setParameter('min_date', $minDate); + $qb->setParameter('max_date', $maxDate); } public function applyOn() @@ -77,7 +79,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface $builder->add('date_calc', ChillDateType::class, [ 'label' => 'Calculate age in relation to this date', - 'data' => new DateTime('now'), + 'data' => new \DateTimeImmutable('now'), + 'input' => 'datetime_immutable' ]); } From 75713af0e08e178576ca28d00a11a5244627ce3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 23 Sep 2022 21:55:00 +0200 Subject: [PATCH 2/9] [export][person] fix alias name for person in CountPersonWithAccompanyingCourse export --- .../Export/Export/CountPersonWithAccompanyingCourse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php index 51d85c479..057611032 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php @@ -95,10 +95,10 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor } if (!in_array('partperson', $qb->getAllAliases(), true)) { - $qb->join('acppart.person', 'partperson'); + $qb->join('acppart.person', 'person'); } - $qb->select('COUNT(DISTINCT partperson.id) AS export_result'); + $qb->select('COUNT(DISTINCT person.id) AS export_result'); return $qb; } From 6eff1962df4e8ed40f8f94d3a54b9d2c43d1dc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 Sep 2022 14:43:04 +0200 Subject: [PATCH 3/9] Fix import and add a "not null" condition on duration time --- .../Export/LinkedToACP/AvgActivityDuration.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php index 5dae4c0ef..3fc975147 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php @@ -17,6 +17,7 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; +use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; @@ -34,7 +35,6 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface public function buildForm(FormBuilderInterface $builder) { - // TODO: Implement buildForm() method. } public function getAllowedFormattersTypes(): array @@ -55,7 +55,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface public function getLabels($key, array $values, $data) { if ('export_avg_activity_duration' !== $key) { - throw new LogicException("the key {$key} is not used by this export"); + throw new \LogicException("the key {$key} is not used by this export"); } return static fn ($value) => '_header' === $value ? 'Average activities linked to an accompanying period duration' : $value; @@ -83,10 +83,12 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { - $qb = $this->repository->createQueryBuilder('activity') - ->join('activity.accompanyingPeriod', 'acp'); + $qb = $this->repository->createQueryBuilder('activity'); - $qb->select('AVG(activity.durationTime) as export_avg_activity_duration'); + $qb + ->join('activity.accompanyingPeriod', 'acp') + ->select('AVG(activity.durationTime) as export_avg_activity_duration') + ->andWhere($qb->expr()->isNotNull('activity.durationTime')); return $qb; } From 58eb089d1caf5b04a9b30edaf9ce93de5a8632f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 Sep 2022 14:49:51 +0200 Subject: [PATCH 4/9] Fix use import and add a "not null" condition on travel time --- .../Export/LinkedToACP/AvgActivityVisitDuration.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php index 560ae8754..69533a09d 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php @@ -17,6 +17,7 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; +use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; @@ -55,7 +56,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac public function getLabels($key, array $values, $data) { if ('export_avg_activity_visit_duration' !== $key) { - throw new LogicException("the key {$key} is not used by this export"); + throw new \LogicException("the key {$key} is not used by this export"); } return static fn ($value) => '_header' === $value ? 'Average activities linked to an accompanying period visit duration' : $value; @@ -83,10 +84,13 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac public function initiateQuery(array $requiredModifiers, array $acl, array $data = []) { - $qb = $this->repository->createQueryBuilder('activity') - ->join('activity.accompanyingPeriod', 'acp'); + $qb = $this->repository->createQueryBuilder('activity'); - $qb->select('AVG(activity.travelTime) as export_avg_activity_visit_duration'); + $qb + ->join('activity.accompanyingPeriod', 'acp') + ->select('AVG(activity.travelTime) as export_avg_activity_visit_duration') + ->andWhere($qb->expr()->isNotNull('activity.travelTime')) + ; return $qb; } From 2c46886e36d41e4d0f71b8a672af3015467572ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 Sep 2022 14:59:31 +0200 Subject: [PATCH 5/9] Fix use import and add a "not null" condition on travel time --- .../Export/Export/LinkedToACP/SumActivityDuration.php | 6 ++++-- .../Export/Export/LinkedToACP/SumActivityVisitDuration.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php index 5c85046ae..e9dbaff29 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php @@ -17,6 +17,7 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; +use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; @@ -55,7 +56,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface public function getLabels($key, array $values, $data) { if ('export_sum_activity_duration' !== $key) { - throw new LogicException("the key {$key} is not used by this export"); + throw new \LogicException("the key {$key} is not used by this export"); } return static fn ($value) => '_header' === $value ? 'Sum activities linked to an accompanying period duration' : $value; @@ -89,7 +90,8 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface $qb->join('activity.accompanyingPeriod', 'acp'); } - $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')); return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php index af1a0c30a..d41994562 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php @@ -17,6 +17,7 @@ use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; +use Chill\PersonBundle\Export\Declarations as PersonDeclarations; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query; @@ -55,7 +56,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac public function getLabels($key, array $values, $data) { if ('export_sum_activity_visit_duration' !== $key) { - throw new LogicException("the key {$key} is not used by this export"); + throw new \LogicException("the key {$key} is not used by this export"); } return static fn ($value) => '_header' === $value ? 'Sum activities linked to an accompanying period visit duration' : $value; @@ -89,7 +90,8 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac $qb->join('activity.accompanyingPeriod', 'acp'); } - $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')); return $qb; } From 95f7622923fc6f19ca3ce442d3b5e78dead66b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 Sep 2022 16:45:36 +0200 Subject: [PATCH 6/9] [Export][person] Fixed: error and more precision on household composition A filter and two aggregators create a join between composition and household, but with a parameter at different date. Each aggregator and filter now have a custom alias, to allow to set this date parameter on each join. --- .../ChillMainBundle/Export/ExportManager.php | 4 +- .../ChildrenNumberAggregator.php | 56 +++++++------------ .../CompositionAggregator.php | 49 +++++++--------- .../Export/Export/CountHousehold.php | 3 +- .../HouseholdFilters/CompositionFilter.php | 37 +++++------- 5 files changed, 57 insertions(+), 92 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Export/ExportManager.php b/src/Bundle/ChillMainBundle/Export/ExportManager.php index df14a8ac8..ba15d0cc0 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportManager.php +++ b/src/Bundle/ChillMainBundle/Export/ExportManager.php @@ -536,8 +536,8 @@ class ExportManager . 'an ExportInterface.'); } - if (null === $centers || [] === $centers) { - // we want to try if at least one center is reachable + if (null === $centers || [] !== $centers) { + // we want to try if at least one center is reachabler return [] !== $this->authorizationHelper->getReachableCenters( $this->user, $role diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php index 240da475e..2343b2bab 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Export\Declarations; use DateTime; use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -39,39 +40,23 @@ class ChildrenNumberAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('composition', $qb->getAllAliases(), true)) { - $qb->join('household.compositions', 'composition'); + if (!in_array('composition_children', $qb->getAllAliases(), true)) { + $clause = $qb->expr()->andX( + $qb->expr()->lte('composition_children.startDate', ':ondate_composition_children'), + $qb->expr()->orX( + $qb->expr()->gt('composition_children.endDate', ':ondate_composition_children'), + $qb->expr()->isNull('composition_children.endDate') + ) + ); + + $qb->leftJoin('household.compositions', 'composition_children', Expr\Join::WITH, $clause); } - $qb->addSelect('composition.numberOfChildren AS childrennumber_aggregator'); + $qb + ->addSelect('composition_children.numberOfChildren AS childrennumber_aggregator') + ->addGroupBy('childrennumber_aggregator'); - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('childrennumber_aggregator'); - } else { - $qb->groupBy('childrennumber_aggregator'); - } - - // add date in where clause - $where = $qb->getDQLPart('where'); - - $clause = $qb->expr()->andX( - $qb->expr()->lte('composition.startDate', ':ondate'), - $qb->expr()->orX( - $qb->expr()->gt('composition.endDate', ':ondate'), - $qb->expr()->isNull('composition.endDate') - ) - ); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); - $qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_children', $data['on_date'], Types::DATE_MUTABLE); } public function applyOn(): string @@ -93,12 +78,11 @@ class ChildrenNumberAggregator implements AggregatorInterface return 'Number of children'; } - return $this->translator->trans( - 'household_composition.numberOfChildren children in household', - [ - 'numberOfChildren' => $value, - ] - ); + if (null === $value) { + return ''; + } + + return $value; }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php index fdb18e951..7e10ea429 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php @@ -18,6 +18,7 @@ use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository; use DateTime; use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -44,39 +45,23 @@ class CompositionAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('composition', $qb->getAllAliases(), true)) { - $qb->join('household.compositions', 'composition'); + if (!in_array('composition_type', $qb->getAllAliases(), true)) { + $clause = $qb->expr()->andX( + $qb->expr()->lte('composition_type.startDate', ':ondate_composition_type'), + $qb->expr()->orX( + $qb->expr()->gt('composition_type.endDate', ':ondate_composition_type'), + $qb->expr()->isNull('composition_type.endDate') + ) + ); + + $qb->leftJoin('household.compositions', 'composition_type', Expr\Join::WITH, $clause); } - $qb->addSelect('IDENTITY(composition.householdCompositionType) AS composition_aggregator'); + $qb + ->addSelect('IDENTITY(composition_type.householdCompositionType) AS composition_aggregator') + ->addGroupBy('composition_aggregator'); - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('composition_aggregator'); - } else { - $qb->groupBy('composition_aggregator'); - } - - // add date in where clause - $where = $qb->getDQLPart('where'); - - $clause = $qb->expr()->andX( - $qb->expr()->lte('composition.startDate', ':ondate'), - $qb->expr()->orX( - $qb->expr()->gt('composition.endDate', ':ondate'), - $qb->expr()->isNull('composition.endDate') - ) - ); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); - $qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_type', $data['on_date'], Types::DATE_MUTABLE); } public function applyOn(): string @@ -98,6 +83,10 @@ class CompositionAggregator implements AggregatorInterface return 'Composition'; } + if (null === $value) { + return ''; + } + $c = $this->typeRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php index 18ddbaea1..106084e4f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php @@ -106,8 +106,7 @@ class CountHousehold implements ExportInterface, GroupedExportInterface $qb->join('member.household', 'household'); } - - $qb->select('COUNT(DISTINCT member.household) AS export_result'); + $qb->select('COUNT(DISTINCT household.id) AS export_result'); return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php index 3d00ed36b..1ca78d669 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php @@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdCompositionType; use Chill\PersonBundle\Export\Declarations; use DateTime; use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -41,32 +42,24 @@ class CompositionFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('composition', $qb->getAllAliases(), true)) { - $qb->join('household.compositions', 'composition'); + if (!in_array('composition_type_filter', $qb->getAllAliases(), true)) { + $clause = + $qb->expr()->andX( + $qb->expr()->lte('composition_type_filter.startDate', ':ondate_composition_type_filter'), + $qb->expr()->orX( + $qb->expr()->gt('composition_type_filter.endDate', ':ondate_composition_type_filter'), + $qb->expr()->isNull('composition_type_filter.endDate') + ) + ); + + $qb->join('household.compositions', 'composition', Expr\Join::WITH, $clause); } - $where = $qb->getDQLPart('where'); + $whereClause = $qb->expr()->in('composition_type_filter.householdCompositionType', ':compositions'); - $clause = $qb->expr()->andX( - $qb->expr()->in('composition.householdCompositionType', ':compositions'), - $qb->expr()->andX( - $qb->expr()->lte('composition.startDate', ':ondate'), - $qb->expr()->orX( - $qb->expr()->gt('composition.endDate', ':ondate'), - $qb->expr()->isNull('composition.endDate') - ) - ) - ); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); + $qb->andWhere($whereClause); $qb->setParameter('compositions', $data['accepted_composition']); - $qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_type_filter', $data['on_date'], Types::DATE_MUTABLE); } public function applyOn(): string From e3764f6f91c85114f3bd70518f7480ccc6bd6d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 26 Sep 2022 17:02:28 +0200 Subject: [PATCH 7/9] [export][person] Fixed: use left join on association between works and goal/results --- .../ActionTypeAggregator.php | 2 +- .../GoalResultAggregator.php | 21 +++++++------------ .../ResultAggregator.php | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php index 37d50bf51..fc96b9e6b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php @@ -40,7 +40,7 @@ final class ActionTypeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpwsocialaction', $qb->getAllAliases(), true)) { - $qb->join('acpw.socialAction', 'acpwsocialaction'); + $qb->leftJoin('acpw.socialAction', 'acpwsocialaction'); } $qb->addSelect('acpwsocialaction.id as action_type_aggregator'); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php index aeced53d7..48075c38b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php @@ -35,6 +35,10 @@ class GoalResultAggregator implements AggregatorInterface public function getLabels($key, array $values, $data) { return function ($value) use ($key): string { + if (null === $value) { + return ''; + } + switch ($key) { case 'goal_aggregator': @@ -107,25 +111,16 @@ class GoalResultAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('goal', $qb->getAllAliases(), true)) { - $qb->join('acpw.goals', 'goal'); + $qb->leftJoin('acpw.goals', 'goal'); } if (!in_array('goalresult', $qb->getAllAliases(), true)) { - $qb->join('goal.results', 'goalresult'); + $qb->leftJoin('goal.results', 'goalresult'); } $qb->addSelect('IDENTITY(goal.goal) as goal_aggregator'); $qb->addSelect('goalresult.id as result_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('goal_aggregator'); - } else { - $qb->groupBy('goal_aggregator'); - } - - $qb->addGroupBy('result_aggregator'); + $qb->addGroupBy('goal_aggregator')->addGroupBy('result_aggregator'); } /** @@ -135,4 +130,4 @@ class GoalResultAggregator implements AggregatorInterface { return Declarations::SOCIAL_WORK_ACTION_TYPE; } -} \ No newline at end of file +} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php index 054b0ab55..4b190e0a5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php @@ -38,7 +38,7 @@ final class ResultAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('result', $qb->getAllAliases(), true)) { - $qb->join('acpw.results', 'result'); + $qb->leftJoin('acpw.results', 'result'); } $qb->addSelect('result.id AS acpw_result_aggregator'); From 78e00b8eba9036c6d46c7359ad2dad09a4ba9ad6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 26 Sep 2022 17:40:58 +0200 Subject: [PATCH 8/9] exports: improve translations --- src/Bundle/ChillPersonBundle/translations/messages.fr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 557a6a24b..c94b4963d 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -339,8 +339,8 @@ Fields to include in export: Champs à inclure dans l'export Address valid at this date: Addresse valide à cette date List duplicates: Liste des doublons Create a list of duplicate people: Créer la liste des personnes détectées comme doublons. -Count people participating in an accompanying course by various parameters.: Nombre de personnes concernées par un parcours -Count people participating in an accompanying course: Nombre de personnes concernés par un parcours +Count people participating in an accompanying course: Nombre de personnes concernées par un parcours +Count people participating in an accompanying course by various parameters.: Compte le nombre de personnes concernées par un parcours Exports of accompanying courses: Exports des parcours d'accompagnement Count accompanying courses: Nombre de parcours From 9f2ecff63ed811983a438a2de4c0265dffaf715c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 26 Sep 2022 18:52:00 +0200 Subject: [PATCH 9/9] exports: ResidentialAddressAt ThirdParty/User Filter, improve query (issue637 et issue638) --- .../ResidentialAddressAtThirdpartyFilter.php | 11 +++++++++-- .../ResidentialAddressAtUserFilter.php | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php index c96fd680f..2770ae82f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php @@ -56,10 +56,17 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface } $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->andX( $qb->expr()->isNotNull('resaddr.hostThirdParty'), - $qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'), - $qb->expr()->in('tpartycat.id', ':type') + $qb->expr()->in('tpartycat.id', ':type'), + $qb->expr()->orX( + $qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'), + $qb->expr()->andX( + $qb->expr()->lte('resaddr.startDate', ':date'), + $qb->expr()->isNull('resaddr.endDate') + ) + ) ); if ($where instanceof Expr\Andx) { diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php index 482312143..7c07121e1 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\Query\Expr; @@ -36,7 +37,17 @@ class ResidentialAddressAtUserFilter implements FilterInterface } $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->isNotNull('resaddr.hostPerson'); + + $clause = $qb->expr()->andX( + $qb->expr()->isNotNull('resaddr.hostPerson'), + $qb->expr()->orX( + $qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'), + $qb->expr()->andX( + $qb->expr()->lte('resaddr.startDate', ':date'), + $qb->expr()->isNull('resaddr.endDate') + ) + ) + ); if ($where instanceof Andx) { $where->add($clause); @@ -44,6 +55,7 @@ class ResidentialAddressAtUserFilter implements FilterInterface $where = $qb->expr()->andX($clause); } + $qb->setParameter('date', $data['date_calc']); $qb->add('where', $where); } @@ -54,7 +66,10 @@ class ResidentialAddressAtUserFilter implements FilterInterface public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) { - // No form needed unless validity date should be added ( not specified in doc as a parameter ). + $builder->add('date_calc', ChillDateType::class, [ + 'label' => 'Date during which residential address was valid', + 'data' => new \DateTime('now'), + ]); } public function describeAction($data, $format = 'string')