From dde1813f78ee30ca193b175f996ffaa87931b0b1 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Mon, 29 Jul 2024 08:57:35 +0200 Subject: [PATCH] mapado route -> 'mapado-api' --- assets/js/calendar.js | 87 ++++++++++++------- site/blueprints/pages/event.yml | 7 +- site/blueprints/pages/program.yml | 8 +- site/blueprints/pages/season.yml | 18 ++++ site/config/config.php | 3 +- .../routes/{mapado.php => mapado-api.php} | 2 +- site/config/routes/month-dates.php | 25 ++++++ site/plugins/helpers/index.php | 4 + site/plugins/mapado-check/index.js | 4 +- .../src/components/MapadoCheckButton.vue | 4 +- site/snippets/calendar-strip.php | 7 +- site/templates/season.php | 0 12 files changed, 127 insertions(+), 42 deletions(-) create mode 100644 site/blueprints/pages/season.yml rename site/config/routes/{mapado.php => mapado-api.php} (96%) create mode 100644 site/config/routes/month-dates.php create mode 100644 site/templates/season.php diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 49cff58..5b82276 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -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; } diff --git a/site/blueprints/pages/event.yml b/site/blueprints/pages/event.yml index a964e99..918f739 100644 --- a/site/blueprints/pages/event.yml +++ b/site/blueprints/pages/event.yml @@ -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: diff --git a/site/blueprints/pages/program.yml b/site/blueprints/pages/program.yml index 69abc87..bb37156 100644 --- a/site/blueprints/pages/program.yml +++ b/site/blueprints/pages/program.yml @@ -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" \ No newline at end of file diff --git a/site/blueprints/pages/season.yml b/site/blueprints/pages/season.yml new file mode 100644 index 0000000..6f9b79a --- /dev/null +++ b/site/blueprints/pages/season.yml @@ -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 diff --git a/site/config/config.php b/site/config/config.php index 7a51d19..28b3b55 100644 --- a/site/config/config.php +++ b/site/config/config.php @@ -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') ] ]; \ No newline at end of file diff --git a/site/config/routes/mapado.php b/site/config/routes/mapado-api.php similarity index 96% rename from site/config/routes/mapado.php rename to site/config/routes/mapado-api.php index 9d28c02..9f3b6b5 100644 --- a/site/config/routes/mapado.php +++ b/site/config/routes/mapado-api.php @@ -1,6 +1,6 @@ '/mapado.json', + 'pattern' => '/mapado-api.json', 'method' => 'POST', 'action' => function () { $jsonRequest = file_get_contents("php://input"); diff --git a/site/config/routes/month-dates.php b/site/config/routes/month-dates.php new file mode 100644 index 0000000..ebb57d8 --- /dev/null +++ b/site/config/routes/month-dates.php @@ -0,0 +1,25 @@ + '/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); + } +]; diff --git a/site/plugins/helpers/index.php b/site/plugins/helpers/index.php index f28c8ce..1c6160f 100644 --- a/site/plugins/helpers/index.php +++ b/site/plugins/helpers/index.php @@ -30,4 +30,8 @@ function buildParamsString($requestParams) { $queryString[] = urlencode($param['name']) . '=' . urlencode($param['value']); } return implode('&', $queryString); +} + +function getEventsByMonth($month) { + $events = page('programme')->children(); } \ No newline at end of file diff --git a/site/plugins/mapado-check/index.js b/site/plugins/mapado-check/index.js index 37df54a..83d4987 100644 --- a/site/plugins/mapado-check/index.js +++ b/site/plugins/mapado-check/index.js @@ -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 = `Événement correspondant sur Mapado : ${result.title}, ${schedule}. Gérer sur Mapado.`; + text.value = `Événement correspondant sur Mapado : ${result.title}, ${schedule} (gérer sur Mapado.).`; }).catch((error) => { icon.value = "alert"; theme.value = "red"; diff --git a/site/plugins/mapado-check/src/components/MapadoCheckButton.vue b/site/plugins/mapado-check/src/components/MapadoCheckButton.vue index 17f9417..6d115eb 100755 --- a/site/plugins/mapado-check/src/components/MapadoCheckButton.vue +++ b/site/plugins/mapado-check/src/components/MapadoCheckButton.vue @@ -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 = `Événement correspondant sur Mapado : ${result.title}, ${schedule}. Gérer sur Mapado.`; + text.value = `Événement correspondant sur Mapado : ${result.title}, ${schedule} (gérer sur Mapado.).`; }) .catch((error) => { icon.value = "alert"; diff --git a/site/snippets/calendar-strip.php b/site/snippets/calendar-strip.php index e9c59da..57dbde5 100644 --- a/site/snippets/calendar-strip.php +++ b/site/snippets/calendar-strip.php @@ -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()" >
- +
diff --git a/site/templates/season.php b/site/templates/season.php new file mode 100644 index 0000000..e69de29