Merge branch '111_exports' into social_action_exports

This commit is contained in:
2022-08-11 14:08:33 +02:00
14 changed files with 869 additions and 4 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\EvaluationAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class EvaluationTypeAggregator implements AggregatorInterface
{
private EvaluationRepository $evaluationRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
EvaluationRepository $evaluationRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->evaluationRepository = $evaluationRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ($value === '_header') {
return 'Evaluation type';
}
$ev = $this->evaluationRepository->find($value);
return $this->translatableStringHelper->localize($ev->getTitle());
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['evaluationtype_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by evaluation type';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('eval.evaluation', 'ev');
$qb->addSelect('ev.id AS evaluationtype_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('evaluationtype_aggregator');
} else {
$qb->groupBy('evaluationtype_aggregator');
}
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::EVAL_TYPE;
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ChildrenNumberAggregator implements AggregatorInterface
{
private TranslatorInterface $translator;
public function __construct(
TranslatorInterface $translator
) {
$this->translator = $translator;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ($value === '_header') {
return 'Number of children';
}
return $this->translator->trans(
'household_composition.numberOfChildren children in household', [
'numberOfChildren' => $value
]);
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['childrennumber_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('on_date', ChillDateType::class, [
'data' => new \DateTime('now'),
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by number of children';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('composition.numberOfChildren AS 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')
)
);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::HOUSEHOLD_TYPE;
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class CompositionAggregator implements AggregatorInterface
{
private HouseholdCompositionTypeRepository $typeRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
HouseholdCompositionTypeRepository $typeRepository,
TranslatableStringHelper $translatableStringHelper
) {
$this->typeRepository = $typeRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ($value === '_header') {
return 'Composition';
}
$c = $this->typeRepository->find($value);
return $this->translatableStringHelper->localize(
$c->getLabel()
);
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['composition_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('on_date', ChillDateType::class, [
'data' => new \DateTime('now'),
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by composition';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('IDENTITY(composition.householdCompositionType) AS 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);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::HOUSEHOLD_TYPE;
}
}