nouveau-theatre-de-besancon/site/config/routes/month-dates.php
2024-07-29 08:57:35 +02:00

25 lines
760 B
PHP

<?php
return [
'pattern' => '/month-dates.json',
'method' => 'POST',
'action' => function () {
$jsonRequest = file_get_contents("php://input");
$request = json_decode($jsonRequest, true);
$dates = $request['dates'];
$year = explode('-', $request['month'])[0];
$correspondingSeasons = page('programme')->children()->filter(
fn ($season) => str_contains($season->title()->value(), $year)
);
$eventsFromSameMonth = $correspondingSeasons->children()->filter(
fn ($event) => $event->isNotEmpty() && $event->startDate()->toDate('Y-m') == $request['month']
);
foreach ($eventsFromSameMonth as $event) {
$day = $event->startDate()->toDate('d');
}
return json_encode($eventsFromSameMonth);
}
];