mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
household position aggregator for person
This commit is contained in:
parent
bde623e806
commit
4c91bf5084
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
|
||||
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Repository\Household\PositionRepository;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class HouseholdPositionAggregator implements AggregatorInterface, ExportElementValidatedInterface
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
private PositionRepository $positionRepository;
|
||||
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatorInterface $translator, TranslatableStringHelper $translatableStringHelper, PositionRepository $positionRepository)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
$this->positionRepository = $positionRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb->resetDQLPart('from');
|
||||
$qb->from('ChillPersonBundle:Household\HouseholdMember', 'hm');
|
||||
|
||||
$qb->join('hm.person', 'person');
|
||||
$qb->join('person.center', 'center');
|
||||
|
||||
$qb->andWhere($qb->expr()->andX(
|
||||
$qb->expr()->lte('hm.startDate', ':date'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('hm.endDate'),
|
||||
$qb->expr()->gte('hm.endDate', ':date')
|
||||
)
|
||||
));
|
||||
|
||||
$qb->setParameter('date', $data['date_position']);
|
||||
|
||||
$qb->addSelect('IDENTITY(hm.position) AS household_position_aggregator');
|
||||
|
||||
$groupBy = $qb->getDQLPart('groupBy');
|
||||
|
||||
if (!empty($groupBy)) {
|
||||
$qb->addGroupBy('household_position_aggregator');
|
||||
} else {
|
||||
$qb->groupBy('household_position_aggregator');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
{
|
||||
return 'person';
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_position', ChillDateType::class, [
|
||||
'label' => 'Household position in relation to this date',
|
||||
'data' => new DateTime(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return function ($value) {
|
||||
if ('_header' === $value) {
|
||||
return 'Household position';
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return $this->translator->trans('without data');
|
||||
}
|
||||
|
||||
$p = $this->positionRepository->find($value);
|
||||
|
||||
return $this->translatableStringHelper->localize($p->getLabel());
|
||||
};
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
return [
|
||||
'household_position_aggregator',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Aggregate by household position';
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
if (null === $data['date_position']) {
|
||||
$context->buildViolation('The date should not be empty')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
@ -111,3 +111,10 @@ services:
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_marital_status_aggregator }
|
||||
|
||||
chill.person.export.aggregator_household_position:
|
||||
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\HouseholdPositionAggregator
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_household_position_aggregator }
|
||||
|
@ -388,7 +388,7 @@ Filter in relation to this date: Filtrer par rapport à cette date
|
||||
"Filtered by a state of %deadOrAlive% at this date %date_calc%": Filtré par personnes qui sont %deadOrAlive% à cette date %date_calc%
|
||||
|
||||
Filter by person's age: Filtrer par âge de la personne
|
||||
Filtered by person's age: Filtré par âge de la personne
|
||||
"Filtered by person's age: between %min_age% and %max_age%": "Filtré par âge de la personne entre %min_age% et %max_age%"
|
||||
Minimum age: Âge minimum
|
||||
Maximum age: Âge maximum
|
||||
The minimum age should be less than the maximum age.: L'âge minimum doit être plus bas que l'âge maximum.
|
||||
@ -570,6 +570,9 @@ Group by country: Grouper par pays
|
||||
Group people by gender: Grouper les personnes par genre
|
||||
Group people by their professional situation: Grouper les personnes par situation professionelle
|
||||
Group people by marital status: Grouper les personnes par état matrimonial
|
||||
Aggregate by household position: Grouper par position dans le ménage
|
||||
Household position in relation to this date: Position dans le ménage par rapport à cette date
|
||||
Household position: Position dans le ménage
|
||||
|
||||
Aggregate by age: Grouper par âge
|
||||
Calculate age in relation to this date: Calculer l'âge par rapport à cette date
|
||||
|
Loading…
x
Reference in New Issue
Block a user