mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
exports: add a new user scope filter
This commit is contained in:
parent
34923df43c
commit
881e608c87
@ -19,4 +19,6 @@ abstract class Declarations
|
||||
public const PERSON_IMPLIED_IN = 'person_implied_in';
|
||||
|
||||
public const PERSON_TYPE = 'person';
|
||||
|
||||
public const ACP_TYPE = 'accompanying_period';
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Chill\MainBundle\Export\ExportInterface;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
@ -82,7 +83,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return 'accompanying_period';
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
|
||||
@ -107,7 +108,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
|
||||
|
||||
public function supportsModifiers(): array
|
||||
{
|
||||
return [];
|
||||
return [Declarations::ACP_TYPE];
|
||||
}
|
||||
|
||||
public function getGroup(): string
|
||||
|
@ -15,6 +15,7 @@ use Chill\MainBundle\Export\ExportInterface;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\Query;
|
||||
@ -109,7 +110,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return 'accompanying_course';
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +153,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
|
||||
*/
|
||||
public function supportsModifiers(): array
|
||||
{
|
||||
return [];
|
||||
return [Declarations::ACP_TYPE];
|
||||
}
|
||||
|
||||
public function getGroup(): string
|
||||
|
101
src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php
Normal file
101
src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?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\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
|
||||
{
|
||||
/**
|
||||
* @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 scopes'];
|
||||
}
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb
|
||||
->join('acp.user', 'u')
|
||||
->join('u.mainScope', 's')
|
||||
;
|
||||
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('u.mainScope', ':userscope');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('userscope', $data['accepted_userscope']);
|
||||
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
{
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('accepted_userscope', EntityType::class, [
|
||||
'class' => Scope::class,
|
||||
'choice_label' => function(Scope $s) {
|
||||
return $this->translatableStringHelper->localize($s->getName());
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'Filter by user scope';
|
||||
}
|
||||
}
|
@ -26,19 +26,19 @@ services:
|
||||
tags:
|
||||
- { name: chill.export, alias: list_person_duplicate }
|
||||
|
||||
chill.person.export.count_accompanying_course:
|
||||
chill.person.export.count_accompanyingcourse:
|
||||
class: Chill\PersonBundle\Export\Export\CountAccompanyingCourse
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
tags:
|
||||
- { name: chill.export, alias: count_accompanying_course }
|
||||
- { name: chill.export, alias: count_accompanyingcourse }
|
||||
|
||||
chill.person.export.avg_accompanying_course_duration:
|
||||
chill.person.export.avg_accompanyingcourse_duration:
|
||||
class: Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration
|
||||
arguments:
|
||||
- '@Chill\PersonBundle\Repository\AccompanyingPeriodRepository'
|
||||
tags:
|
||||
- { name: chill.export, alias: avg_accompanying_course_duration }
|
||||
- { name: chill.export, alias: avg_accompanyingcourse_duration }
|
||||
|
||||
chill.person.export.filter_gender:
|
||||
class: Chill\PersonBundle\Export\Filter\GenderFilter
|
||||
@ -58,6 +58,14 @@ services:
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: person_nationality_filter }
|
||||
|
||||
chill.person.export.filter_userscope:
|
||||
class: Chill\PersonBundle\Export\Filter\UserScopeFilter
|
||||
arguments:
|
||||
$translator: '@translator'
|
||||
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_userscope_filter }
|
||||
|
||||
chill.person.export.aggregator_nationality:
|
||||
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator
|
||||
|
@ -376,6 +376,10 @@ Having an accompanying period closed after this date: Ayant une période d'accom
|
||||
"Having an accompanying period closed before this date": "Ayant une période d'accompagnement fermée avant cette date"
|
||||
"Filtered by accompanying period: persons having an accompanying period closed between the %date_from% and %date_to%": "Filtrer par période d'accompagnement: ayant une période fermée entre le %date_from% et le %date_to%"
|
||||
|
||||
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
|
||||
|
||||
## aggregators
|
||||
Group people by nationality: Aggréger les personnes par nationalités
|
||||
Group by level: Grouper par niveau
|
||||
|
Loading…
x
Reference in New Issue
Block a user