Merge branch '111_exports_suite' into testing

This commit is contained in:
Julien Fastré 2022-09-28 09:49:33 +02:00
commit 1786fa838f
15 changed files with 118 additions and 126 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
};
}

View File

@ -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(

View File

@ -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');

View File

@ -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;
}
}
}

View File

@ -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');

View File

@ -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;
}

View File

@ -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

View File

@ -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) {

View File

@ -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')

View File

@ -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