Show events in the past

This commit is contained in:
Tim Lappe 2025-03-15 09:06:01 +01:00
parent ec166854cb
commit c60b5f653e
3 changed files with 49 additions and 25 deletions

View File

@ -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;
}
}
}

View File

@ -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' => [

View File

@ -53,34 +53,58 @@
<div class="calendar-header">So</div>
{% set currentMonth = null %}
{% set firstDay = days|first %}
{% if firstDay.weekday > 1 %}
{% if currentMonth != firstDay.date|date('F') %}
{% set currentMonth = firstDay.date|date('F') %}
<div class="calendar-week" style="background-color: #e9ecef;">{{ firstDay.date|date('F Y') }}</div>
{% endif %}
{% for i in 1..firstDay.weekday - 1 %}
<div class="calendar-day"></div>
{% 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') %}
<div class="calendar-week" style="background-color: #e9ecef;">{{ day.date|date('F Y') }}</div>
{# Add empty cells for first row of month #}
{% set dayWeekday = day.weekday %}
{% if dayWeekday > 1 %}
{% for i in 1..dayWeekday-1 %}
<div class="calendar-day"></div>
{% 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 %}
<div class="calendar-day"></div>
{% endfor %}
{% endif %}
{% endif %}
{# Render the day #}
<div class="calendar-day {{ day.class }}">
<div>{{ day.date|date('d.m.Y') }}</div>
{% if day.isFtk %}<div>FTK</div>{% endif %}
{% if day.isUrlaub %}<div>Urlaub</div>{% endif %}
</div>
{# 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 %}
<div class="calendar-day"></div>
{% 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 %}
<div class="calendar-day"></div>
{% endfor %}
{% endif %}
{% endfor %}
{% if days|last.weekday < 7 %}
{% for i in days|last.weekday + 1..7 %}
<div class="calendar-day"></div>
{% endfor %}
{% endif %}
</div>
</div>
</body>