mapado route -> 'mapado-api'
This commit is contained in:
parent
37a84058d1
commit
dde1813f78
12 changed files with 127 additions and 42 deletions
|
|
@ -24,41 +24,45 @@ async function getMapadoDates(monthNumb) {
|
||||||
.add(1, "month")
|
.add(1, "month")
|
||||||
.format("YYYY-MM-DD");
|
.format("YYYY-MM-DD");
|
||||||
|
|
||||||
const requestEndPoint = 'event_dates'
|
const requestEndPoint = "event_dates";
|
||||||
const requestParams = [
|
const requestParams = [
|
||||||
{ name: 'itemsPerPage', value: 100 },
|
{ name: "itemsPerPage", value: 100 },
|
||||||
{ name: 'contract', value: contractId },
|
{ name: "contract", value: contractId },
|
||||||
{ name: 'after', value: firstDayOfMonth },
|
{ name: "after", value: firstDayOfMonth },
|
||||||
{ name: 'before', value: firstDayOfNextMonth },
|
{ name: "before", value: firstDayOfNextMonth },
|
||||||
{ name: 'order', value: 'asc' }
|
{ name: "order", value: "asc" },
|
||||||
]
|
];
|
||||||
|
|
||||||
const requestFields = [
|
const requestFields = [
|
||||||
{ name: 'startDate', },
|
{ name: "startDate" },
|
||||||
{ name: 'bookableStock', },
|
{ name: "bookableStock" },
|
||||||
{ name: 'ticketing', subfields: [
|
{
|
||||||
{ name: "@id", },
|
name: "ticketing",
|
||||||
{ name: "title", },
|
subfields: [
|
||||||
{ name: "slug", },
|
{ name: "@id" },
|
||||||
{ name: "venue", subfields: [
|
{ name: "title" },
|
||||||
|
{ name: "slug" },
|
||||||
|
{
|
||||||
|
name: "venue",
|
||||||
|
subfields: [
|
||||||
{ name: "@id" },
|
{ name: "@id" },
|
||||||
{ name: "address" },
|
{ name: "address" },
|
||||||
{ name: "zipCode" },
|
{ name: "zipCode" },
|
||||||
{ name: "city" },
|
{ name: "city" },
|
||||||
{ name: "countryCode" },
|
{ name: "countryCode" },
|
||||||
{ name: "timezone" },
|
{ 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 json = await response.json();
|
||||||
|
|
||||||
const eventDates = json["hydra:member"];
|
const eventDates = json["hydra:member"];
|
||||||
|
|
@ -75,7 +79,8 @@ async function getMapadoDates(monthNumb) {
|
||||||
day: getDay(eventDate),
|
day: getDay(eventDate),
|
||||||
title: eventDate.ticketing.title,
|
title: eventDate.ticketing.title,
|
||||||
startTime: getStartTime(eventDate),
|
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 date = eventDate.startDate.slice(0, 10);
|
||||||
const splittedDate = date.split("-");
|
const splittedDate = date.split("-");
|
||||||
const day = splittedDate[2];
|
const day = splittedDate[2];
|
||||||
return day
|
return day;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStartTime(eventDate) {
|
function getStartTime(eventDate) {
|
||||||
const rawTime = eventDate.startDate.slice(11, 19);
|
const rawTime = eventDate.startDate.slice(11, 19);
|
||||||
const time = dayjs(`2000-01-01T${rawTime}`);
|
const time = dayjs(`2000-01-01T${rawTime}`);
|
||||||
const formattedTime = time.format('HH[h]mm');
|
const formattedTime = time.format("HH[h]mm");
|
||||||
return formattedTime
|
return formattedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTicketingUrl(eventDate) {
|
function getTicketingUrl(eventDate) {
|
||||||
const baseUrl = "https://cdn-besancon.mapado.com/event/"
|
const baseUrl = "https://cdn-besancon.mapado.com/event/";
|
||||||
return baseUrl + eventDate.ticketing.slug
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ tabs:
|
||||||
mapadoKeyInfos:
|
mapadoKeyInfos:
|
||||||
label: Événement connecté à Mapado
|
label: Événement connecté à Mapado
|
||||||
type: info
|
type: info
|
||||||
text: Les données de dates et de durée sont récupérées de [Mapado](https://desk.mapado.com/).
|
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/4
|
width: 2/3
|
||||||
when:
|
when:
|
||||||
isMapadoEvent: true
|
isMapadoEvent: true
|
||||||
endDate:
|
endDate:
|
||||||
|
|
@ -65,6 +65,9 @@ tabs:
|
||||||
label: Galerie
|
label: Galerie
|
||||||
type: files
|
type: files
|
||||||
layout: cards
|
layout: cards
|
||||||
|
image:
|
||||||
|
cover: true
|
||||||
|
ratio: 4/3
|
||||||
- width: 1/2
|
- width: 1/2
|
||||||
fields:
|
fields:
|
||||||
authors:
|
authors:
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ tabs:
|
||||||
label: Calendrier
|
label: Calendrier
|
||||||
icon: calendar
|
icon: calendar
|
||||||
sections:
|
sections:
|
||||||
events:
|
seasons:
|
||||||
label: Événements
|
label: Saisons
|
||||||
type: pages
|
type: pages
|
||||||
template: event
|
template: season
|
||||||
layout: cards
|
info: "{{ page.children.count }} événements"
|
||||||
18
site/blueprints/pages/season.yml
Normal file
18
site/blueprints/pages/season.yml
Normal 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
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
return [
|
return [
|
||||||
'debug' => true,
|
'debug' => true,
|
||||||
'routes' => [
|
'routes' => [
|
||||||
require_once(__DIR__ . '/routes/mapado.php')
|
require_once(__DIR__ . '/routes/mapado-api.php'),
|
||||||
|
require_once(__DIR__ . '/routes/month-dates.php')
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'pattern' => '/mapado.json',
|
'pattern' => '/mapado-api.json',
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'action' => function () {
|
'action' => function () {
|
||||||
$jsonRequest = file_get_contents("php://input");
|
$jsonRequest = file_get_contents("php://input");
|
||||||
25
site/config/routes/month-dates.php
Normal file
25
site/config/routes/month-dates.php
Normal 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);
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
@ -30,4 +30,8 @@ function buildParamsString($requestParams) {
|
||||||
$queryString[] = urlencode($param['name']) . '=' . urlencode($param['value']);
|
$queryString[] = urlencode($param['name']) . '=' . urlencode($param['value']);
|
||||||
}
|
}
|
||||||
return implode('&', $queryString);
|
return implode('&', $queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEventsByMonth($month) {
|
||||||
|
$events = page('programme')->children();
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +55,7 @@
|
||||||
redirect: "follow"
|
redirect: "follow"
|
||||||
};
|
};
|
||||||
fetch(
|
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
|
requestOptions
|
||||||
).then((response) => {
|
).then((response) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
|
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
|
||||||
);
|
);
|
||||||
console.log(result);
|
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) => {
|
}).catch((error) => {
|
||||||
icon.value = "alert";
|
icon.value = "alert";
|
||||||
theme.value = "red";
|
theme.value = "red";
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ function connect() {
|
||||||
fetch(
|
fetch(
|
||||||
"https://ticketing.mapado.net/v1/ticketings/" +
|
"https://ticketing.mapado.net/v1/ticketings/" +
|
||||||
id.value +
|
id.value +
|
||||||
"?fields=title,slug,sellingDeviceSchedule",
|
"?fields=id,title,slug,sellingDeviceSchedule",
|
||||||
requestOptions
|
requestOptions
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
@ -91,7 +91,7 @@ function connect() {
|
||||||
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
|
result.sellingDeviceSchedule[scheduleFirstKey].fr.toLowerCase()
|
||||||
);
|
);
|
||||||
console.log(result);
|
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) => {
|
.catch((error) => {
|
||||||
icon.value = "alert";
|
icon.value = "alert";
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,15 @@
|
||||||
this.dates = getDatesInMonth(this.monthNumb);
|
this.dates = getDatesInMonth(this.monthNumb);
|
||||||
|
|
||||||
const mapadoDates = await getMapadoDates(this.monthNumb)
|
const mapadoDates = await getMapadoDates(this.monthNumb)
|
||||||
|
|
||||||
mapadoDates.forEach(mapadoDate => {
|
mapadoDates.forEach(mapadoDate => {
|
||||||
const day = parseInt(mapadoDate.day)
|
const day = parseInt(mapadoDate.day)
|
||||||
this.dates[day].push(mapadoDate)
|
this.dates[day].push(mapadoDate)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const kirbyDates = await getKirbyDates(this.monthNumb, this.dates)
|
||||||
|
|
||||||
|
console.log('kirby dates', kirbyDates)
|
||||||
|
|
||||||
console.log('dates', this.dates)
|
console.log('dates', this.dates)
|
||||||
document.body.classList.toggle('progress')
|
document.body.classList.toggle('progress')
|
||||||
|
|
@ -36,7 +41,7 @@
|
||||||
x-init="updateDates()"
|
x-init="updateDates()"
|
||||||
>
|
>
|
||||||
<div class="calendar-strip__selector">
|
<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>
|
<span x-text="monthName"></span>
|
||||||
<button class="next-month" @click="monthNumb++; updateDates()">→</button>
|
<button class="next-month" @click="monthNumb++; updateDates()">→</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
0
site/templates/season.php
Normal file
0
site/templates/season.php
Normal file
Loading…
Add table
Add a link
Reference in a new issue