exports: add a new user job filter

This commit is contained in:
Mathieu Jaumotte 2022-07-19 15:04:57 +02:00
parent 881e608c87
commit 70f118011b
4 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,102 @@
<?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;
use Chill\CustomFieldsBundle\Form\Type\ChoicesType;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
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 UserJobFilter 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 describeAction($data, $format = 'string')
{
// to complete..
return ['Filtered by user jobs'];
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
->join('acp.user', 'u')
->join('u.userJob', 'j')
;
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('u.userJob', ':userjob');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('userjob', $data['accepted_userjob']);
}
public function applyOn()
{
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('accepted_userjob', EntityType::class, [
'class' => UserJob::class,
'choice_label' => function(UserJob $j) {
return $this->translatableStringHelper->localize($j->getLabel());
},
'multiple' => true,
'expanded' => true,
])
;
}
public function getTitle()
{
return 'Filter by user job';
}
}

View File

@ -66,6 +66,14 @@ services:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags:
- { name: chill.export_filter, alias: accompanyingcourse_userscope_filter }
chill.person.export.filter_userjob:
class: Chill\PersonBundle\Export\Filter\UserJobFilter
arguments:
$translator: '@translator'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags:
- { name: chill.export_filter, alias: accompanyingcourse_userjob_filter }
chill.person.export.aggregator_nationality:
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator

View File

@ -380,6 +380,10 @@ Filter by user scope: Filtrer par service du référent
Accepted userscope: Services
Filtered by user scopes: Filtré par service du référent
Filter by user job: Filtrer par métier du référent
Accepted userjob: Métiers
Filtered by user jobs: Filtré par métier du référent
## aggregators
Group people by nationality: Aggréger les personnes par nationalités
Group by level: Grouper par niveau