99 lines
3.1 KiB
PHP
99 lines
3.1 KiB
PHP
<?php
|
|
|
|
function getCorrespondingSeasons($request) {
|
|
$year = explode('-', $request['month'])[0];
|
|
return page('programme')->children()->filter(
|
|
fn ($season) => str_contains($season->title()->value(), $year)
|
|
);
|
|
}
|
|
|
|
function getTimeDifference($start, $end) {
|
|
$start = new DateTime($start);
|
|
$end = new DateTime($end);
|
|
|
|
$difference = $end->diff($start);
|
|
|
|
return $difference->h . "h" . $difference->i;
|
|
}
|
|
|
|
return [
|
|
'pattern' => '/month-dates.json',
|
|
'method' => 'POST',
|
|
'action' => function () {
|
|
$jsonRequest = file_get_contents("php://input");
|
|
$request = json_decode($jsonRequest, true);
|
|
|
|
$dates = $request['dates'];
|
|
$requestMonth = $request['month'];
|
|
|
|
$correspondingSeasons = getCorrespondingSeasons($request);
|
|
|
|
foreach ($correspondingSeasons->children() as $event) {
|
|
|
|
$eventInfos = [
|
|
"title" => $event->title()->value(),
|
|
"place" => $event->place()->value(),
|
|
"authors" => $event->authors()->value()
|
|
];
|
|
|
|
if ($event->isMapadoEvent() == 'false') {
|
|
foreach ($event->sessions()->toStructure() as $session) {
|
|
|
|
$sessionMonth = $session->date()->toDate('Y-MM');
|
|
if ($sessionMonth === $requestMonth) {
|
|
$day = intval($session->date()->toDate('d'));
|
|
$dates[$day]['sessions'][] = array_merge($eventInfos, [
|
|
"color" => $event->color()->value(),
|
|
"day" => $day,
|
|
"time" => $session->time()->value(),
|
|
"place" => $event->place()->value(),
|
|
"duration" => $event->duration()->value(),
|
|
"eventUrl" => $event->url(),
|
|
]);
|
|
};
|
|
}
|
|
}
|
|
|
|
if ($event->isMapadoEvent() == 'true') {
|
|
$request = createMapadoEventRequest($event);
|
|
$mapadoEvent = fetchMapadoEvent($request);
|
|
|
|
$duration = null;
|
|
|
|
$sessionsToSave = [];
|
|
|
|
foreach ($mapadoEvent->eventDateList as $session) {
|
|
|
|
$sessionMonth = substr($session->startDate, 0, 7);
|
|
|
|
if ($sessionMonth === $requestMonth) {
|
|
$day = intval(substr($session->startDate, 8, 2));
|
|
$startTime = substr($session->startDate, 11, 5);
|
|
$eventDateId = explode('/', $session->{'@id'});
|
|
$eventDateId = $eventDateId[count($eventDateId) - 1];
|
|
$ticketingUrl = option('ticketingUrl') . 'event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId;
|
|
|
|
if (isset($session->endDate) && !$duration) {
|
|
$endTime = substr($session->endDate, 11 , 5);
|
|
$duration = getTimeDifference($startTime, $endTime);
|
|
}
|
|
|
|
$dates[$day]['sessions'][] = array_merge($eventInfos, [
|
|
"color" => $event->color()->value(),
|
|
"day" => $day,
|
|
"time" => str_replace(':', 'h', $startTime),
|
|
"duration" => $duration,
|
|
"place" => $event->place()->value(),
|
|
"eventUrl" => $event->url(),
|
|
"ticketingUrl" => $ticketingUrl
|
|
]);
|
|
}
|
|
}
|
|
|
|
saveMapadoEvent($mapadoEvent, $event);
|
|
}
|
|
}
|
|
|
|
return json_encode($dates);
|
|
}
|
|
];
|