mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
user scope and job filter on socialwork actions
This commit is contained in:
parent
455a50d292
commit
5c82ccc49d
100
src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php
Normal file
100
src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?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\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\Component\Security\Core\Security;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
class UserJobFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
protected TranslatorInterface $translator;
|
||||||
|
|
||||||
|
private TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
TranslatableStringHelper $translatableStringHelper
|
||||||
|
) {
|
||||||
|
$this->translator = $translator;
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder->add('userjob', EntityType::class, [
|
||||||
|
'class' => UserJob::class,
|
||||||
|
'choice_label' => function (UserJob $j) {
|
||||||
|
return $this->translatableStringHelper->localize(
|
||||||
|
$j->getLabel()
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
$userjobs = [];
|
||||||
|
|
||||||
|
foreach ($data['userjob'] as $j) {
|
||||||
|
$userjobs[] = $this->translatableStringHelper->localize(
|
||||||
|
$j->getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['Filtered by the following jobs: only %userjobs%', [
|
||||||
|
'%userjobs%' => implode(', ou ', $userjobs)
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRole()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
$qb->join('acpw.referrers', 'r');
|
||||||
|
|
||||||
|
$where = $qb->getDQLPart('where');
|
||||||
|
$clause = $qb->expr()->eq('r.userJob', ':userjob');
|
||||||
|
|
||||||
|
if ($where instanceof Andx) {
|
||||||
|
$where->add($clause);
|
||||||
|
} else {
|
||||||
|
$where = $qb->expr()->andX($clause);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->add('where', $where);
|
||||||
|
$qb->setParameter('userjob', $data['userjob']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return 'Filter by job';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
<?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\MainBundle\Entity\Scope;
|
||||||
|
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 UserScopeFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
protected TranslatorInterface $translator;
|
||||||
|
|
||||||
|
private TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TranslatorInterface $translator,
|
||||||
|
TranslatableStringHelper $translatableStringHelper
|
||||||
|
) {
|
||||||
|
$this->translator = $translator;
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder->add('scope', EntityType::class, [
|
||||||
|
'class' => Scope::class,
|
||||||
|
'choice_label' => function (Scope $s) {
|
||||||
|
return $this->translatableStringHelper->localize(
|
||||||
|
$s->getName()
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
$scopes = [];
|
||||||
|
|
||||||
|
foreach ($data['scope'] as $s) {
|
||||||
|
$scopes[] = $this->translatableStringHelper->localize(
|
||||||
|
$s->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['Filtered by the following scopes: only %scope%', [
|
||||||
|
'%scope%' => implode(', ou ', $scopes)
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRole()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
$qb->join('acpw.referrers', 'r');
|
||||||
|
|
||||||
|
$where = $qb->getDQLPart('where');
|
||||||
|
$clause = $qb->expr()->eq('r.mainScope', ':scope');
|
||||||
|
|
||||||
|
if ($where instanceof Andx) {
|
||||||
|
$where->add($clause);
|
||||||
|
} else {
|
||||||
|
$where = $qb->expr()->andX($clause);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->add('where', $where);
|
||||||
|
$qb->setParameter('scope', $data['scope']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return 'Filter by scope';
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export, alias: count_social_work_actions }
|
- { name: chill.export, alias: count_social_work_actions }
|
||||||
|
|
||||||
|
## FILTERS
|
||||||
chill.person.export.filter_referrers:
|
chill.person.export.filter_referrers:
|
||||||
class: Chill\PersonBundle\Export\Filter\ReferrerFilter
|
class: Chill\PersonBundle\Export\Filter\ReferrerFilter
|
||||||
autowire: true
|
autowire: true
|
||||||
@ -14,9 +15,23 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: social_work_actions_referrer_filter }
|
- { name: chill.export_filter, alias: social_work_actions_referrer_filter }
|
||||||
|
|
||||||
chill.person.export.filter_social_work_type:
|
# chill.person.export.filter_social_work_type:
|
||||||
class: Chill\PersonBundle\Export\Filter\SocialWorkTypeFilter
|
# class: Chill\PersonBundle\Export\Filter\SocialWorkTypeFilter
|
||||||
|
# autowire: true
|
||||||
|
# autoconfigure: true
|
||||||
|
# tags:
|
||||||
|
# - { name: chill.export_filter, alias: social_work_type_filter }
|
||||||
|
|
||||||
|
chill.person.export.filter_userscope:
|
||||||
|
class: Chill\PersonBundle\Export\Filter\UserScopeFilter
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: social_work_type_filter }
|
- { name: chill.export_filter, alias: social_work_actions_userscope_filter }
|
||||||
|
|
||||||
|
chill.person.export.filter_userjob:
|
||||||
|
class: Chill\PersonBundle\Export\Filter\UserJobFilter
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
tags:
|
||||||
|
- { name: chill.export_filter, alias: social_work_actions_userjob_filter }
|
Loading…
x
Reference in New Issue
Block a user