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