diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php index 83f09bb0d..d8c0e1343 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php @@ -12,15 +12,25 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory; use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; class ResidentialAddressAtThirdpartyFilter implements FilterInterface { + private TranslatableStringHelper $translatableStringHelper; + + public function __construct(TranslatableStringHelper $translatableStringHelper) + { + $this->translatableStringHelper = $translatableStringHelper; + } + public function addRole() { return null; @@ -28,8 +38,9 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('thirdparty_type', EntityType::class, [ + $builder->add('thirdparty_cat', EntityType::class, [ 'class' => ThirdPartyCategory::class, + 'label' => 'Category', 'choice_label' => function (ThirdPartyCategory $tpc) { return $this->translatableStringHelper->localize($tpc->getName()); }, @@ -45,19 +56,19 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - - //TODO: Query is not finished... not clear what 'catégorie' corresponds with. Cannot get values to appear in table thirdparty_category $qb->resetDQLPart('from'); $qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra'); $qb->join('ra.person', 'person'); $qb->join('person.center', 'center'); - $qb->join('ra.hostThirdparty', 'thirdparty'); + $qb->join('ra.hostThirdParty', 't'); + $qb->join('t.categories', 'tc'); $where = $qb->getDQLPart('where'); $clause = $qb->expr()->andX( - $qb->expr()->isNotNull('ra.hostThirdparty'), - // $qb->expr()->in('thirdparty.categories') + $qb->expr()->isNotNull('ra.hostThirdParty'), + $qb->expr()->between(':date', 'ra.startDate', 'ra.endDate'), + $qb->expr()->in('tc.id', ':type') ); if ($where instanceof Expr\Andx) { @@ -66,6 +77,8 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface $where = $qb->expr()->andX($clause); } + $qb->setParameter('type', $data['thirdparty_cat']); + $qb->setParameter('date', $data['date_calc']); $qb->add('where', $where); } @@ -77,11 +90,14 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface public function describeAction($data, $format = 'string') { - return ['Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%']; + return ['Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type% and valid on %date_calc%', [ + '%thirdparty_type%' => $this->translatableStringHelper->localize($data['thirdparty_cat'][0]->getName()), + '%date_calc%' => $data['date_calc']->format('d-m-Y'), + ],]; } public function getTitle() { - return 'Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%'; + return 'Filtered by person\'s who have a residential address located at a thirdparty of type'; } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php index 9558c5940..835185db5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php @@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; class ResidentialAddressAtUserFilter implements FilterInterface @@ -34,7 +35,7 @@ class ResidentialAddressAtUserFilter implements FilterInterface $where = $qb->getDQLPart('where'); $clause = $qb->expr()->isNotNull('ra.hostPerson'); - if ($where instanceof Expr\Andx) { + if ($where instanceof Andx) { $where->add($clause); } else { $where = $qb->expr()->andX($clause); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index c17dcaaf1..ae8f90b78 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -76,6 +76,13 @@ services: tags: - { name: chill.export_filter, alias: person_residential_address_at_user_filter } + chill.person.export.filter_residential_address_at_thirdparty: + class: Chill\PersonBundle\Export\Filter\PersonFilters\ResidentialAddressAtThirdpartyFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: person_residential_address_at_thirdparty_filter } + ## Aggregators chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index df43b5922..db79e6551 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -573,6 +573,8 @@ 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 +Filtered by person's who have a residential address located at a thirdparty of type: Uniquement les usagers qui ont une addresse de résidence chez un tiers de catégorie "xxx" +"Filtered by person's who have a residential address located at a thirdparty of type %thirdparty_type% and valid on %date_calc%": "Uniquement les usagers qui ont une addresse de résidence chez un tiers de catégorie %thirdparty_type% et valide sur la date %date_calc%" Aggregate by age: Grouper par âge Calculate age in relation to this date: Calculer l'âge par rapport à cette date