mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch '111_export_GeographicalUnit' into 111_exports_suite
This commit is contained in:
@@ -2,39 +2,69 @@
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
final class GeographicalUnitStatAggregator implements AggregatorInterface
|
||||
{
|
||||
/*
|
||||
private EntityRepository $repository;
|
||||
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em
|
||||
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->repository = $em->getRepository(...::class);
|
||||
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'Geographical unit';
|
||||
}
|
||||
switch ($key) {
|
||||
case 'acp_geog_agg_unitname':
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'acp_geog_agg_unitname';
|
||||
}
|
||||
|
||||
$g = $this->repository->find($value);
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $g; //...
|
||||
};
|
||||
return $value;
|
||||
};
|
||||
case 'acp_geog_agg_unitrefid':
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'acp_geog_agg_unitrefid';
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
};
|
||||
default:
|
||||
throw new \UnexpectedValueException('this value should not happens');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +72,7 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['geographicalunitstat_aggregator'];
|
||||
return ['acp_geog_agg_unitname', 'acp_geog_agg_unitrefid'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +80,22 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
$builder
|
||||
->add('date_calc', ChillDateType::class, [
|
||||
'label' => 'Compute geographical location at date',
|
||||
'required' => true,
|
||||
'data' => new \DateTimeImmutable('today'),
|
||||
'input' => 'datetime_immutable',
|
||||
])
|
||||
->add('level', EntityType::class, [
|
||||
'label' => 'Geographical layer',
|
||||
'placeholder' => 'Select a geographical layer',
|
||||
'class' => GeographicalUnitLayer::class,
|
||||
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
|
||||
'choice_label' => function(GeographicalUnitLayer $item) {
|
||||
return $this->translatableStringHelper->localize($item->getName());
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,16 +119,70 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('acp_geog_agg_location_history', $qb->getAllAliases(), true)) {
|
||||
$qb->leftJoin('acp.locationHistories', 'acp_geog_agg_location_history');
|
||||
|
||||
//$qb->addSelect('... AS geographicalunitstat_aggregator');
|
||||
$qb->andWhere(
|
||||
$qb->expr()->andX(
|
||||
'acp_geog_agg_location_history.startDate <= :acp_geog_aggregator_date',
|
||||
$qb->expr()->orX(
|
||||
'acp_geog_agg_location_history.endDate IS NULL',
|
||||
'acp_geog_agg_location_history.endDate > :acp_geog_aggregator_date'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$groupby = $qb->getDQLPart('groupBy');
|
||||
|
||||
if (!empty($groupBy)) {
|
||||
$qb->addGroupBy('geographicalunitstat_aggregator');
|
||||
} else {
|
||||
$qb->groupBy('geographicalunitstat_aggregator');
|
||||
$qb->setParameter('acp_geog_aggregator_date', $data['date_calc']);
|
||||
}
|
||||
|
||||
// link between location history and person
|
||||
if (!in_array('acp_geog_agg_address_person_location', $qb->getAllAliases(), true)) {
|
||||
$qb->leftJoin(
|
||||
PersonHouseholdAddress::class,
|
||||
'acp_geog_agg_address_person_location',
|
||||
Join::WITH,
|
||||
$qb->expr()->andX(
|
||||
'IDENTITY(acp_geog_agg_address_person_location.person) = IDENTITY(acp_geog_agg_location_history.personLocation)',
|
||||
'acp_geog_agg_address_person_location.validFrom < :acp_geog_aggregator_date',
|
||||
$qb->expr()->orX(
|
||||
'acp_geog_agg_address_person_location.validTo > :acp_geog_aggregator_date',
|
||||
$qb->expr()->isNull('acp_geog_agg_address_person_location.validTo')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$qb->setParameter('acp_geog_aggregator_date', $data['date_calc']);
|
||||
}
|
||||
|
||||
// we finally find an address
|
||||
if (!in_array('acp_geog_agg_address', $qb->getAllAliases(), true)) {
|
||||
$qb->leftJoin(
|
||||
Address::class,
|
||||
'acp_geog_agg_address',
|
||||
Join::WITH,
|
||||
'COALESCE(IDENTITY(acp_geog_agg_address_person_location.address), IDENTITY(acp_geog_agg_location_history.addressLocation)) = acp_geog_agg_address.id'
|
||||
);
|
||||
}
|
||||
|
||||
// and we do a join with units
|
||||
$qb->leftJoin(
|
||||
GeographicalUnit::class,
|
||||
'acp_geog_units',
|
||||
Join::WITH,
|
||||
'ST_CONTAINS(acp_geog_units.geom, acp_geog_agg_address.point) = TRUE'
|
||||
);
|
||||
|
||||
$qb->andWhere($qb->expr()->eq('acp_geog_units.layer', ':acp_geog_unit_layer'));
|
||||
|
||||
$qb->setParameter('acp_geog_unit_layer', $data['level']);
|
||||
|
||||
// we add group by
|
||||
$qb
|
||||
->addSelect('acp_geog_units.unitName AS acp_geog_agg_unitname')
|
||||
->addSelect('acp_geog_units.unitRefId AS acp_geog_agg_unitrefid')
|
||||
->addGroupBy('acp_geog_agg_unitname')
|
||||
->addGroupBy('acp_geog_agg_unitrefid')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,4 +192,4 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
|
||||
{
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Entity\GeographicalUnitLayer;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class GeographicalUnitAggregator implements AggregatorInterface
|
||||
{
|
||||
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
switch ($key) {
|
||||
case 'geog_unit_name':
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'acp_geog_agg_unitname';
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
};
|
||||
|
||||
case 'geog_unit_key':
|
||||
return function ($value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'acp_geog_agg_unitrefid';
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
};
|
||||
|
||||
default:
|
||||
throw new \LogicException('key not supported');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
return ['geog_unit_name', 'geog_unit_key'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('date_calc', ChillDateType::class, [
|
||||
'label' => 'Address valid at this date',
|
||||
'required' => true,
|
||||
'data' => new \DateTimeImmutable('today'),
|
||||
'input' => 'datetime_immutable',
|
||||
])
|
||||
->add('level', EntityType::class, [
|
||||
'label' => 'Geographical layer',
|
||||
'placeholder' => 'Select a geographical layer',
|
||||
'class' => GeographicalUnitLayer::class,
|
||||
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
|
||||
'choice_label' => function(GeographicalUnitLayer $item) {
|
||||
return $this->translatableStringHelper->localize($item->getName());
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Group people by geographical unit based on his address';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function alterQuery(QueryBuilder $qb, $data): void
|
||||
{
|
||||
$qb
|
||||
->leftJoin('person.householdAddresses', 'person_geog_agg_current_household_address')
|
||||
->leftJoin('person_geog_agg_current_household_address.address', 'person_geog_agg_address')
|
||||
->leftJoin(GeographicalUnit::class, 'person_geog_agg_geog_unit', Join::WITH, 'ST_CONTAINS(person_geog_agg_geog_unit.geom, person_geog_agg_address.point) = TRUE')
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('person_geog_agg_current_household_address'),
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte('person_geog_agg_current_household_address.validFrom', ':person_geog_agg_date'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('person_geog_agg_current_household_address.validTo'),
|
||||
$qb->expr()->gt('person_geog_agg_current_household_address.validTo', ':person_geog_agg_date')
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('person_geog_agg_geog_unit'),
|
||||
$qb->expr()->in('person_geog_agg_geog_unit.layer', ':person_geog_agg_layers')
|
||||
)
|
||||
)
|
||||
->setParameter('person_geog_agg_date', $data['date_calc'])
|
||||
->setParameter('person_geog_agg_layers', $data['level'])
|
||||
->addSelect('person_geog_agg_geog_unit.unitName AS geog_unit_name')
|
||||
->addSelect('person_geog_agg_geog_unit.unitRefId AS geog_unit_key')
|
||||
->addGroupBy('geog_unit_name')
|
||||
->addGroupBy('geog_unit_key')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function applyOn()
|
||||
{
|
||||
return Declarations::PERSON_TYPE;
|
||||
}
|
||||
|
||||
public static function getDefaultAlias(): string
|
||||
{
|
||||
return 'person_geog_agg';
|
||||
}
|
||||
}
|
@@ -11,29 +11,46 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query\Expr;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* e) par zone géographique.
|
||||
*
|
||||
* Paramètre:
|
||||
* * Date
|
||||
* * Choix unique entre: territoire, epci, canton, commune, secteur d'intervention
|
||||
* * une fois le premier choix effectué, l'utilisateur choisi parmi les zones (choix multiple)
|
||||
*
|
||||
* Le filtre retiendra les parcours localisé dans un des territoires cochés, à la date indiquée en paramètre.
|
||||
* Filter accompanying period by geographical zone
|
||||
*/
|
||||
class GeographicalUnitStatFilter implements FilterInterface
|
||||
{
|
||||
|
||||
private GeographicalUnitRepositoryInterface $geographicalUnitRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
GeographicalUnitRepositoryInterface $geographicalUnitRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->em = $em;
|
||||
$this->geographicalUnitRepository = $geographicalUnitRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
@@ -41,18 +58,32 @@ class GeographicalUnitStatFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->eq(1, 1);
|
||||
$subQueryDql =
|
||||
'SELECT
|
||||
1
|
||||
FROM '.AccompanyingPeriod\AccompanyingPeriodLocationHistory::class.' acp_geog_filter_location_history
|
||||
LEFT JOIN '.PersonHouseholdAddress::class.' acp_geog_filter_address_person_location
|
||||
WITH IDENTITY(acp_geog_filter_location_history.personLocation) = IDENTITY(acp_geog_filter_address_person_location.person)
|
||||
LEFT JOIN '.Address::class.' acp_geog_filter_address
|
||||
WITH COALESCE(IDENTITY(acp_geog_filter_address_person_location.address), IDENTITY(acp_geog_filter_location_history.addressLocation)) = acp_geog_filter_address.id
|
||||
LEFT JOIN '.GeographicalUnit::class.' acp_geog_filter_units WITH ST_CONTAINS(acp_geog_units.geom, acp_geog_filter_address.point) = TRUE
|
||||
WHERE
|
||||
(acp_geog_filter_location_history.startDate <= :acp_geog_filter_date AND (
|
||||
acp_geog_filter_location_history.endDate IS NULL OR acp_geog_filter_location_history.endDate < :acp_geog_filter_date
|
||||
))
|
||||
AND
|
||||
(acp_geog_filter_address_person_location.validFrom < :acp_geog_filter_date AND (
|
||||
acp_geog_filter_address_person_location.validTo IS NULL OR acp_geog_filter_address_person_location.validTo < :acp_geog_filter_date
|
||||
))
|
||||
AND acp_geog_filter_units IN (:acp_geog_filter_units)
|
||||
AND acp_geog_filter_location_history.period = acp.id
|
||||
';
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('date', $data['date'], Types::DATE_MUTABLE);
|
||||
$qb->setParameter('loctype', $data['accepted_loctype']);
|
||||
$qb
|
||||
->andWhere($qb->expr()->exists($subQueryDql))
|
||||
->setParameter('acp_geog_filter_date', $data['date_calc'])
|
||||
->setParameter('acp_geog_filter_units', $data['units'])
|
||||
;
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -63,23 +94,40 @@ class GeographicalUnitStatFilter implements FilterInterface
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('date', ChillDateType::class, [
|
||||
'data' => new DateTime(),
|
||||
->add('date_calc', ChillDateType::class, [
|
||||
'label' => 'Compute geographical location at date',
|
||||
'required' => true,
|
||||
'data' => new \DateTimeImmutable('today'),
|
||||
'input' => 'datetime_immutable',
|
||||
])
|
||||
->add('accepted_loctype', EntityType::class, [
|
||||
->add('units', EntityType::class, [
|
||||
'label' => 'Geographical unit',
|
||||
'placeholder' => 'Select a geographical unit',
|
||||
'class' => GeographicalUnit::class,
|
||||
'choice_label' => static function (GeographicalUnit $u) {
|
||||
return $u->getUnitName();
|
||||
'choices' => $this->geographicalUnitRepository->findAll(),
|
||||
'choice_label' => function(GeographicalUnit $item) {
|
||||
return $this->translatableStringHelper->localize($item->getLayer()->getName()) . ' > ' . $item->getUnitName();
|
||||
},
|
||||
'attr' => [
|
||||
'class' => 'select2',
|
||||
],
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
return ['Filtered by geographic unit: only %date%', [
|
||||
'%date%' => $data['date']->format('d-m-Y'),
|
||||
return ['Filtered by geographic unit: computed at %date%, only in %units%', [
|
||||
'%date%' => $data['date_calc']->format('d-m-Y'),
|
||||
'%units' => implode(
|
||||
', ',
|
||||
array_map(
|
||||
function(GeographicalUnit $item) {
|
||||
return $this->translatableStringHelper->localize($item->getLayer()->getName()) . ' > ' . $item->getUnitName();
|
||||
},
|
||||
$data['units']
|
||||
)
|
||||
)
|
||||
]];
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
|
||||
{
|
||||
private GeographicalUnitRepositoryInterface $geographicalUnitRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
GeographicalUnitRepositoryInterface $geographicalUnitRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->geographicalUnitRepository = $geographicalUnitRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('date_calc', ChillDateType::class, [
|
||||
'label' => 'Compute geographical location at date',
|
||||
'required' => true,
|
||||
'data' => new \DateTimeImmutable('today'),
|
||||
'input' => 'datetime_immutable',
|
||||
])
|
||||
->add('units', EntityType::class, [
|
||||
'label' => 'Geographical unit',
|
||||
'placeholder' => 'Select a geographical unit',
|
||||
'class' => GeographicalUnit::class,
|
||||
'choices' => $this->geographicalUnitRepository->findAll(),
|
||||
'choice_label' => function(GeographicalUnit $item) {
|
||||
return $this->translatableStringHelper->localize($item->getLayer()->getName()) . ' > ' . $item->getUnitName();
|
||||
},
|
||||
'attr' => [
|
||||
'class' => 'select2',
|
||||
],
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Filter by person\'s geographical unit (based on address)';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
return [
|
||||
'exports.by_person.Filtered by person\'s geographical unit (based on address) computed at datecalc, only units',
|
||||
[
|
||||
'datecalc' => $data['date_calc']->format('Y-m-d'),
|
||||
'units' => implode(
|
||||
', ',
|
||||
array_map(
|
||||
function (GeographicalUnit $item) {
|
||||
return $this->translatableStringHelper->localize($item->getLayer()->getName()) . ' > ' . $item->getUnitName();
|
||||
},
|
||||
$data['units']->toArray()
|
||||
)
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$subQuery =
|
||||
'SELECT 1
|
||||
FROM '.PersonHouseholdAddress::class.' person_filter_geog_person_household_address
|
||||
JOIN person_filter_geog_person_household_address.address person_filter_geog_address
|
||||
JOIN '.GeographicalUnit::class.' person_filter_geog_unit
|
||||
WITH ST_CONTAINS(person_filter_geog_unit.geom, person_filter_geog_address.point) = TRUE
|
||||
WHERE
|
||||
person_filter_geog_person_household_address.validFrom <= :person_filter_geog_date
|
||||
AND
|
||||
(person_filter_geog_person_household_address.validTo IS NULL
|
||||
OR person_filter_geog_person_household_address.validTo > :person_filter_geog_date)
|
||||
AND
|
||||
person_filter_geog_unit IN (:person_filter_geog_units)
|
||||
AND
|
||||
person_filter_geog_person_household_address.person = person
|
||||
';
|
||||
|
||||
$qb
|
||||
->andWhere(
|
||||
$qb->expr()->exists($subQuery)
|
||||
)
|
||||
->setParameter('person_filter_geog_date', $data['date_calc'])
|
||||
->setParameter('person_filter_geog_units', $data['units'])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function applyOn()
|
||||
{
|
||||
return Declarations::PERSON_TYPE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
<?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\Tests\Export\Aggregator\AccompanyingCourseAggregators;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\GeographicalUnitStatAggregator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class GeographicalUnitStatAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
private GeographicalUnitStatAggregator $aggregator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->aggregator = self::$container->get('chill.person.export.aggregator_geographicalunitstat');
|
||||
}
|
||||
|
||||
public function getAggregator()
|
||||
{
|
||||
return $this->aggregator;
|
||||
}
|
||||
|
||||
public function getFormData(): array
|
||||
{
|
||||
return [
|
||||
[],
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
{
|
||||
if (null === self::$kernel) {
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
return [
|
||||
$em->createQueryBuilder()
|
||||
->select('count(acp.id)')
|
||||
->from(AccompanyingPeriod::class, 'acp')
|
||||
,
|
||||
];
|
||||
}
|
||||
}
|
@@ -44,12 +44,12 @@ services:
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_step_filter }
|
||||
|
||||
#chill.person.export.filter_geographicalunitstat:
|
||||
# class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\GeographicalUnitStatFilter
|
||||
# autowire: true
|
||||
# autoconfigure: true
|
||||
# tags:
|
||||
# - { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter }
|
||||
chill.person.export.filter_geographicalunitstat:
|
||||
class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\GeographicalUnitStatFilter
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter }
|
||||
|
||||
chill.person.export.filter_socialaction:
|
||||
class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\SocialActionFilter
|
||||
@@ -171,12 +171,12 @@ services:
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: accompanyingcourse_step_aggregator }
|
||||
|
||||
#chill.person.export.aggregator_geographicalunitstat:
|
||||
# class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\GeographicalUnitStatAggregator
|
||||
# autowire: true
|
||||
# autoconfigure: true
|
||||
# tags:
|
||||
# - { name: chill.export_aggregator, alias: accompanyingcourse_geographicalunitstat_aggregator }
|
||||
chill.person.export.aggregator_geographicalunitstat:
|
||||
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\GeographicalUnitStatAggregator
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: accompanyingcourse_geographicalunitstat_aggregator }
|
||||
|
||||
chill.person.export.aggregator_socialaction:
|
||||
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialActionAggregator
|
||||
|
@@ -90,6 +90,12 @@ services:
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: person_marital_status_filter }
|
||||
|
||||
Chill\PersonBundle\Export\Filter\PersonFilters\GeographicalUnitFilter:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: person_geog_filter }
|
||||
|
||||
## Aggregators
|
||||
chill.person.export.aggregator_nationality:
|
||||
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator
|
||||
@@ -132,3 +138,10 @@ services:
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_household_position_aggregator }
|
||||
|
||||
Chill\PersonBundle\Export\Aggregator\PersonAggregators\GeographicalUnitAggregator:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_aggregator, alias: person_geog_aggregator }
|
||||
|
||||
|
@@ -130,3 +130,8 @@ periods:
|
||||
many {Masquer # parcours clôturés ou anciens parcours}
|
||||
other {Masquer # parcours clôturés ou anciens parcours}
|
||||
}
|
||||
|
||||
exports:
|
||||
by_person:
|
||||
Filtered by person\'s geographical unit (based on address) computed at date, only units:
|
||||
"Filtré par zone géographique sur base de l'adresse, calculé à {datecalc, date, short}, seulement les zones suivantes: {units}"
|
||||
|
@@ -456,7 +456,14 @@ Group by step: Grouper les parcours par statut du parcours
|
||||
|
||||
Filter by geographical unit: Filtrer les parcours par zone géographique
|
||||
Group by geographical unit: Grouper les parcours par zone géographique
|
||||
Compute geographical location at date: Date de calcul de la localisation géographique
|
||||
Geographical unit: Zone géographique
|
||||
acp_geog_agg_unitname: Zone géographique
|
||||
acp_geog_agg_unitrefid: Clé de la zone géographique
|
||||
Geographical layer: Couche géographique
|
||||
Select a geographical layer: Choisir une couche géographique
|
||||
Group people by geographical unit based on his address: Grouper les personnes par zone géographique (sur base de l'adresse)
|
||||
Filter by person's geographical unit (based on address): Filter les personnes par zone géographique (sur base de l'adresse)
|
||||
|
||||
Filter by socialaction: Filtrer les parcours par action d'accompagnement
|
||||
Accepted socialactions: Actions d'accompagnement
|
||||
|
Reference in New Issue
Block a user