mapado route -> 'mapado-api'

This commit is contained in:
isUnknown 2024-07-29 08:57:35 +02:00
parent 37a84058d1
commit dde1813f78
12 changed files with 127 additions and 42 deletions

View file

@ -24,41 +24,45 @@ async function getMapadoDates(monthNumb) {
.add(1, "month")
.format("YYYY-MM-DD");
const requestEndPoint = 'event_dates'
const requestEndPoint = "event_dates";
const requestParams = [
{ name: 'itemsPerPage', value: 100 },
{ name: 'contract', value: contractId },
{ name: 'after', value: firstDayOfMonth },
{ name: 'before', value: firstDayOfNextMonth },
{ name: 'order', value: 'asc' }
]
{ name: "itemsPerPage", value: 100 },
{ name: "contract", value: contractId },
{ name: "after", value: firstDayOfMonth },
{ name: "before", value: firstDayOfNextMonth },
{ name: "order", value: "asc" },
];
const requestFields = [
{ name: 'startDate', },
{ name: 'bookableStock', },
{ name: 'ticketing', subfields: [
{ name: "@id", },
{ name: "title", },
{ name: "slug", },
{ name: "venue", subfields: [
{ name: "startDate" },
{ name: "bookableStock" },
{
name: "ticketing",
subfields: [
{ name: "@id" },
{ name: "title" },
{ name: "slug" },
{
name: "venue",
subfields: [
{ name: "@id" },
{ name: "address" },
{ name: "zipCode" },
{ name: "city" },
{ name: "countryCode" },
{ name: "timezone" },
]
],
},
]
],
},
];
const requestOptions = {
method: 'POST',
body: JSON.stringify({requestEndPoint, requestParams, requestFields})
}
const response = await fetch('/mapado.json', requestOptions);
const requestOptions = {
method: "POST",
body: JSON.stringify({ requestEndPoint, requestParams, requestFields }),
};
const response = await fetch("/mapado-api.json", requestOptions);
const json = await response.json();
const eventDates = json["hydra:member"];
@ -75,7 +79,8 @@ async function getMapadoDates(monthNumb) {
day: getDay(eventDate),
title: eventDate.ticketing.title,
startTime: getStartTime(eventDate),
ticketingUrl: getTicketingUrl(eventDate)
ticketingUrl: getTicketingUrl(eventDate),
id: getId(eventDate),
};
});
@ -86,17 +91,41 @@ function getDay(eventDate) {
const date = eventDate.startDate.slice(0, 10);
const splittedDate = date.split("-");
const day = splittedDate[2];
return day
return day;
}
function getStartTime(eventDate) {
const rawTime = eventDate.startDate.slice(11, 19);
const time = dayjs(`2000-01-01T${rawTime}`);
const formattedTime = time.format('HH[h]mm');
return formattedTime
const formattedTime = time.format("HH[h]mm");
return formattedTime;
}
function getTicketingUrl(eventDate) {
const baseUrl = "https://cdn-besancon.mapado.com/event/"
return baseUrl + eventDate.ticketing.slug
const baseUrl = "https://cdn-besancon.mapado.com/event/";
return baseUrl + eventDate.ticketing.slug;
}
function getId(eventData) {
const endpoint = eventData.ticketing["@id"];
const splitString = endpoint.split("/");
const id = parseInt(splitString[3]);
return id;
}
async function getKirbyDates(monthNumb, dates) {
const month = dayjs().month(monthNumb).format("YYYY-MM");
const requestParams = {
month,
dates,
};
const requestOptions = {
method: "POST",
body: JSON.stringify(requestParams),
};
const response = await fetch("/month-dates.json", requestOptions);
const json = await response.json();
return json;
}

View file

@ -21,8 +21,8 @@ tabs:
mapadoKeyInfos:
label: Événement connecté à Mapado
type: info
text: Les données de dates et de durée sont récupérées de [Mapado](https://desk.mapado.com/).
width: 2/4
text: Les données de dates et de durée sont récupérées de Mapado ([gestion Mapado](https://desk.mapado.com/)).
width: 2/3
when:
isMapadoEvent: true
endDate:
@ -65,6 +65,9 @@ tabs:
label: Galerie
type: files
layout: cards
image:
cover: true
ratio: 4/3
- width: 1/2
fields:
authors:

View file

@ -14,8 +14,8 @@ tabs:
label: Calendrier
icon: calendar
sections:
events:
label: Événements
seasons:
label: Saisons
type: pages
template: event
layout: cards
template: season
info: "{{ page.children.count }} événements"

View file

@ -0,0 +1,18 @@
title: Saison
image: false
tabs:
contentTab:
label: Calendrier
icon: calendar
sections:
seasons:
label: Événéments
type: pages
template: event
layout: cards
size: large
image:
cover: true
ratio: 4/3
search: true

View file

@ -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')
]
];

View file

@ -1,6 +1,6 @@
<?php
return [
'pattern' => '/mapado.json',
'pattern' => '/mapado-api.json',
'method' => 'POST',
'action' => function () {
$jsonRequest = file_get_contents("php://input");

View 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);
}
];

View file

@ -30,4 +30,8 @@ function buildParamsString($requestParams) {
$queryString[] = urlencode($param['name']) . '=' . urlencode($param['value']);
}
return implode('&', $queryString);
}
function getEventsByMonth($month) {
$events = page('programme')->children();
}

View file

@ -55,7 +55,7 @@
redirect: "follow"
};
fetch(
"https://ticketing.mapado.net/v1/ticketings/" + id.value + "?fields=title,slug,sellingDeviceSchedule",
"https://ticketing.mapado.net/v1/ticketings/" + id.value + "?fields=id,title,slug,sellingDeviceSchedule",
requestOptions
).then((response) => {
console.log(response);
@ -78,7 +78,7 @@
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
);
console.log(result);
text.value = `<strong>Événement correspondant sur Mapado : <em>${result.title}</em>, ${schedule}.</strong> <a href="https://desk.mapado.com/activity/${result.slug}/events" target="_blank">Gérer sur Mapado.</a>`;
text.value = `<strong>Événement correspondant sur Mapado : <em>${result.title}</em>, ${schedule}</strong> (<a href="https://desk.mapado.com/mass-action/ticketing/${id.value}" target="_blank">gérer sur Mapado.</a>).`;
}).catch((error) => {
icon.value = "alert";
theme.value = "red";

View file

@ -66,7 +66,7 @@ function connect() {
fetch(
"https://ticketing.mapado.net/v1/ticketings/" +
id.value +
"?fields=title,slug,sellingDeviceSchedule",
"?fields=id,title,slug,sellingDeviceSchedule",
requestOptions
)
.then((response) => {
@ -91,7 +91,7 @@ function connect() {
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
);
console.log(result);
text.value = `<strong>Événement correspondant sur Mapado : <em>${result.title}</em>, ${schedule}.</strong> <a href="https://desk.mapado.com/activity/${result.slug}/events" target="_blank">Gérer sur Mapado.</a>`;
text.value = `<strong>Événement correspondant sur Mapado : <em>${result.title}</em>, ${schedule}</strong> (<a href="https://desk.mapado.com/mass-action/ticketing/${id.value}" target="_blank">gérer sur Mapado.</a>).`;
})
.catch((error) => {
icon.value = "alert";

View file

@ -18,10 +18,15 @@
this.dates = getDatesInMonth(this.monthNumb);
const mapadoDates = await getMapadoDates(this.monthNumb)
mapadoDates.forEach(mapadoDate => {
const day = parseInt(mapadoDate.day)
this.dates[day].push(mapadoDate)
})
const kirbyDates = await getKirbyDates(this.monthNumb, this.dates)
console.log('kirby dates', kirbyDates)
console.log('dates', this.dates)
document.body.classList.toggle('progress')
@ -36,7 +41,7 @@
x-init="updateDates()"
>
<div class="calendar-strip__selector">
<button class="prev-month" @click="monthNumb--; updateDates()" :disabled="monthNumb === -4 ? true : false"></button>
<button class="prev-month" @click="monthNumb--; updateDates()"></button>
<span x-text="monthName"></span>
<button class="next-month" @click="monthNumb++; updateDates()"></button>
</div>

View file