Merge branch 'social_action_exports' into 111_exports

This commit is contained in:
2022-08-17 17:48:43 +02:00
15 changed files with 169 additions and 384 deletions

View File

@@ -12,21 +12,23 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Templating\TranslatableStringHelper;
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)
private TranslatableStringHelper $translatableStringHelper;
public function __construct(MaritalStatusRepository $maritalStatusRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->maritalStatusRepository = $maritalStatusRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
@@ -66,7 +68,7 @@ final class MaritalStatusAggregator implements AggregatorInterface
$g = $this->maritalStatusRepository->find($value);
return $g->getName()['fr'];
return $this->translatableStringHelper->localize($g->getName());
};
}

View File

@@ -124,17 +124,19 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
// initialize array and add blank key for null values
$labels = [
'' => $this->translator->trans('without data'),
'_header' => $this->translator->trans('Nationality'),
];
foreach ($countries as $row) {
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
}
}
if ('continent' === $data['group_by_level']) {
$labels = [
'EU' => $this->translator->trans('Europe'),
@@ -149,9 +151,10 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
];
}
return static function (string $value) use ($labels): string {
return function ($value) use ($labels): string {
return $labels[$value];
};
}
public function getQueryKeys($data)

View File

@@ -1,86 +0,0 @@
<?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

@@ -12,9 +12,9 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -22,11 +22,12 @@ final class ActionTypeAggregator implements AggregatorInterface
{
private SocialActionRepository $socialActionRepository;
private SocialActionRender $socialActionRender;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(SocialActionRepository $socialActionRepository)
public function __construct(SocialActionRepository $socialActionRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->socialActionRepository = $socialActionRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
@@ -69,7 +70,7 @@ final class ActionTypeAggregator implements AggregatorInterface
$sa = $this->socialActionRepository->find($value);
return $sa->getTitle()['fr'];
return $this->translatableStringHelper->localize($sa->getTitle());
};
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
use Doctrine\ORM\QueryBuilder;
@@ -21,9 +22,12 @@ final class GoalAggregator implements AggregatorInterface
{
private GoalRepository $goalRepository;
public function __construct(GoalRepository $goalRepository)
private TranslatableStringHelper $translatableStringHelper;
public function __construct(GoalRepository $goalRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->goalRepository = $goalRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
@@ -65,7 +69,7 @@ final class GoalAggregator implements AggregatorInterface
$g = $this->goalRepository->find($value);
return $g->getTitle()['fr'];
return $this->translatableStringHelper->localize($g->getTitle());
};
}

View File

@@ -33,8 +33,8 @@ final class ResultAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.results', 'r');
$qb->addSelect('r.id as result_aggregator');
$qb->join('acpw.results', 'res');
$qb->addSelect('res.id as result_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@@ -65,7 +65,7 @@ final class ResultAggregator implements AggregatorInterface
$g = $this->resultRepository->find($value);
return $g->getTitle()['fr'];
return $this->translatableStringHelper->localize($g->getTitle());
};
}

View File

@@ -1,65 +0,0 @@
<?php
// TODO move to vendee root folder
/**
* 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\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr\Andx;
class EntrustedChildFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('App:VendeePersonMineur', 'vpm');
$qb->join('vpm.person', 'person');
$qb->join('person.center', 'center');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('vpm.enfantConfie', 'true');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by entrusted child status'];
}
public function getTitle()
{
return 'Filter by entrusted child status';
}
}

View File

@@ -1,64 +0,0 @@
<?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.
*/
// TODO move to vendee root folder
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
class NomadicFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('App:VendeePerson', 'vp');
$qb->join('vp.person', 'person');
$qb->join('person.center', 'center');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('vp.gensDuVoyage', 'true');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by nomadic status'];
}
public function getTitle()
{
return 'Filter by nomadic status';
}
}

View File

@@ -0,0 +1,87 @@
<?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\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use DateTime;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class ResidentialAddressAtThirdpartyFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('thirdparty_type', EntityType::class, [
'class' => ThirdPartyCategory::class,
'choice_label' => function (ThirdPartyCategory $tpc) {
return $this->translatableStringHelper->localize($tpc->getName());
},
'multiple' => true,
'expanded' => true
]);
$builder->add('date_calc', ChillDateType::class, [
'label' => 'Date during which residential address was valid',
'data' => new DateTime('now'),
]);
}
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');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->isNotNull('ra.hostThirdparty'),
// $qb->expr()->in('thirdparty.categories')
);
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%'];
}
public function getTitle()
{
return 'Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type%';
}
}

View File

@@ -26,7 +26,7 @@ class ResidentialAddressAtUserFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('ChillPersonBundle:Person:ResidentialAddress', 'ra');
$qb->from('ChillPersonBundle:Person\ResidentialAddress', 'ra');
$qb->join('ra.person', 'person');
$qb->join('person.center', 'center');
@@ -42,7 +42,6 @@ class ResidentialAddressAtUserFilter implements FilterInterface
$qb->add('where', $where);
dump($qb->getQuery());
}
public function applyOn()

View File

@@ -3,6 +3,7 @@
namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
@@ -12,117 +13,27 @@ use Symfony\Component\Form\FormBuilderInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Event\PostSetDataEvent;
use Symfony\Component\Form\Event\PostSubmitEvent;
use Symfony\Component\Form\Event\PreSetDataEvent;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormInterface;
class SocialWorkTypeFilter implements FilterInterface
{
private SocialActionRender $socialActionRender;
public function __construct(SocialActionRender $socialActionRender)
private TranslatableStringHelper $translatableStringHelper;
public function __construct(SocialActionRender $socialActionRender, TranslatableStringHelper $translatableStringHelper)
{
$this->socialActionRender = $socialActionRender;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder)
{
/**
* EXAMPLE CODE TO INSPIRE
*/
// parent::buildForm($builder, $options);
// //other fields
// $builder->add('country', 'entity', array(
// 'class' => 'Orfos\CoreBundle\Entity\Country',
// 'property' => $locale . 'name',
// 'label' => 'register.country.label',
// 'query_builder' => function(EntityRepository $er) {
// return $er->createQueryBuilder('c')
// ->select('c', 't')
// ->join('c.translations', 't');
// },
// ));
// $factory = $builder->getFormFactory();
// $refreshRegion = function ($form, $country) use ($factory, $locale) {
// $form->add($factory->createNamed('entity', 'region', null, array(
// 'class' => 'Orfos\CoreBundle\Entity\Region',
// 'property' => $locale . 'name',
// 'label' => 'register.region.label',
// 'query_builder' => function (EntityRepository $repository) use ($country) {
// $qb = $repository->createQueryBuilder('region')
// ->select('region', 'translation')
// ->innerJoin('region.country', 'country')
// ->join('region.translations', 'translation');
// if ($country instanceof Country) {
// $qb = $qb->where('region.country = :country')
// ->setParameter('country', $country);
// } elseif (is_numeric($country)) {
// $qb = $qb->where('country.id = :country_id')
// ->setParameter('country_id', $country);
// } else {
// $qb = $qb->where('country.id = 1');
// }
// return $qb;
// }
// )));
// };
// $factory = $builder->getFormFactory();
// $refreshCity = function($form, $region) use ($factory, $locale) {
// $form->add($factory->createNamed('entity', 'city', null, array(
// 'class' => 'Orfos\CoreBundle\Entity\City',
// 'property' => $locale . 'name',
// 'label' => 'register.city.label',
// 'query_builder' => function (EntityRepository $repository) use ($region) {
// $qb = $repository->createQueryBuilder('city')
// ->select('city', 'translation')
// ->innerJoin('city.region', 'region')
// ->innerJoin('city.translations', 'translation');
// if ($region instanceof Region) {
// $qb = $qb->where('city.region = :region')
// ->setParameter('region', $region);
// } elseif (is_numeric($region)) {
// $qb = $qb->where('region.id = :region_id')
// ->setParameter('region_id', $region);
// } else {
// $qb = $qb->where('region.id = 1');
// }
// return $qb;
// }
// )));
// };
// $builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use ($refreshRegion, $refreshCity) {
// $form = $event->getForm();
// $data = $event->getData();
// if ($data == null){
// $refreshRegion($form, null);
// $refreshCity($form, null);
// }
// if ($data instanceof Country) {
// $refreshRegion($form, $data->getCountry()->getRegions());
// $refreshCity($form, $data->getRegion()->getCities());
// }
// });
// $builder->addEventListener(FormEvents::PRE_BIND, function (DataEvent $event) use ($refreshRegion, $refreshCity) {
// $form = $event->getForm();
// $data = $event->getData();
// if (array_key_exists('country', $data)) {
// $refreshRegion($form, $data['country']);
// }
// if (array_key_exists('region', $data)) {
// $refreshCity($form, $data['region']);
// }
// });
$builder->add('actionType', EntityType::class, [
'class' => SocialAction::class,
@@ -133,45 +44,39 @@ class SocialWorkTypeFilter implements FilterInterface
'expanded' => true
]);
$refreshGoals = function ($form, $actionType) {
$refreshGoals = function (FormInterface $form, SocialAction $actionType = null) {
$goals = null === $actionType ? [] : $actionType->getGoals();
$form->add('goal', EntityType::class, [
'class' => Goal::class,
'placeholder' => '',
'choices' => $goals,
'choice_label' => function (Goal $g) {
return $g->getTitle();
return $this->translatableStringHelper->localize($g->getTitle());
},
'query_builder' => function (EntityRepository $repository) use ($actionType) {
$qb = $repository->createQueryBuilder('g')
->select('g')
->join('g.socialActions', 'socialActions');
if ($actionType instanceof SocialAction) {
$qb = $qb->where(
$qb->expr()->andX(
$qb->expr()->in('g', ':socialActions')
))
->setParameter('country', $actionType);
}
dump($qb->getQuery()->getResult());
return $qb;
}
]);
};
};
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (PreSetDataEvent $event) use ($refreshGoals) {
$builder->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) use ($refreshGoals) {
dump($event);
$form = $event->getForm();
$data = $event->getData();
if ($data == null){
$refreshGoals($form, null);
}
if ($data instanceof SocialAction) {
$refreshGoals($form, $data->getGoals());
// $refreshCity($form, $data->getRegion()->getCities());
}
$refreshGoals($form, $data);
});
$builder->get('actionType')->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) use ($refreshGoals) {
$actionType = $event->getForm()->getData();
dump('after submit listener');
dump($actionType);
$refreshGoals($event->getForm()->getParent(), $actionType);
}
);
}
public function getTitle(): string