merged dates working
This commit is contained in:
parent
dde1813f78
commit
68253fa497
3 changed files with 42 additions and 14 deletions
|
|
@ -114,7 +114,7 @@ function getId(eventData) {
|
|||
return id;
|
||||
}
|
||||
|
||||
async function getKirbyDates(monthNumb, dates) {
|
||||
async function getMergedDates(monthNumb, dates) {
|
||||
const month = dayjs().month(monthNumb).format("YYYY-MM");
|
||||
const requestParams = {
|
||||
month,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,30 @@
|
|||
<?php
|
||||
|
||||
function getCorrespondingSeasons($request) {
|
||||
$year = explode('-', $request['month'])[0];
|
||||
return page('programme')->children()->filter(
|
||||
fn ($season) => str_contains($season->title()->value(), $year)
|
||||
);
|
||||
}
|
||||
|
||||
function getEventsByDay($eventsFromSameMonth) {
|
||||
$eventsByDay = [];
|
||||
foreach ($eventsFromSameMonth as $event) {
|
||||
$day = $event->startDate()->toDate('d');
|
||||
if (!isset($eventsByDay[$day])) {
|
||||
$eventsByDay[$day] = [];
|
||||
}
|
||||
$eventsByDay[$day][] = [
|
||||
"day" => $day,
|
||||
"title" => $event->title()->value(),
|
||||
"id" => null,
|
||||
"startTime" => null,
|
||||
"ticketingUrl" => null,
|
||||
];
|
||||
}
|
||||
return $eventsByDay;
|
||||
}
|
||||
|
||||
return [
|
||||
'pattern' => '/month-dates.json',
|
||||
'method' => 'POST',
|
||||
|
|
@ -6,20 +32,23 @@ return [
|
|||
$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)
|
||||
);
|
||||
$mapadoDates = $request['dates'];
|
||||
$requestMonth = $request['month'];
|
||||
|
||||
$correspondingSeasons = getCorrespondingSeasons($request);
|
||||
|
||||
$eventsFromSameMonth = $correspondingSeasons->children()->filter(
|
||||
fn ($event) => $event->isNotEmpty() && $event->startDate()->toDate('Y-m') == $request['month']
|
||||
fn ($event) => $event->isNotEmpty() && $event->startDate()->toDate('Y-m') == $requestMonth
|
||||
);
|
||||
|
||||
foreach ($eventsFromSameMonth as $event) {
|
||||
$day = $event->startDate()->toDate('d');
|
||||
$eventsByDay = getEventsByDay($eventsFromSameMonth);
|
||||
|
||||
foreach ($mapadoDates as $day => $mapadoDate) {
|
||||
if (isset($eventsByDay[$day])) {
|
||||
$mapadoDates[$day] = array_merge($mapadoDates[$day], $eventsByDay[$day]);
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($eventsFromSameMonth);
|
||||
return json_encode($mapadoDates);
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -24,11 +24,10 @@
|
|||
this.dates[day].push(mapadoDate)
|
||||
})
|
||||
|
||||
const kirbyDates = await getKirbyDates(this.monthNumb, this.dates)
|
||||
const mergedDates = await getMergedDates(this.monthNumb, this.dates)
|
||||
this.dates = mergedDates
|
||||
|
||||
console.log('kirby dates', kirbyDates)
|
||||
|
||||
console.log('dates', this.dates)
|
||||
console.log('Merged dates', this.dates)
|
||||
document.body.classList.toggle('progress')
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue