mapado route -> 'mapado-api'
This commit is contained in:
parent
37a84058d1
commit
dde1813f78
12 changed files with 127 additions and 42 deletions
|
|
@ -3,6 +3,7 @@
|
|||
return [
|
||||
'debug' => true,
|
||||
'routes' => [
|
||||
require_once(__DIR__ . '/routes/mapado.php')
|
||||
require_once(__DIR__ . '/routes/mapado-api.php'),
|
||||
require_once(__DIR__ . '/routes/month-dates.php')
|
||||
]
|
||||
];
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
return [
|
||||
'pattern' => '/mapado.json',
|
||||
'pattern' => '/mapado-api.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
25
site/config/routes/month-dates.php
Normal file
25
site/config/routes/month-dates.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?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);
|
||||
}
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue