start with person aggregators

This commit is contained in:
Julie Lenaerts 2022-08-03 16:21:57 +02:00
parent 2ff346d7d8
commit 32bb868b2b
6 changed files with 186 additions and 2 deletions

View File

@ -0,0 +1,82 @@
<?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\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\MaritalStatusRepository;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
final class MaritalStatusAggregator implements AggregatorInterface
{
private MaritalStatusRepository $maritalStatusRepository;
public function __construct(MaritalStatusRepository $maritalStatusRepository)
{
$this->maritalStatusRepository = $maritalStatusRepository;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('person.maritalStatus', 'ms');
$qb->addSelect('ms.id as marital_status_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('marital_status_aggregator');
} else {
$qb->groupBy('marital_status_aggregator');
}
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
}
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'Marital status';
}
$g = $this->maritalStatusRepository->find($value);
return $g->getName()['fr'];
};
}
public function getQueryKeys($data)
{
return ['marital_status_aggregator'];
}
public function getTitle()
{
return 'Group people by marital status';
}
}

View File

@ -0,0 +1,86 @@
<?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 App\Repository\VendeePerson\SituationProfessionelleRepository;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
// todo FIX ERROR AND MOVE TO VENDEE ROOT FOLDER
final class ProfessionalSituationAggregator implements AggregatorInterface
{
private SituationProfessionelleRepository $professionalSituationRepository;
public function __construct(SituationProfessionelleRepository $professionalSituationRepository)
{
$this->professionalSituationRepository = $professionalSituationRepository;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('App:VendeePerson', 'vp');
$qb->join('vp.person', 'person');
$qb->join('person.center', 'center');
$qb->join('vp.situationProfessionelle', 'sp');
$qb->addSelect('sp.id as professional_situation_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('professional_situation_aggregator');
} else {
$qb->groupBy('professional_situation_aggregator');
}
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
}
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'Professional situation';
}
$g = $this->professionalSituationRepository->find($value);
return $g->getName()['fr'];
};
}
public function getQueryKeys($data)
{
return ['professional_situation_aggregator'];
}
public function getTitle()
{
return 'Group people by their professional situation';
}
}

View File

@ -1,5 +1,5 @@
<?php <?php
// TODO move to vendee root folder
/** /**
* Chill is a software for social workers * Chill is a software for social workers
* *

View File

@ -6,7 +6,7 @@
* For the full copyright and license information, please view * For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code. * the LICENSE file that was distributed with this source code.
*/ */
// TODO move to vendee root folder
declare(strict_types=1); declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters; namespace Chill\PersonBundle\Export\Filter\PersonFilters;

View File

@ -110,3 +110,17 @@ services:
autoconfigure: true autoconfigure: true
tags: tags:
- { name: chill.export_aggregator, alias: person_age_aggregator } - { name: chill.export_aggregator, alias: person_age_aggregator }
chill.person.export.aggregator_marital_status:
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\MaritalStatusAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: person_marital_status_aggregator }
# chill.person.export.aggregator_professional_situation:
# class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\ProfessionalSituationAggregator
# autowire: true
# autoconfigure: true
# tags:
# - { name: chill.export_aggregator, alias: person_professional_situation_aggregator }

View File

@ -489,6 +489,8 @@ Group by continents: Grouper par continent
Group by country: Grouper par pays Group by country: Grouper par pays
Group people by gender: Aggréger les personnes par genre Group people by gender: Aggréger les personnes par genre
Group people by their professional situation: Aggréger les personnes par situation professionelle
Group people by marital status: Aggréger les personnes par état matrimonial
Aggregate by age: Aggréger par âge Aggregate by age: Aggréger par âge
Calculate age in relation to this date: Calculer l'âge par rapport à cette date Calculate age in relation to this date: Calculer l'âge par rapport à cette date