update mapado event working
This commit is contained in:
parent
4cd3bfba57
commit
c98d5eb36b
8 changed files with 184 additions and 126 deletions
|
|
@ -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);
|
||||
}
|
||||
];
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue