update mapado event working
This commit is contained in:
parent
4cd3bfba57
commit
c98d5eb36b
8 changed files with 184 additions and 126 deletions
|
|
@ -79,11 +79,13 @@ tabs:
|
|||
disabled: true
|
||||
columns:
|
||||
date:
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
time:
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
ticketingUrl:
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
bookableStock:
|
||||
width: 1/4
|
||||
when:
|
||||
isMapadoEvent: true
|
||||
fields:
|
||||
|
|
@ -91,15 +93,19 @@ tabs:
|
|||
type: date
|
||||
icon: calendar
|
||||
display: DD/MM/YYYY
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
time:
|
||||
label: Horaire de début
|
||||
type: text
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
ticketingUrl:
|
||||
label: Lien billetterie
|
||||
type: url
|
||||
width: 1/3
|
||||
width: 1/4
|
||||
bookableStock:
|
||||
label: Places disponibles
|
||||
type: text
|
||||
width: 1/4
|
||||
- width: 1/1
|
||||
fields:
|
||||
line:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ return [
|
|||
],
|
||||
'routes' => [
|
||||
require_once(__DIR__ . '/routes/mapado-api.php'),
|
||||
require_once(__DIR__ . '/routes/month-dates.php')
|
||||
require_once(__DIR__ . '/routes/month-dates.php'),
|
||||
require_once(__DIR__ . '/routes/update-mapado-event.php'),
|
||||
],
|
||||
'hooks' => [
|
||||
'page.update:after' => require_once(__DIR__ . '/hooks/update-mapado-event.php')
|
||||
|
|
|
|||
|
|
@ -1,67 +1,10 @@
|
|||
<?php
|
||||
|
||||
return function($newPage, $oldPage) {
|
||||
return function($newPage, $oldPage) {
|
||||
if ($newPage->isMapadoEvent() != 'true') return;
|
||||
$request = [
|
||||
"requestEndPoint" => "ticketings/" . $newPage->mapadoId()->value(),
|
||||
"requestParams" => [],
|
||||
"requestFields" => [
|
||||
["name" => "title"],
|
||||
["name" => "address"],
|
||||
["name" => "slug"],
|
||||
[
|
||||
"name" => "eventDateList",
|
||||
"subfields" => [
|
||||
["name" => "startDate"],
|
||||
["name" => "endDate"],
|
||||
["name" => "bookableStock"]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$request = createMapadoEventRequest($newPage);
|
||||
$mapadoEvent = fetchMapadoEvent($request);
|
||||
$duration = null;
|
||||
$sessionsToSave = [];
|
||||
|
||||
if ($mapadoEvent->{"@type"} === 'hydra:Error') {
|
||||
|
||||
$error = null;
|
||||
if ($newPage->mapadoId()->isEmpty()) {
|
||||
$error = 'Entrez l\'identifiant de l\'événement Mapado dans l\'onglet "Réglages".';
|
||||
} else {
|
||||
$error = 'Aucun événement Mapado ne correspond à l\'identifiant ' . $newPage->mapado()->value() . '. En êtes-vous sûr•e ?';
|
||||
}
|
||||
|
||||
throw new Exception($error, 1);
|
||||
}
|
||||
|
||||
|
||||
foreach ($mapadoEvent->eventDateList as $session) {
|
||||
|
||||
$sessionMonth = substr($session->startDate, 0, 7);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
$sessionsToSave[] = [
|
||||
"date" => substr($session->startDate, 0, 10),
|
||||
"time" => str_replace(':', 'h', $startTime),
|
||||
'ticketingUrl' => $ticketingUrl
|
||||
];
|
||||
}
|
||||
|
||||
$newPage->update([
|
||||
"mapadoSlug" => $mapadoEvent->slug,
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
]);
|
||||
saveMapadoEvent($mapadoEvent, $newPage);
|
||||
};
|
||||
|
|
@ -3,67 +3,15 @@
|
|||
return [
|
||||
'pattern' => '/update-mapado-event.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
'action' => function() {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$request = json_decode($jsonRequest, true);
|
||||
|
||||
$id = $request['id'];
|
||||
|
||||
$request = [
|
||||
"requestEndPoint" => "ticketings/" . $id,
|
||||
"requestParams" => [],
|
||||
"requestFields" => [
|
||||
["name" => "title"],
|
||||
["name" => "address"],
|
||||
["name" => "slug"],
|
||||
[
|
||||
"name" => "eventDateList",
|
||||
"subfields" => [
|
||||
["name" => "startDate"],
|
||||
["name" => "endDate"],
|
||||
["name" => "bookableStock"]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
$page = page($request['pageUri']);
|
||||
|
||||
$request = createMapadoEventRequest($page);
|
||||
$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];
|
||||
|
||||
if (isset($session->endDate) && !$duration) {
|
||||
$endTime = substr($session->endDate, 11 , 5);
|
||||
$duration = getTimeDifference($startTime, $endTime);
|
||||
|
||||
}
|
||||
|
||||
$dates[$day][] = array_merge($eventInfos, [
|
||||
"day" => $day,
|
||||
"time" => str_replace(':', 'h', $startTime),
|
||||
"duration" => $duration,
|
||||
"ticketingUrl" => option('ticketingUrl') . 'event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId
|
||||
]);
|
||||
|
||||
$sessionsToSave[] = [
|
||||
"date" => substr($session->startDate, 0, 10),
|
||||
"time" => str_replace(':', 'h', $startTime)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$event->update([
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
]);
|
||||
return saveMapadoEvent($mapadoEvent, $page);
|
||||
}
|
||||
];
|
||||
];
|
||||
|
|
@ -87,4 +87,80 @@ function fetchMapadoEvents($request) {
|
|||
$responseJson = json_encode(json_decode($responseString));
|
||||
|
||||
return $responseJson;
|
||||
}
|
||||
|
||||
function createMapadoEventRequest($page) {
|
||||
$request = [
|
||||
"requestEndPoint" => "ticketings/" . $page->mapadoId()->value(),
|
||||
"requestParams" => [],
|
||||
"requestFields" => [
|
||||
["name" => "title"],
|
||||
["name" => "address"],
|
||||
["name" => "slug"],
|
||||
[
|
||||
"name" => "eventDateList",
|
||||
"subfields" => [
|
||||
["name" => "startDate"],
|
||||
["name" => "endDate"],
|
||||
["name" => "bookableStock"]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
function saveMapadoEvent($mapadoEvent, $page) {
|
||||
$kirby = kirby();
|
||||
$kirby->impersonate('kirby');
|
||||
|
||||
$duration = '';
|
||||
$sessionsToSave = [];
|
||||
|
||||
if ($mapadoEvent->{"@type"} === 'hydra:Error') {
|
||||
|
||||
$error = null;
|
||||
if ($page->mapadoId()->isEmpty()) {
|
||||
$error = 'Entrez l\'identifiant de l\'événement Mapado dans l\'onglet "Réglages".';
|
||||
} else {
|
||||
$error = 'Aucun événement Mapado ne correspond à l\'identifiant ' . $page->mapado()->value() . '. En êtes-vous sûr•e ?';
|
||||
}
|
||||
|
||||
throw new Exception($error, 1);
|
||||
}
|
||||
|
||||
|
||||
foreach ($mapadoEvent->eventDateList as $session) {
|
||||
|
||||
$sessionMonth = substr($session->startDate, 0, 7);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
$sessionsToSave[] = [
|
||||
"date" => substr($session->startDate, 0, 10),
|
||||
"time" => str_replace(':', 'h', $startTime),
|
||||
"ticketingUrl" => $ticketingUrl,
|
||||
"bookableStock" => $session->bookableStock
|
||||
];
|
||||
}
|
||||
|
||||
$dataToSave = [
|
||||
"mapadoSlug" => $mapadoEvent->slug,
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
];
|
||||
|
||||
$page->update($dataToSave);
|
||||
|
||||
return $dataToSave;
|
||||
}
|
||||
|
|
@ -19,6 +19,38 @@
|
|||
</section>
|
||||
|
||||
<section class="collapsable-sections">
|
||||
<?php snippet('collapsable-section', ['title' => 'Prenez vos places !'], slots: true) ?>
|
||||
<?php slot('content') ?>
|
||||
<div
|
||||
class="sessions"
|
||||
x-data="{
|
||||
sessions: null,
|
||||
async fetchSessions() {
|
||||
this.sessions = await updateMapadoEvent('<?= $page->uri() ?>');
|
||||
console.log(this.sessions);
|
||||
}
|
||||
}"
|
||||
x-init="fetchSessions()"
|
||||
>
|
||||
<?php
|
||||
$sessions = $page->isMapadoEvent() != 'true' ? $page->sessions()->toStructure() : $page->remoteSessions()->toStructure();
|
||||
|
||||
foreach ($sessions as $session) :
|
||||
$date = new DateTime($session->date());
|
||||
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::FULL, IntlDateFormatter::NONE);
|
||||
$formattedDate = $formatter->format($date);
|
||||
?>
|
||||
<div class="session grid">
|
||||
<p><?= $formattedDate ?></p>
|
||||
<p><?= $session->time() ?></p>
|
||||
<p><?= $page->place() ?></p>
|
||||
<p>test</p>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<?php endslot() ?>
|
||||
<?php endsnippet() ?>
|
||||
|
||||
<?php snippet('collapsable-section', ['title' => 'Distribution et production'], slots: true) ?>
|
||||
<?php slot('content') ?>
|
||||
<div class="production">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue