mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
[export] fix 4 job/scope filters in activity and acp
This commit is contained in:
@@ -11,19 +11,29 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use function in_array;
|
||||
|
||||
class CreatorJobFilter implements FilterInterface
|
||||
{
|
||||
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly UserJobRepositoryInterface $userJobRepository) {}
|
||||
private const PREFIX = 'acp_filter_creator_job';
|
||||
|
||||
public function __construct(
|
||||
private readonly RollingDateConverter $rollingDateConverter,
|
||||
private readonly TranslatableStringHelper $translatableStringHelper,
|
||||
private readonly UserJobRepositoryInterface $userJobRepository
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -32,13 +42,30 @@ class CreatorJobFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('acp_creator', $qb->getAllAliases(), true)) {
|
||||
$qb->join('acp.createdBy', 'acp_creator');
|
||||
}
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb
|
||||
->andWhere($qb->expr()->in('acp_creator.userJob', ':creator_job'))
|
||||
->setParameter('creator_job', $data['creator_job']);
|
||||
->join("acp.createdBy", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserJobHistory::class,
|
||||
"{$p}_history",
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere($qb->expr()->in("{$p}_history.job", ":{$p}_jobs"))
|
||||
->setParameters([
|
||||
"{$p}_jobs" => $data["creator_job"],
|
||||
"{$p}_at" => $this->rollingDateConverter->convert($data["job_at"])
|
||||
]);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -48,20 +75,21 @@ class CreatorJobFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('creator_job', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choices' => $this->userJobRepository->findAllActive(),
|
||||
'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'Job',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
$builder
|
||||
->add('creator_job', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choices' => $this->userJobRepository->findAllActive(),
|
||||
'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'label' => 'Job',
|
||||
])
|
||||
->add('job_at', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.course.creator_job.Calc date',
|
||||
'required' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
@@ -79,8 +107,16 @@ class CreatorJobFilter implements FilterInterface
|
||||
]];
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [
|
||||
'creator_job' => [],
|
||||
'job_at' => new RollingDate(RollingDate::T_TODAY)
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Filter by creator job';
|
||||
return 'export.filter.course.creator_job.Filter by creator job';
|
||||
}
|
||||
}
|
||||
|
@@ -571,8 +571,6 @@ Filtered acp which has no actions: 'Filtré: uniquement les parcours qui n''ont
|
||||
Group by number of actions: Grouper les parcours par nombre d’actions
|
||||
Filter by creator: Filtrer les parcours par créateur
|
||||
'Filtered by creator: only %creators%': 'Filtré par créateur: uniquement %creators%'
|
||||
Filter by creator job: Filtrer les parcours par métier du créateur
|
||||
'Filtered by creator job: only %jobs%': 'Filtré par métier du créateur: uniquement %jobs%'
|
||||
|
||||
Filter actions without end date: Filtre les actions sans date de fin (ouvertes)
|
||||
Filtered actions without end date: 'Filtré: uniquement les actions sans date de fin (ouvertes)'
|
||||
@@ -1135,7 +1133,9 @@ export:
|
||||
Having a person's location: Ayant une localisation auprès d'un usager
|
||||
Calculation date: Date de la localisation
|
||||
creator_job:
|
||||
'Filtered by creator job: only %jobs%': 'Filtré par métier du créateur: seulement %jobs%'
|
||||
Filter by creator job: Filtrer les parcours par métier du créateur
|
||||
'Filtered by creator job: only %jobs%': "Filtré par métier du créateur: uniquement %jobs%"
|
||||
Calc date: Date de calcul du métier du créateur
|
||||
by_user_job:
|
||||
Filter by user job: Filtrer les parcours par métier du référent
|
||||
"Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%"
|
||||
|
Reference in New Issue
Block a user