event - update mapado infos on update
This commit is contained in:
parent
6df3927970
commit
c1a94e832f
10 changed files with 215 additions and 11 deletions
|
|
@ -1,3 +1 @@
|
|||
.events-grid {
|
||||
min-height: 30rem;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
body.progress * {
|
||||
cursor: progress !important;
|
||||
}
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,14 @@ tabs:
|
|||
- width: 1/2
|
||||
fields:
|
||||
mapadoKeyInfos:
|
||||
label: Séances et durée récupérées de Mapado
|
||||
label: Connecté à Mapado
|
||||
type: info
|
||||
width: 1/2
|
||||
text: |
|
||||
[Gérer l'événement Mapado](https://desk.mapado.com/mass-action/ticketing/{{page.mapadoId}})
|
||||
[Gérer l'événement Mapado](https://desk.mapado.com/mass-action/ticketing/{{page.mapadoId}}).
|
||||
|
||||
**Infos erronées ?**
|
||||
Enregistrez (touches ⌘ / ctrl + s) et rechargez la page.
|
||||
when:
|
||||
isMapadoEvent: true
|
||||
duration:
|
||||
|
|
@ -22,6 +26,15 @@ tabs:
|
|||
placeholder: 1h20
|
||||
when:
|
||||
isMapadoEvent: false
|
||||
remoteDuration:
|
||||
label: Durée
|
||||
type: text
|
||||
icon: clock
|
||||
width: 1/2
|
||||
placeholder: 1h20
|
||||
disabled: true
|
||||
when:
|
||||
isMapadoEvent: true
|
||||
- width: 1/2
|
||||
fields:
|
||||
public:
|
||||
|
|
@ -57,6 +70,33 @@ tabs:
|
|||
label: Horaire de début
|
||||
type: text
|
||||
width: 1/2
|
||||
remoteSessions:
|
||||
label: Séances
|
||||
type: structure
|
||||
disabled: true
|
||||
columns:
|
||||
date:
|
||||
width: 1/3
|
||||
time:
|
||||
width: 1/3
|
||||
ticketingUrl:
|
||||
width: 1/3
|
||||
when:
|
||||
isMapadoEvent: true
|
||||
fields:
|
||||
date:
|
||||
type: date
|
||||
icon: calendar
|
||||
display: DD/MM/YYYY
|
||||
width: 1/3
|
||||
time:
|
||||
label: Horaire de début
|
||||
type: text
|
||||
width: 1/3
|
||||
ticketingUrl:
|
||||
label: Lien billetterie
|
||||
type: url
|
||||
width: 1/3
|
||||
- width: 1/1
|
||||
fields:
|
||||
line:
|
||||
|
|
|
|||
|
|
@ -35,5 +35,8 @@ return [
|
|||
'routes' => [
|
||||
require_once(__DIR__ . '/routes/mapado-api.php'),
|
||||
require_once(__DIR__ . '/routes/month-dates.php')
|
||||
],
|
||||
'hooks' => [
|
||||
'page.update:after' => require_once(__DIR__ . '/hooks/update-mapado-event.php')
|
||||
]
|
||||
];
|
||||
66
site/config/hooks/update-mapado-event.php
Normal file
66
site/config/hooks/update-mapado-event.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
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"]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$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 = 'https://cdn-besancon.mapado.com/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([
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
]);
|
||||
};
|
||||
|
|
@ -85,6 +85,7 @@ return [
|
|||
$startTime = substr($session->startDate, 11, 5);
|
||||
$eventDateId = explode('/', $session->{'@id'});
|
||||
$eventDateId = $eventDateId[count($eventDateId) - 1];
|
||||
$ticketingUrl = 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId;
|
||||
|
||||
if (isset($session->endDate) && !$duration) {
|
||||
$endTime = substr($session->endDate, 11 , 5);
|
||||
|
|
@ -95,17 +96,19 @@ return [
|
|||
"day" => $day,
|
||||
"time" => str_replace(':', 'h', $startTime),
|
||||
"duration" => $duration,
|
||||
"ticketingUrl" => 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId
|
||||
"ticketingUrl" => $ticketingUrl
|
||||
]);
|
||||
|
||||
$sessionsToSave[] = [
|
||||
"date" => substr($session->startDate, 0, 10),
|
||||
"time" => str_replace(':', 'h', $startTime)
|
||||
"time" => str_replace(':', 'h', $startTime),
|
||||
"ticketingUrl" => $ticketingUrl
|
||||
];
|
||||
}
|
||||
}
|
||||
$event->update([
|
||||
"sessions" => $sessionsToSave
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
69
site/config/routes/update-mapado-event.php
Normal file
69
site/config/routes/update-mapado-event.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '/update-mapado-event.json',
|
||||
'method' => 'POST',
|
||||
'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"]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$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" => 'https://cdn-besancon.mapado.com/event/' . $mapadoEvent->slug . '?eventDate=' . $eventDateId
|
||||
]);
|
||||
|
||||
$sessionsToSave[] = [
|
||||
"date" => substr($session->startDate, 0, 10),
|
||||
"time" => str_replace(':', 'h', $startTime)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$event->update([
|
||||
"remoteDuration" => $duration,
|
||||
"remoteSessions" => $sessionsToSave
|
||||
]);
|
||||
}
|
||||
];
|
||||
3
site/snippets/event-card.php
Normal file
3
site/snippets/event-card.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<div class="event-card">
|
||||
<?php snippet('picture', ["file" => $event->files()->first()]) ?>
|
||||
</div>
|
||||
|
|
@ -1 +1,5 @@
|
|||
<div class="events-grid"></div>
|
||||
<div class="events-grid grid" style="--span: <?= $events->count() ?>;">
|
||||
<?php foreach($events as $event): ?>
|
||||
<?php snippet('event-card', ["event" => $event]) ?>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
|
@ -8,5 +8,18 @@
|
|||
</div>
|
||||
</div>
|
||||
<?php snippet('calendar-strip') ?>
|
||||
<?php snippet('events-grid') ?>
|
||||
<?php
|
||||
$currentSeason = page('programme')->children()->first()->children();
|
||||
$orderedEvents = $currentSeason->sortBy(function ($event) {
|
||||
if ($event->isMapadoEvent() == 'true') {
|
||||
return $event->remoteSessions()->toStructure()->toArray()[0]['date'];
|
||||
} else {
|
||||
return $event->sessions()->toStructure()->toArray()[0]['date'];
|
||||
}
|
||||
},
|
||||
'asc'
|
||||
);
|
||||
|
||||
snippet('events-grid', ['events' => $orderedEvents->limit(2)])
|
||||
?>
|
||||
<?php snippet('footer') ?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue