mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
exports: add a new user scope filter
This commit is contained in:
@@ -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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user