feat: default statistics filter to a rolling 12-month window

This commit is contained in:
2026-09-01 09:45:53 +02:00
parent 410c99a9b0
commit f6667dcfc7
10 changed files with 114 additions and 36 deletions
@@ -35,8 +35,8 @@ class ApplicationsByDestinationController extends AbstractController
}
$statistics = $this->applicationRepository->getApplicationsByDestination(
$filterDto->getDateFrom(),
$filterDto->getDateTo(),
$filterDto->getEffectiveDateFrom(),
$filterDto->getEffectiveDateTo(),
);
return $this->render('administrative/statistics/applications_by_destination.html.twig', [
@@ -35,8 +35,8 @@ class FeedbackByDestinationController extends AbstractController
}
$statistics = $this->dispositionRepository->getFeedbackStatisticsByNormalizedHotelCode(
$filterDto->getDateFrom(),
$filterDto->getDateTo(),
$filterDto->getEffectiveDateFrom(),
$filterDto->getEffectiveDateTo(),
);
return $this->render('administrative/statistics/feedback_by_destination.html.twig', [
@@ -35,8 +35,8 @@ class FeedbackRatingsByDestinationController extends AbstractController
}
$statistics = $this->feedbackRepository->getAverageRatingsByDestinationAndFeedbackSet(
$filterDto->getDateFrom(),
$filterDto->getDateTo(),
$filterDto->getEffectiveDateFrom(),
$filterDto->getEffectiveDateTo(),
);
return $this->render('administrative/statistics/feedback_ratings_by_destination.html.twig', [
@@ -35,8 +35,8 @@ class FeedbackRatingsController extends AbstractController
}
$statistics = $this->feedbackRepository->getAverageRatingsByQuestionAndFeedbackSet(
$filterDto->getDateFrom(),
$filterDto->getDateTo(),
$filterDto->getEffectiveDateFrom(),
$filterDto->getEffectiveDateTo(),
);
// Prepare chart data for each feedback set
+23
View File
@@ -32,4 +32,27 @@ class StatisticsFilterDto extends AbstractFilterDto
return $this;
}
/**
* The lower bound actually applied to a query: the picked date, or a rolling
* 12-month window ending today when nothing is picked.
*
* The default lives here rather than in a nullable property so that
* AbstractFilterDto::isActive() still sees a fresh instance as "not filtered"
* (it compares properties with !==, which no two DateTimeImmutable share).
*/
public function getEffectiveDateFrom(): \DateTimeImmutable
{
return $this->dateFrom ?? (new \DateTimeImmutable('today'))->modify('-12 months');
}
public function getEffectiveDateTo(): \DateTimeImmutable
{
return $this->dateTo ?? new \DateTimeImmutable('today 23:59:59');
}
public function isUsingDefaultRange(): bool
{
return null === $this->dateFrom && null === $this->dateTo;
}
}
@@ -24,13 +24,12 @@
{{ form_end(form) }}
</div>
{% if filterDto.active %}
<p class="text-sm text-gray-600 mb-4">
Filter aktiv:
{% if filterDto.dateFrom %}von {{ filterDto.dateFrom|date('d.m.Y') }}{% endif %}
{% if filterDto.dateTo %}bis {{ filterDto.dateTo|date('d.m.Y') }}{% endif %}
</p>
{% endif %}
<p class="text-sm text-gray-600 mb-4">
Zeitraum: {{ filterDto.effectiveDateFrom|date('d.m.Y') }} &ndash; {{ filterDto.effectiveDateTo|date('d.m.Y') }}
<span class="text-gray-400">
{% if filterDto.usingDefaultRange %}(Standard: letzte 12 Monate){% else %}(Filter aktiv){% endif %}
</span>
</p>
{% if statistics is empty %}
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
@@ -24,13 +24,12 @@
{{ form_end(form) }}
</div>
{% if filterDto.active %}
<p class="text-sm text-gray-600 mb-4">
Filter aktiv:
{% if filterDto.dateFrom %}von {{ filterDto.dateFrom|date('d.m.Y') }}{% endif %}
{% if filterDto.dateTo %}bis {{ filterDto.dateTo|date('d.m.Y') }}{% endif %}
</p>
{% endif %}
<p class="text-sm text-gray-600 mb-4">
Zeitraum: {{ filterDto.effectiveDateFrom|date('d.m.Y') }} &ndash; {{ filterDto.effectiveDateTo|date('d.m.Y') }}
<span class="text-gray-400">
{% if filterDto.usingDefaultRange %}(Standard: letzte 12 Monate){% else %}(Filter aktiv){% endif %}
</span>
</p>
{% if statistics is empty %}
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
@@ -24,13 +24,12 @@
{{ form_end(form) }}
</div>
{% if filterDto.active %}
<p class="text-sm text-gray-600 mb-4">
Filter aktiv:
{% if filterDto.dateFrom %}von {{ filterDto.dateFrom|date('d.m.Y') }}{% endif %}
{% if filterDto.dateTo %}bis {{ filterDto.dateTo|date('d.m.Y') }}{% endif %}
</p>
{% endif %}
<p class="text-sm text-gray-600 mb-4">
Zeitraum: {{ filterDto.effectiveDateFrom|date('d.m.Y') }} &ndash; {{ filterDto.effectiveDateTo|date('d.m.Y') }}
<span class="text-gray-400">
{% if filterDto.usingDefaultRange %}(Standard: letzte 12 Monate){% else %}(Filter aktiv){% endif %}
</span>
</p>
{% if chartsData is empty %}
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
@@ -24,13 +24,12 @@
{{ form_end(form) }}
</div>
{% if filterDto.active %}
<p class="text-sm text-gray-600 mb-4">
Filter aktiv:
{% if filterDto.dateFrom %}von {{ filterDto.dateFrom|date('d.m.Y') }}{% endif %}
{% if filterDto.dateTo %}bis {{ filterDto.dateTo|date('d.m.Y') }}{% endif %}
</p>
{% endif %}
<p class="text-sm text-gray-600 mb-4">
Zeitraum: {{ filterDto.effectiveDateFrom|date('d.m.Y') }} &ndash; {{ filterDto.effectiveDateTo|date('d.m.Y') }}
<span class="text-gray-400">
{% if filterDto.usingDefaultRange %}(Standard: letzte 12 Monate){% else %}(Filter aktiv){% endif %}
</span>
</p>
{% if destinations is empty %}
<div class="bg-white rounded-lg shadow p-8 text-center text-gray-500">
+59
View File
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace App\Tests\Model;
use App\Model\StatisticsFilterDto;
use PHPUnit\Framework\TestCase;
class StatisticsFilterDtoTest extends TestCase
{
public function testFreshDtoFallsBackToARollingTwelveMonthWindow(): void
{
$dto = new StatisticsFilterDto();
$expectedFrom = (new \DateTimeImmutable('today'))->modify('-12 months');
$this->assertSame(
$expectedFrom->format('Y-m-d'),
$dto->getEffectiveDateFrom()->format('Y-m-d'),
);
$this->assertSame(
(new \DateTimeImmutable('today'))->format('Y-m-d'),
$dto->getEffectiveDateTo()->format('Y-m-d'),
);
$this->assertTrue($dto->isUsingDefaultRange());
$this->assertFalse($dto->isActive());
}
public function testAPickedLowerBoundStopsTheFromFallbackButNotTheToFallback(): void
{
$from = new \DateTimeImmutable('2025-03-01');
$dto = (new StatisticsFilterDto())->setDateFrom($from);
$this->assertSame($from, $dto->getEffectiveDateFrom());
$this->assertSame(
(new \DateTimeImmutable('today'))->format('Y-m-d'),
$dto->getEffectiveDateTo()->format('Y-m-d'),
);
$this->assertFalse($dto->isUsingDefaultRange());
$this->assertTrue($dto->isActive());
}
public function testBothBoundsPickedAreReturnedVerbatim(): void
{
$from = new \DateTimeImmutable('2025-01-01');
$to = new \DateTimeImmutable('2025-06-30');
$dto = (new StatisticsFilterDto())
->setDateFrom($from)
->setDateTo($to)
;
$this->assertSame($from, $dto->getEffectiveDateFrom());
$this->assertSame($to, $dto->getEffectiveDateTo());
$this->assertFalse($dto->isUsingDefaultRange());
}
}