mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
exports: add new social issues filter (wip)
This commit is contained in:
parent
b608976326
commit
bb22317eb1
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class SocialIssueFilter implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_socialissue', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'choice_label' => function(SocialIssue $s) {
|
||||
return $this->translatableStringHelper->localize($s->getTitle());
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Filter by social issue';
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
foreach ($data['accepted_socialissue'] as $i) {
|
||||
if ('null' === $i) {
|
||||
$issues[] = $this->translator->trans('Not given');
|
||||
} else {
|
||||
$issues[] = $this->translatableStringHelper->localize($i->getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'Filtered by socialissues: only %socialissues%', [
|
||||
'%socialissues%' => implode(', ', $issues)
|
||||
]];
|
||||
}
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb->join('acp.socialIssues', 's');
|
||||
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('s.id', ':socialissues');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('socialissues', $data['accepted_socialissue']);
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
{
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -73,6 +73,13 @@ services:
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_userjob_filter }
|
||||
|
||||
chill.person.export.filter_socialissue:
|
||||
class: Chill\PersonBundle\Export\Filter\SocialIssueFilter
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_socialissue_filter }
|
||||
|
||||
chill.person.export.filter_step:
|
||||
class: Chill\PersonBundle\Export\Filter\StepFilter
|
||||
autowire: true
|
||||
|
@ -384,6 +384,10 @@ Filter by user job: Filtrer par métier du référent
|
||||
Accepted userjob: Métiers
|
||||
"Filtered by user jobs: only %jobs%": "Filtré par métier du référent: uniquement %jobs%"
|
||||
|
||||
Filter by social issue: Filtrer par problématiques sociales
|
||||
Accepted socialissue: Problématiques sociales
|
||||
"Filtered by socialissues: only %socialissues%": "Filtré par problématique sociale: uniquement %socialissues%"
|
||||
|
||||
Filter by step: Filtrer par statut du parcours
|
||||
Accepted step: Statuts
|
||||
"Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%"
|
||||
|
Loading…
x
Reference in New Issue
Block a user