mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33:49 +00:00
Add dates in the filter "filter course by activity type"
This commit is contained in:
@@ -15,17 +15,22 @@ use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\ActivityBundle\Entity\ActivityType;
|
||||
use Chill\ActivityBundle\Repository\ActivityTypeRepositoryInterface;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class ActivityTypeFilter implements FilterInterface
|
||||
final readonly class ActivityTypeFilter implements FilterInterface
|
||||
{
|
||||
private const BASE_EXISTS = 'SELECT 1 FROM '.Activity::class.' act_type_filter_activity WHERE act_type_filter_activity.accompanyingPeriod = acp';
|
||||
|
||||
public function __construct(
|
||||
private readonly ActivityTypeRepositoryInterface $activityTypeRepository,
|
||||
private readonly TranslatableStringHelperInterface $translatableStringHelper
|
||||
private ActivityTypeRepositoryInterface $activityTypeRepository,
|
||||
private TranslatableStringHelperInterface $translatableStringHelper,
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
@@ -35,13 +40,26 @@ class ActivityTypeFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb->andWhere(
|
||||
$qb->expr()->exists(
|
||||
'SELECT 1 FROM '.Activity::class.' act_type_filter_activity
|
||||
WHERE act_type_filter_activity.activityType IN (:act_type_filter_activity_types) AND act_type_filter_activity.accompanyingPeriod = acp'
|
||||
)
|
||||
);
|
||||
$qb->setParameter('act_type_filter_activity_types', $data['accepted_activitytypes']);
|
||||
$exists = self::BASE_EXISTS;
|
||||
|
||||
if (count($data['accepted_activitytypes']) > 0) {
|
||||
$exists .= ' AND act_type_filter_activity.activityType IN (:act_type_filter_activity_types)';
|
||||
$qb->setParameter('act_type_filter_activity_types', $data['accepted_activitytypes']);
|
||||
}
|
||||
|
||||
if (null !== $data['date_after']) {
|
||||
$exists .= ' AND act_type_filter_activity.date >= :act_type_filter_activity_date_after';
|
||||
$qb->setParameter('act_type_filter_activity_date_after', $this->rollingDateConverter->convert($data['date_after']));
|
||||
}
|
||||
|
||||
if (null !== $data['date_before']) {
|
||||
$exists .= ' AND act_type_filter_activity.date >= :act_type_filter_activity_date_before';
|
||||
$qb->setParameter('act_type_filter_activity_date_before', $this->rollingDateConverter->convert($data['date_before']));
|
||||
}
|
||||
|
||||
if (self::BASE_EXISTS !== $exists) {
|
||||
$qb->andWhere($qb->expr()->exists($exists));
|
||||
}
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
@@ -60,11 +78,27 @@ class ActivityTypeFilter implements FilterInterface
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
|
||||
$builder->add('date_after', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.activity.acp_by_activity_type.activity after',
|
||||
'help' => 'export.filter.activity.acp_by_activity_type.activity after help',
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('date_before', PickRollingDateType::class, [
|
||||
'label' => 'export.filter.activity.acp_by_activity_type.activity before',
|
||||
'help' => 'export.filter.activity.acp_by_activity_type.activity before help',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'accepted_activitytypes' => [],
|
||||
'date_after' => null,
|
||||
'date_before' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
@@ -75,8 +109,12 @@ class ActivityTypeFilter implements FilterInterface
|
||||
$types[] = $this->translatableStringHelper->localize($aty->getName());
|
||||
}
|
||||
|
||||
return ['export.filter.activity.acp_by_activity_type.acp_containing_at_least_one_%activitytypes%', [
|
||||
'%activitytypes%' => implode(', ', $types),
|
||||
return ['export.filter.activity.acp_by_activity_type.acp_containing_at_least_one_activitytypes', [
|
||||
'activitytypes' => implode(', ', $types),
|
||||
'has_date_after' => null !== $data['date_after'] ? 1 : 0,
|
||||
'date_after' => $this->rollingDateConverter->convert($data['date_after']),
|
||||
'has_date_before' => null !== $data['date_before'] ? 1 : 0,
|
||||
'date_before' => $this->rollingDateConverter->convert($data['date_before']),
|
||||
]];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user