Merge branch '111_exports_suite' into 111_export_GeographicalUnit

This commit is contained in:
2022-10-03 12:00:15 +02:00
205 changed files with 7277 additions and 761 deletions

View File

@@ -25,23 +25,17 @@ class AbstractAccompanyingPeriodExportElement
*/
protected function addJoinAccompanyingPeriod(QueryBuilder $query): void
{
if (false === $this->havingAccompanyingPeriodInJoin($query)) {
if (false === in_array('person', $query->getAllAliases(), true)) {
throw new LogicException("the alias 'person' does not exists in "
. 'query builder');
}
if (false === in_array('person', $query->getAllAliases(), true)) {
throw new LogicException("the alias 'person' does not exists in "
. 'query builder');
}
$query->join('person.accompanyingPeriods', 'accompanying_period');
if (!in_array('acppart', $query->getAllAliases(), true)) {
$query->join('person.accompanyingPeriodParticipations', 'acppart');
}
if (!in_array('acp', $query->getAllAliases(), true)) {
$query->join('acppart.accompanyingPeriod', 'acp');
}
}
/**
* Return true if "accompanying_period" alias is present in the query alises.
*/
protected function havingAccompanyingPeriodInJoin(QueryBuilder $query): bool
{
$joins = $query->getDQLPart('join') ?? [];
return in_array('accompanying_period', $query->getAllAliases(), true);
}
}

View File

@@ -40,18 +40,11 @@ class AdministrativeLocationAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acploc', $qb->getAllAliases(), true)) {
$qb->join('acp.administrativeLocation', 'acploc');
$qb->leftJoin('acp.administrativeLocation', 'acploc');
}
$qb->addSelect('IDENTITY(acp.administrativeLocation) AS location_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('location_aggregator');
} else {
$qb->groupBy('location_aggregator');
}
$qb->addGroupBy('location_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ class AdministrativeLocationAggregator implements AggregatorInterface
return 'Administrative location';
}
if (null === $value) {
return '';
}
$l = $this->locationRepository->find($value);
return $l->getName() . ' (' . $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')';

View File

@@ -15,21 +15,23 @@ use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class ClosingMotiveAggregator implements AggregatorInterface
{
private EntityManagerInterface $em;
private ClosingMotiveRepositoryInterface $motiveRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
EntityManagerInterface $em,
ClosingMotiveRepositoryInterface $motiveRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->motiveRepository = $em->getRepository(ClosingMotive::class);
$this->motiveRepository = $motiveRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
@@ -40,19 +42,8 @@ class ClosingMotiveAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpmotive', $qb->getAllAliases(), true)) {
$qb->join('acp.closingMotive', 'acpmotive');
}
$qb->addSelect('IDENTITY(acp.closingMotive) AS closingmotive_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('closingmotive_aggregator');
} else {
$qb->groupBy('closingmotive_aggregator');
}
$qb->addGroupBy('closingmotive_aggregator');
}
public function applyOn(): string
@@ -72,6 +63,10 @@ class ClosingMotiveAggregator implements AggregatorInterface
return 'Closing motive';
}
if (NULL === $value) {
return '';
}
$cm = $this->motiveRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -35,14 +35,7 @@ class ConfidentialAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('acp.confidential AS confidential_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('confidential_aggregator');
} else {
$qb->groupBy('confidential_aggregator');
}
$qb->addGroupBy('confidential_aggregator');
}
public function applyOn(): string

View File

@@ -44,15 +44,8 @@ final class DurationAggregator implements AggregatorInterface
// et ajouter une fonction custom qui calcule plus précisément les intervals, comme doctrineum/date-interval
// https://packagist.org/packages/doctrineum/date-interval#3.1.0 (mais composer fait un conflit de dépendance)
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('duration_aggregator');
} else {
$qb->groupBy('duration_aggregator');
}
$qb->orderBy('duration_aggregator');
$qb->addGroupBy('duration_aggregator');
$qb->addOrderBy('duration_aggregator');
}
public function applyOn(): string

View File

@@ -35,14 +35,7 @@ class EmergencyAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('acp.emergency AS emergency_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('emergency_aggregator');
} else {
$qb->groupBy('emergency_aggregator');
}
$qb->addGroupBy('emergency_aggregator');
}
public function applyOn(): string

View File

@@ -41,22 +41,15 @@ final class EvaluationAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpw', $qb->getAllAliases(), true)) {
$qb->join('acp.works', 'acpw');
$qb->leftJoin('acp.works', 'acpw');
}
if (!in_array('workeval', $qb->getAllAliases(), true)) {
$qb->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval');
$qb->leftJoin('acpw.accompanyingPeriodWorkEvaluations', 'workeval');
}
$qb->addSelect('IDENTITY(workeval.evaluation) AS evaluation_aggregator');
$groupby = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('evaluation_aggregator');
} else {
$qb->groupBy('evaluation_aggregator');
}
$qb->addGroupBy('evaluation_aggregator');
}
public function applyOn(): string
@@ -76,6 +69,10 @@ final class EvaluationAggregator implements AggregatorInterface
return 'Evaluation';
}
if (null === $value) {
return '';
}
$e = $this->evaluationRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -35,14 +35,7 @@ class IntensityAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('acp.intensity AS intensity_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('intensity_aggregator');
} else {
$qb->groupBy('intensity_aggregator');
}
$qb->addGroupBy('intensity_aggregator');
}
public function applyOn(): string

View File

@@ -40,18 +40,11 @@ final class JobAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpjob', $qb->getAllAliases(), true)) {
$qb->join('acp.job', 'acpjob');
$qb->leftJoin('acp.job', 'acpjob');
}
$qb->addSelect('IDENTITY(acp.job) AS job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('job_aggregator');
}
$qb->addGroupBy('job_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class JobAggregator implements AggregatorInterface
return 'Job';
}
if (null === $value) {
return '';
}
$j = $this->jobRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -42,18 +42,11 @@ final class OriginAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acporigin', $qb->getAllAliases(), true)) {
$qb->join('acp.origin', 'acporigin');
$qb->leftJoin('acp.origin', 'acporigin');
}
$qb->addSelect('acporigin.id AS origin_aggregator');
$groupby = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('origin_aggregator');
} else {
$qb->groupBy('origin_aggregator');
}
$qb->addGroupBy('origin_aggregator');
}
public function applyOn(): string
@@ -73,6 +66,10 @@ final class OriginAggregator implements AggregatorInterface
return 'Origin';
}
if (null === $value) {
return '';
}
$o = $this->repository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -40,18 +40,11 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpuser', $qb->getAllAliases(), true)) {
$qb->join('acp.user', 'acpuser');
$qb->leftJoin('acp.user', 'acpuser');
}
$qb->addSelect('acpuser.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_aggregator');
} else {
$qb->groupBy('referrer_aggregator');
}
$qb->addGroupBy('referrer_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class ReferrerAggregator implements AggregatorInterface
return 'Referrer';
}
if (null === $value) {
return '';
}
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);

View File

@@ -57,15 +57,7 @@ final class RequestorAggregator implements AggregatorInterface
END ) AS requestor_aggregator
");
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('requestor_aggregator');
} else {
$qb->groupBy('requestor_aggregator');
}
// TODO 'order by' does not works !
$qb->addGroupBy('requestor_aggregator');
}
public function applyOn(): string

View File

@@ -40,18 +40,11 @@ final class ScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpscope', $qb->getAllAliases(), true)) {
$qb->join('acp.scopes', 'acpscope');
$qb->leftJoin('acp.scopes', 'acpscope');
}
$qb->addSelect('acpscope.id as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('scope_aggregator');
}
$qb->addGroupBy('scope_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class ScopeAggregator implements AggregatorInterface
return 'Scope';
}
if (null === $value) {
return '';
}
$s = $this->scopeRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -41,18 +41,12 @@ final class SocialActionAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpw', $qb->getAllAliases(), true)) {
// here, we will only see accompanying period linked with a socialAction
$qb->join('acp.works', 'acpw');
}
$qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator'); // DISTINCT ??
$groupby = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('socialaction_aggregator');
} else {
$qb->groupBy('socialaction_aggregator');
}
$qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator');
$qb->addGroupBy('socialaction_aggregator');
}
public function applyOn(): string
@@ -72,6 +66,10 @@ final class SocialActionAggregator implements AggregatorInterface
return 'Social action';
}
if (null === $value) {
return '';
}
$sa = $this->actionRepository->find($value);
return $this->actionRender->renderString($sa, []);

View File

@@ -40,18 +40,12 @@ final class SocialIssueAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpsocialissue', $qb->getAllAliases(), true)) {
// we will see accompanying period linked with social issues
$qb->join('acp.socialIssues', 'acpsocialissue');
}
$qb->addSelect('acpsocialissue.id as socialissue_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('socialissue_aggregator');
} else {
$qb->groupBy('socialissue_aggregator');
}
$qb->addGroupBy('socialissue_aggregator');
}
public function applyOn(): string

View File

@@ -41,15 +41,9 @@ final class StepAggregator implements AggregatorInterface //, FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('acp.step AS step_aggregator');
$qb->addGroupBy('step_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('step_aggregator');
} else {
$qb->groupBy('step_aggregator');
}
/*
// add date in where clause
$where = $qb->getDQLPart('where');
@@ -69,6 +63,7 @@ final class StepAggregator implements AggregatorInterface //, FilterInterface
$qb->add('where', $where);
$qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE);
*/
}
public function applyOn(): string

View File

@@ -39,15 +39,8 @@ class EvaluationTypeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('IDENTITY(eval.evaluation) AS evaluationtype_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('evaluationtype_aggregator');
} else {
$qb->groupBy('evaluationtype_aggregator');
}
$qb->addSelect('IDENTITY(workeval.evaluation) AS eval_evaluationtype_aggregator');
$qb->addGroupBy('eval_evaluationtype_aggregator');
}
public function applyOn(): string
@@ -67,6 +60,10 @@ class EvaluationTypeAggregator implements AggregatorInterface
return 'Evaluation type';
}
if (null === $value) {
return '';
}
$ev = $this->evaluationRepository->find($value);
return $this->translatableStringHelper->localize($ev->getTitle());
@@ -75,7 +72,7 @@ class EvaluationTypeAggregator implements AggregatorInterface
public function getQueryKeys($data): array
{
return ['evaluationtype_aggregator'];
return ['eval_evaluationtype_aggregator'];
}
public function getTitle(): string

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

@@ -62,6 +62,9 @@ final class GenderAggregator implements AggregatorInterface
case Person::BOTH_GENDER:
return $this->translator->trans('both');
case Person::NO_INFORMATION:
return $this->translator->trans('unknown');
case null:
return $this->translator->trans('Not given');

View File

@@ -59,6 +59,7 @@ final class MaritalStatusAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)

View File

@@ -40,18 +40,11 @@ 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');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('action_type_aggregator');
} else {
$qb->groupBy('action_type_aggregator');
}
$qb->addGroupBy('action_type_aggregator');
}
public function applyOn()
@@ -71,6 +64,10 @@ final class ActionTypeAggregator implements AggregatorInterface
return 'Social Action Type';
}
if (null === $value) {
return '';
}
$sa = $this->socialActionRepository->find($value);
return $this->actionRender->renderString($sa, []);

View File

@@ -38,21 +38,14 @@ final class GoalAggregator 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');
}
$qb->addSelect('goal.id as goal_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('goal_aggregator');
} else {
$qb->groupBy('goal_aggregator');
}
$qb->addSelect('IDENTITY(goal.goal) as acpw_goal_aggregator');
$qb->addGroupBy('acpw_goal_aggregator');
}
public function applyOn()
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
@@ -69,18 +62,24 @@ final class GoalAggregator implements AggregatorInterface
return 'Goal Type';
}
if (null === $value) {
return '';
}
$g = $this->goalRepository->find($value);
return $this->translatableStringHelper->localize($g->getTitle());
return $this->translatableStringHelper->localize(
$g->getTitle()
);
};
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
return ['goal_aggregator'];
return ['acpw_goal_aggregator'];
}
public function getTitle()
public function getTitle(): string
{
return 'Group social work actions by goal';
}

View File

@@ -0,0 +1,133 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class GoalResultAggregator implements AggregatorInterface
{
private ResultRepository $resultRepository;
private GoalRepository $goalRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
ResultRepository $resultRepository,
GoalRepository $goalRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->resultRepository = $resultRepository;
$this->goalRepository = $goalRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value) use ($key): string {
if (null === $value) {
return '';
}
switch ($key) {
case 'goal_aggregator':
if ('_header' === $value) {
return 'Goal Type';
}
$g = $this->goalRepository->find($value);
return $this->translatableStringHelper->localize(
$g->getTitle()
);
case 'result_aggregator':
if ('_header' === $value) {
return 'Result Type';
}
$r = $this->resultRepository->find($value);
return $this->translatableStringHelper->localize(
$r->getTitle()
);
default:
throw new \LogicException();
}
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return [
'goal_aggregator',
'result_aggregator'
];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group social work actions by goal and result';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('goal', $qb->getAllAliases(), true)) {
$qb->leftJoin('acpw.goals', 'goal');
}
if (!in_array('goalresult', $qb->getAllAliases(), true)) {
$qb->leftJoin('goal.results', 'goalresult');
}
$qb->addSelect('IDENTITY(goal.goal) as goal_aggregator');
$qb->addSelect('goalresult.id as result_aggregator');
$qb->addGroupBy('goal_aggregator')->addGroupBy('result_aggregator');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@@ -40,18 +40,11 @@ final class JobAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
$qb->leftJoin('acpw.referrers', 'acpwuser');
}
$qb->addSelect('IDENTITY(acpwuser.userJob) as job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('job_aggregator');
} else {
$qb->groupBy('job_aggregator');
}
$qb->addSelect('IDENTITY(acpwuser.userJob) as job_aggregator')
->addGroupBy('job_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class JobAggregator implements AggregatorInterface
return 'Job';
}
if (null === $value) {
return '';
}
$j = $this->jobRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -40,18 +40,11 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
$qb->leftJoin('acpw.referrers', 'acpwuser');
}
$qb->addSelect('acpwuser.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_aggregator');
} else {
$qb->groupBy('referrer_aggregator');
}
$qb->addGroupBy('referrer_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class ReferrerAggregator implements AggregatorInterface
return 'Referrer';
}
if (null === $value) {
return '';
}
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);

View File

@@ -37,30 +37,15 @@ final class ResultAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpwresult', $qb->getAllAliases(), true)) {
$qb->join('acpw.results', 'acpwresult');
if (!in_array('result', $qb->getAllAliases(), true)) {
$qb->leftJoin('acpw.results', 'result');
}
if (!in_array('goal', $qb->getAllAliases(), true)) {
$qb->join('acpw.goals', 'goal');
}
if (!in_array('goalresult', $qb->getAllAliases(), true)) {
$qb->join('goal.results', 'goalresult');
}
$qb->addSelect('acpwresult.id, IDENTITY(goal.results) as result_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('result_aggregator');
} else {
$qb->groupBy('result_aggregator');
}
$qb->addSelect('result.id AS acpw_result_aggregator');
$qb->addGroupBy('acpw_result_aggregator');
}
public function applyOn()
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
@@ -77,18 +62,24 @@ final class ResultAggregator implements AggregatorInterface
return 'Result Type';
}
$g = $this->resultRepository->find($value);
if (null === $value) {
return '';
}
return $this->translatableStringHelper->localize($g->getTitle());
$r = $this->resultRepository->find($value);
return $this->translatableStringHelper->localize(
$r->getTitle()
);
};
}
public function getQueryKeys($data)
public function getQueryKeys($data): array
{
return ['result_aggregator'];
return ['acpw_result_aggregator'];
}
public function getTitle()
public function getTitle(): string
{
return 'Group social work actions by result';
}

View File

@@ -40,18 +40,11 @@ final class ScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
$qb->join('acpw.referrers', 'acpwuser');
$qb->leftJoin('acpw.referrers', 'acpwuser');
}
$qb->addSelect('IDENTITY(acpwuser.mainScope) as scope_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('scope_aggregator');
} else {
$qb->groupBy('scope_aggregator');
}
$qb->addGroupBy('scope_aggregator');
}
public function applyOn(): string
@@ -71,6 +64,10 @@ final class ScopeAggregator implements AggregatorInterface
return 'Scope';
}
if (null === $value) {
return '';
}
$s = $this->scopeRepository->find($value);
return $this->translatableStringHelper->localize(

View File

@@ -15,6 +15,8 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -90,9 +92,25 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$qb = $this->repository->createQueryBuilder('acp');
$qb->select('COUNT(acp.id) AS export_result');
$qb
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('authorized_centers', $centers)
;
$qb->select('COUNT(DISTINCT acp.id) AS export_result');
return $qb;
}

View File

@@ -15,6 +15,8 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -88,6 +90,10 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$qb = $this->repository->createQueryBuilder('acp');
if (!in_array('acpw', $qb->getAllAliases(), true)) {
@@ -98,7 +104,19 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface
$qb->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval');
}
$qb->select('COUNT(workeval.id) AS export_result');
$qb
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('authorized_centers', $centers)
;
$qb->select('COUNT(DISTINCT workeval.id) AS export_result');
return $qb;
}

View File

@@ -15,6 +15,9 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -88,26 +91,31 @@ class CountHousehold implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$qb = $this->repository->createQueryBuilder('acp');
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
if (!in_array('acppart', $qb->getAllAliases(), true)) {
$qb->join('acp.participations', 'acppart');
}
$qb = $this->repository
->createQueryBuilder('acp')
->join('acp.participations', 'acppart')
// little optimization: we remove joins and make a direct join between participations and household members
->join(HouseholdMember::class, 'member', Query\Expr\Join::WITH, 'IDENTITY(acppart.person) = IDENTITY(member.person)')
->join('member.household', 'household')
;
if (!in_array('partperson', $qb->getAllAliases(), true)) {
$qb->join('acppart.person', 'partperson');
}
$qb
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('authorized_centers', $centers)
;
if (!in_array('member', $qb->getAllAliases(), true)) {
$qb->join('partperson.householdParticipations', 'member');
}
if (!in_array('household', $qb->getAllAliases(), true)) {
$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

@@ -14,9 +14,11 @@ namespace Chill\PersonBundle\Export\Export;
use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use LogicException;
@@ -100,9 +102,12 @@ class CountPerson implements ExportInterface, GroupedExportInterface
$qb = $this->personRepository->createQueryBuilder('person');
$qb->select('COUNT(person.id) AS export_result')
->join('person.center', 'center')
->andWhere('center IN (:authorized_centers)')
->setParameter('authorized_centers', $centers);
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
)
)
->setParameter('authorized_centers', $centers);
return $qb;
}

View File

@@ -15,6 +15,7 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -88,6 +89,10 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor
public function initiateQuery(array $requiredModifiers, array $acl, array $data = [])
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$qb = $this->repository->createQueryBuilder('acp');
if (!in_array('acppart', $qb->getAllAliases(), true)) {
@@ -95,10 +100,16 @@ 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->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.PersonCenterHistory::class.' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
)
)->setParameter('authorized_centers', $centers);
$qb->select('COUNT(DISTINCT person.id) AS export_result');
return $qb;
}

View File

@@ -15,6 +15,8 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\EntityManagerInterface;
@@ -90,13 +92,26 @@ class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this->repository->createQueryBuilder('acp');
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
if (!in_array('acpw', $qb->getAllAliases(), true)) {
$qb->join('acp.works', 'acpw');
}
$qb = $this->repository->createQueryBuilder('acp')
->join('acp.works', 'acpw');
$qb->select('COUNT(acpw.id) as export_result');
$qb
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('authorized_centers', $centers)
;
$qb->select('COUNT(DISTINCT acpw.id) as export_result');
return $qb;
}

View File

@@ -16,6 +16,8 @@ use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use DateTime;
@@ -94,15 +96,27 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$centers = array_map(static function ($el) {
return $el['center'];
}, $acl);
$qb = $this->repository->createQueryBuilder('acp');
$qb
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('authorized_centers', $centers)
;
$qb
->select('AVG(
( CASE
WHEN acp.closingDate IS NOT NULL
THEN acp.closingDate
ELSE :force_closingDate
END ) - acp.openingDate
COALESCE(acp.closingDate, :force_closingDate) - acp.openingDate
) AS export_result')
->setParameter('force_closingDate', $data['closingdate']);

View File

@@ -29,24 +29,9 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = "OVERLAPSI (acp.openingDate, acp.closingDate), (:datefrom, :dateto) = 'TRUE'";
$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->andWhere($clause);
$qb->setParameter('datefrom', $data['date_from'], Types::DATE_MUTABLE);
$qb->setParameter('dateto', $data['date_to'], Types::DATE_MUTABLE);
}

View File

@@ -29,20 +29,12 @@ class OpenBetweenDatesFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->lt('acp.openingDate', ':datefrom'),
$qb->expr()->gt('acp.closingDate', ':dateto')
$qb->expr()->gte('acp.openingDate', ':datefrom'),
$qb->expr()->lte('acp.openingDate', ':dateto')
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->andWhere($clause);
$qb->setParameter('datefrom', $data['date_from'], Types::DATE_MUTABLE);
$qb->setParameter('dateto', $data['date_to'], Types::DATE_MUTABLE);
}

View File

@@ -70,10 +70,6 @@ final class RequestorFilter implements FilterInterface
case 'other_person':
$expr = $this->em->getExpressionBuilder();
if (!in_array('acppart', $qb->getAllAliases(), true)) {
$qb->join('acp.participations', 'acppart');
}
$clause = $expr->andX(
$expr->isNotNull('acp.requestorPerson'),
$expr->notIn(
@@ -85,6 +81,7 @@ final class RequestorFilter implements FilterInterface
->join('acp2.participations', 'acppart2')
->select('identity(acp2.requestorPerson)')
->where($expr->eq('acp2.requestorPerson', 'acppart2.person'))
->andWhere('acp2.id = acp.id')
->getDQL()
)
);

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

@@ -32,8 +32,8 @@ class AccompanyingPeriodClosingFilter extends AbstractAccompanyingPeriodExportEl
$this->addJoinAccompanyingPeriod($qb);
$clause = $qb->expr()->andX(
$qb->expr()->lte('accompanying_period.closingDate', ':date_to'),
$qb->expr()->gte('accompanying_period.closingDate', ':date_from')
$qb->expr()->lte('acp.closingDate', ':date_to'),
$qb->expr()->gte('acp.closingDate', ':date_from')
);
$qb->andWhere($clause);

View File

@@ -34,12 +34,12 @@ class AccompanyingPeriodFilter extends AbstractAccompanyingPeriodExportElement i
$clause = $qb->expr()->andX();
$clause->add(
$qb->expr()->lte('accompanying_period.openingDate', ':date_to')
$qb->expr()->lte('acp.openingDate', ':date_to')
);
$clause->add(
$qb->expr()->orX(
$qb->expr()->gte('accompanying_period.closingDate', ':date_from'),
$qb->expr()->isNull('accompanying_period.closingDate')
$qb->expr()->gte('acp.closingDate', ':date_from'),
$qb->expr()->isNull('acp.closingDate')
)
);

View File

@@ -32,8 +32,8 @@ class AccompanyingPeriodOpeningFilter extends AbstractAccompanyingPeriodExportEl
$this->addJoinAccompanyingPeriod($qb);
$clause = $qb->expr()->andX(
$qb->expr()->lte('accompanying_period.openingDate', ':date_to'),
$qb->expr()->gte('accompanying_period.openingDate', ':date_from')
$qb->expr()->lte('acp.openingDate', ':date_to'),
$qb->expr()->gte('acp.openingDate', ':date_from')
);
$qb->andWhere($clause);

View File

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

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