From c60b5f653e5f3b5f0c645f9112997bed4ec84993 Mon Sep 17 00:00:00 2001 From: Tim Lappe Date: Sat, 15 Mar 2025 09:06:01 +0100 Subject: [PATCH] Show events in the past --- src/Controller/CalendarController.php | 10 ++--- src/Service/AbsenceManager.php | 2 +- templates/calendar/index.html.twig | 62 +++++++++++++++++++-------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/Controller/CalendarController.php b/src/Controller/CalendarController.php index fb903ee..1426853 100644 --- a/src/Controller/CalendarController.php +++ b/src/Controller/CalendarController.php @@ -28,8 +28,8 @@ final class CalendarController extends AbstractController return new Response('Kein Zugriff', Response::HTTP_FORBIDDEN); } - $startDate = (new DateTime())->format('Y-m-d'); - $endDate = (new DateTime('+90 days'))->format('Y-m-d'); + $startDate = (new DateTime('-1 day'))->format('Y-m-d'); + $endDate = (new DateTime('+180 days'))->format('Y-m-d'); $absences = $this->absenceManager->getAbsencesForUser('tim.lappe@check24.de', new DateTime('-1 day')); @@ -50,10 +50,10 @@ final class CalendarController extends AbstractController return new Response('Kein Zugriff', Response::HTTP_FORBIDDEN); } - $startDate = (new DateTime())->format('Y-m-d'); + $startDate = (new DateTime('-1 year'))->format('Y-m-d'); $endDate = (new DateTime('+180 days'))->format('Y-m-d'); - $absences = $this->absenceManager->getAbsencesForUser('tim.lappe@check24.de', new DateTime('-1 day')); + $absences = $this->absenceManager->getAbsencesForUser('tim.lappe@check24.de', new DateTime('-1 year')); $days = $this->calendarService->getAllDays($startDate, $endDate); $days = $this->calendarService->processAbsences($days, $absences); @@ -66,4 +66,4 @@ final class CalendarController extends AbstractController return $response; } -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/Service/AbsenceManager.php b/src/Service/AbsenceManager.php index d4a3d1c..3e91a38 100644 --- a/src/Service/AbsenceManager.php +++ b/src/Service/AbsenceManager.php @@ -25,7 +25,7 @@ final class AbsenceManager $response = $this->absenceClient->getAbsences([ 'skip' => 0, - 'limit' => 50, + 'limit' => 500, 'filter' => [ 'start' => ['$gte' => $startDate->format('Y-m-d\TH:i:s.u\Z')], 'assignedTo:user._id' => [ diff --git a/templates/calendar/index.html.twig b/templates/calendar/index.html.twig index ca84c94..92971c7 100644 --- a/templates/calendar/index.html.twig +++ b/templates/calendar/index.html.twig @@ -53,34 +53,58 @@
So
{% set currentMonth = null %} - {% set firstDay = days|first %} - {% if firstDay.weekday > 1 %} - {% if currentMonth != firstDay.date|date('F') %} - {% set currentMonth = firstDay.date|date('F') %} -
{{ firstDay.date|date('F Y') }}
- {% endif %} - {% for i in 1..firstDay.weekday - 1 %} -
- {% endfor %} - {% endif %} - + {% set currentWeek = null %} + {% for day in days %} - {% if currentMonth != day.date|date('F') %} - {% set currentMonth = day.date|date('F') %} + {# Check if month changed #} + {% if currentMonth != day.date|date('F Y') %} + {% set currentMonth = day.date|date('F Y') %}
{{ day.date|date('F Y') }}
+ + {# Add empty cells for first row of month #} + {% set dayWeekday = day.weekday %} + {% if dayWeekday > 1 %} + {% for i in 1..dayWeekday-1 %} +
+ {% endfor %} + {% endif %} {% endif %} + + {# Check if week changed #} + {% if currentWeek != day.weekNumber %} + {% set currentWeek = day.weekNumber %} + {% if day.weekday > 1 and not loop.first and currentMonth == day.date|date('F Y') %} + {# If it's not the first day overall and not the first day of a month, but it's the first day of a week #} + {% for i in 1..day.weekday-1 %} +
+ {% endfor %} + {% endif %} + {% endif %} + + {# Render the day #}
{{ day.date|date('d.m.Y') }}
{% if day.isFtk %}
FTK
{% endif %} {% if day.isUrlaub %}
Urlaub
{% endif %}
+ + {# After the last day of a month, fill remaining days in the week #} + {% set nextDay = days[loop.index] is defined ? days[loop.index] : null %} + {% if nextDay and nextDay.date|date('F Y') != day.date|date('F Y') %} + {% if day.weekday < 7 %} + {% for i in day.weekday+1..7 %} +
+ {% endfor %} + {% endif %} + {% endif %} + + {# After the very last day, fill remaining days in the week #} + {% if loop.last and day.weekday < 7 %} + {% for i in day.weekday+1..7 %} +
+ {% endfor %} + {% endif %} {% endfor %} - - {% if days|last.weekday < 7 %} - {% for i in days|last.weekday + 1..7 %} -
- {% endfor %} - {% endif %}