mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-06 20:28:25 +00:00
Fix case where no 'reason' is picked within the PersonHavingActivityBetweenDateFilter.php
This commit is contained in:
6
.changes/unreleased/Fixed-20251027-124814.yaml
Normal file
6
.changes/unreleased/Fixed-20251027-124814.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
kind: Fixed
|
||||
body: Fix export case where no 'reason' is picked within the PersonHavingActivityBetweenDateFilter.php
|
||||
time: 2025-10-27T12:48:14.851325971+01:00
|
||||
custom:
|
||||
Issue: ""
|
||||
SchemaChange: No schema change
|
||||
@@ -90,7 +90,9 @@ class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInt
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
'reasons' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function describeAction($data, ExportGenerationContext $context): string|\Symfony\Contracts\Translation\TranslatableInterface|array
|
||||
|
||||
@@ -42,6 +42,8 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data, ExportGenerationContext $exportGenerationContext): void
|
||||
{
|
||||
error_log('alterQuery called with data: '.json_encode(array_keys($data)));
|
||||
|
||||
// create a subquery for activity
|
||||
$sqb = $qb->getEntityManager()->createQueryBuilder();
|
||||
$sqb->select('1')
|
||||
@@ -59,7 +61,6 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
if (\in_array('activity', $qb->getAllAliases(), true)) {
|
||||
$sqb->andWhere('activity_person_having_activity.id = activity.id');
|
||||
}
|
||||
|
||||
if (isset($data['reasons']) && [] !== $data['reasons']) {
|
||||
// add clause activity reason
|
||||
$sqb->join('activity_person_having_activity.reasons', 'reasons_person_having_activity');
|
||||
@@ -124,12 +125,38 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
|
||||
public function normalizeFormData(array $formData): array
|
||||
{
|
||||
return ['date_from_rolling' => $formData['date_from_rolling']->normalize(), 'date_to_rolling' => $formData['date_to_rolling']->normalize()];
|
||||
$normalized = [
|
||||
'date_from_rolling' => $formData['date_from_rolling']->normalize(),
|
||||
'date_to_rolling' => $formData['date_to_rolling']->normalize(),
|
||||
'reasons' => [],
|
||||
];
|
||||
|
||||
if (isset($formData['reasons']) && [] !== $formData['reasons']) {
|
||||
$normalized['reasons'] = array_map(
|
||||
fn (ActivityReason $reason) => $reason->getId(),
|
||||
$formData['reasons']
|
||||
);
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
public function denormalizeFormData(array $formData, int $fromVersion): array
|
||||
{
|
||||
return ['date_from_rolling' => RollingDate::fromNormalized($formData['date_from_rolling']), 'date_to_rolling' => RollingDate::fromNormalized($formData['date_to_rolling'])];
|
||||
$denormalized = [
|
||||
'date_from_rolling' => RollingDate::fromNormalized($formData['date_from_rolling']),
|
||||
'date_to_rolling' => RollingDate::fromNormalized($formData['date_to_rolling']),
|
||||
'reasons' => [],
|
||||
];
|
||||
|
||||
if (isset($formData['reasons']) && [] !== $formData['reasons']) {
|
||||
$denormalized['reasons'] = array_map(
|
||||
fn ($id) => $this->activityReasonRepository->find($id),
|
||||
$formData['reasons']
|
||||
);
|
||||
}
|
||||
|
||||
return $denormalized;
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
@@ -143,10 +170,12 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
|
||||
public function describeAction($data, ExportGenerationContext $context): array
|
||||
{
|
||||
$reasons = $data['reasons'] ?? [];
|
||||
|
||||
return [
|
||||
[] === $data['reasons'] ?
|
||||
'export.filter.person_between_dates.describe_action_with_no_subject'
|
||||
: 'export.filter.person_between_dates.describe_action_with_subject',
|
||||
[] === $reasons ?
|
||||
'export.filter.activity.describe_action_with_no_subject'
|
||||
: 'export.filter.activity.describe_action_with_subject',
|
||||
[
|
||||
'date_from' => $this->rollingDateConverter->convert($data['date_from_rolling']),
|
||||
'date_to' => $this->rollingDateConverter->convert($data['date_to_rolling']),
|
||||
@@ -154,7 +183,7 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
', ',
|
||||
array_map(
|
||||
fn (ActivityReason $r): string => '"'.$this->translatableStringHelper->localize($r->getName()).'"',
|
||||
$data['reasons']
|
||||
$reasons
|
||||
)
|
||||
),
|
||||
],
|
||||
@@ -168,6 +197,7 @@ final readonly class PersonHavingActivityBetweenDateFilter implements ExportElem
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context): void
|
||||
{
|
||||
error_log('validateForm called with data: '.json_encode(array_keys($data)));
|
||||
if ($this->rollingDateConverter->convert($data['date_from_rolling'])
|
||||
>= $this->rollingDateConverter->convert($data['date_to_rolling'])) {
|
||||
$context->buildViolation('export.filter.activity.person_between_dates.date mismatch')
|
||||
|
||||
Reference in New Issue
Block a user