nouveau-theatre-de-besancon/site/templates/program.php

249 lines
9.9 KiB
PHP
Raw Normal View History

2024-08-28 19:11:58 +02:00
<?php snippet('header') ?>
2024-08-30 14:37:13 +02:00
<div
2024-08-30 15:16:41 +02:00
class="program-methods"
2024-08-30 14:37:13 +02:00
x-data="{
setInitialTab() {
const queryString = window.location.search;
if (queryString.length === 0) return 'Programme';
const urlParams = new URLSearchParams(queryString);
const tab = urlParams.get('tab');
return tab;
},
disableEmptySections() {
setTimeout(() => {
const sections = document.querySelectorAll('.collapsable')
sections.forEach(section => {
const sessions = section.querySelector('.sessions li')
const toggleBtn = section.querySelector('.toggle')
if (sessions) {
toggleBtn.removeAttribute('disabled')
toggleBtn.setAttribute('title', '')
toggleBtn.querySelector('.arrow-right').classList.remove('unvisible')
} else {
toggleBtn.setAttribute('disabled', true)
toggleBtn.setAttribute('title', 'aucune séance')
toggleBtn.querySelector('.arrow-right').classList.add('unvisible')
}
})
})
},
scrollToNextClosestDate() {
const nodes = document.querySelectorAll('.sessions [data-date]');
const today = new Date();
2024-11-07 15:47:50 +01:00
today.setHours(0, 0, 0, 0);
2024-11-07 15:41:13 +01:00
const nextNode = Array.from(nodes).find(node => {
const date = new Date(node.getAttribute('data-date'));
date.setHours(0, 0, 0, 0);
return date >= today;
});
2024-11-07 15:41:13 +01:00
if (nextNode) {
nextNode.scrollIntoView({ behavior: 'smooth' });
}
2024-11-05 17:37:31 +01:00
},
2024-11-07 15:41:13 +01:00
2024-11-05 17:37:31 +01:00
getFilter(string) {
return string.split('—')[1].trim()
2024-08-30 14:37:13 +02:00
}
}"
>
2024-08-30 15:16:41 +02:00
<div class="program-data"
2024-08-30 14:37:13 +02:00
x-data="{
2024-09-02 18:02:46 +02:00
tab: setInitialTab(),
filter: null
2024-08-30 14:37:13 +02:00
}"
x-init="
disableEmptySections()
$watch('tab', value => {
disableEmptySections()
})
"
2024-08-30 14:37:13 +02:00
>
2024-08-30 15:16:41 +02:00
2024-08-30 15:16:41 +02:00
<section class="filters">
<button
x-data="{title: 'Calendrier'}"
x-text="title"
2024-09-02 18:02:46 +02:00
:class="tab === title ? 'strong' : ''"
@click="
2024-09-24 08:59:17 +02:00
tab = title
const url = new URL(window.location.href);
url.searchParams.set('tab', tab);
window.history.pushState({}, '', url);
setTimeout(scrollToNextClosestDate, 100)
"
2024-08-30 15:16:41 +02:00
></button>
2024-09-04 15:56:19 +02:00
<?php foreach($page->categories()->split() as $filter): ?>
<button
x-data="{
title: '<?= $filter ?>',
get filterTitle() {
if(tab.includes('Calendrier')){
return 'Calendrier — ' + this.title
}
else{
return this.title
}
2024-09-04 15:56:19 +02:00
}
}"
x-text="title"
:class="tab === filterTitle ? 'strong' : ''"
@click="
tab = filterTitle;
filter = title; /* où est utiliser cette vriable ? */
const url = new URL(window.location.href);
url.searchParams.set('tab', tab);
window.history.pushState({}, '', url);
setTimeout(scrollToNextClosestDate, 100);
"
2024-09-04 15:56:19 +02:00
></button>
<?php endforeach ?>
2024-08-30 15:16:41 +02:00
</section>
2024-08-30 14:37:13 +02:00
<section class="page-title">
<h1 x-text="tab"></h1>
</section>
2024-08-30 15:16:41 +02:00
<!-- Programme -->
<template x-if="!tab.includes('Calendrier')">
2024-08-30 15:16:41 +02:00
<div class="program-content__events">
<?php
$categoriesInNextEvents = [];
foreach($events['next'] as $event) {
foreach($event->categories()->split() as $cat) {
$categoriesInNextEvents[] = $cat;
}
}
$categoriesInNextEvents = array_values(array_unique($categoriesInNextEvents));
$hasNextEvents = count($events['next']) > 0;
?>
<template
x-if="<?= $hasNextEvents ? 'true' : 'false' ?> && (tab === 'Programme' || <?= htmlspecialchars(json_encode($categoriesInNextEvents)) ?>.includes(tab))"
>
<div class="temporality-wrapper">
<section class="yellow">
<h2>Prochainement <?= $page->children()->first()->title() ?></h2>
</section>
<?php snippet('events-grid', ['events' => $events['next'], 'columns' => 3]) ?>
</div>
</template>
<?php
$categoriesInPrevEvents = [];
foreach($events['previous'] as $event) {
foreach($event->categories()->split() as $cat) {
$categoriesInPrevEvents[] = $cat;
}
}
$categoriesInPrevEvents = array_values(array_unique($categoriesInPrevEvents));
$hasPrevEvents = $events['previous']->count() > 0;
?>
<template
x-if="<?= $hasPrevEvents ? 'true' : 'false' ?> && (tab === 'Programme' || <?= htmlspecialchars(json_encode($categoriesInPrevEvents)) ?>.includes(tab))"
>
<div class="temporality-wrapper">
<section class="yellow">
<h2>Événements passés</h2>
</section>
<?php snippet('events-grid', ['events' => $events['previous'], 'columns' => 3]) ?>
</div>
</template>
2024-08-30 15:16:41 +02:00
</div>
</template>
<!-- Calendrier -->
2024-09-02 18:02:46 +02:00
<template x-if="tab.includes('Calendrier')">
2024-08-30 15:16:41 +02:00
<div class="program-content__events">
<section class="collapsable-sections">
2024-09-16 16:28:12 +02:00
<?php
$currentMonth = date('n');
2024-09-16 16:28:12 +02:00
foreach($currentSeasonSessions as $month => $sessions): ?>
<?php
$open = getMonthNumber($month) == $currentMonth || getMonthNumber($month) == $currentMonth + 1;
?>
2024-08-30 15:16:41 +02:00
<?php if (count($sessions) > 0): ?>
<?php snippet('collapsable-section', ['title' => $month, 'padding' => false, 'open' => $open], slots: true) ?>
2024-08-30 15:16:41 +02:00
<?php slot('content') ?>
<ul
class="sessions sessions--detailed"
x-init="
scrollToNextClosestDate()
"
>
2024-09-02 16:32:21 +02:00
<?php
foreach($sessions as $session):
$date = new DateTime($session['date']);
$formatter = new IntlDateFormatter('fr_FR', IntlDateFormatter::NONE, IntlDateFormatter::NONE);
$formattedDate = $formatter->formatObject($date, "d MMMM");
2024-09-04 15:56:19 +02:00
?>
<template
x-if="tab === 'Calendrier' || ('<?= $session['categories'] ?>'.length > 0 && '<?= $session['categories'] ?>'.includes(getFilter(tab)))"
>
<li id="<?= Str::slug($session['title']) ?>" class="collapsable__item--padding session grid js-link" style="--color: <?= $session['color'] ?>" data-date="<?= $session['date'] ?>">
2024-09-12 15:39:44 +02:00
<div class="left-column">
<div class="session__info">
<p><?= $formattedDate ?></p>
2024-10-31 14:35:37 +01:00
<p><?= $session['time'] ?></p>
2024-09-12 15:39:44 +02:00
</div>
<div class="session__info">
<p><strong><?= $session['title'] ?></strong></p>
<p><?= $session['authors'] ?></p>
</div>
2024-09-02 17:09:53 +02:00
</div>
2024-09-12 15:39:44 +02:00
<div class="right-column">
<div class="mobile-group">
<div class="session__info">
<?php if (strlen($session['duration']) > 0 || strlen($session['public']) > 0): ?>
<p>
<?php if (strlen($session['duration']) > 0): ?>
Durée : <?= $session['duration'] ?><br />
<?php endif ?>
<?php if (strlen($session['public']) > 0): ?>
<?= $session['public'] ?>
<?php endif ?>
</p>
2024-09-02 17:09:53 +02:00
<?php endif ?>
2024-09-12 15:39:44 +02:00
</div>
<div class="session__info">
<p><?= $session['place'] ?></p>
</div>
</div>
<div class="session__info session__info--ticket">
<?php if ($session['bookableStock'] === 'free'): ?>
<?php if (strlen($session['ticketingUrl']) > 0): ?>
<a class="ticket-link" title="Plateforme de réservation" href="<?= $session['ticketingUrl'] ?>" target="_blank" tabindex="-1"><?php snippet('ticket') ?>Billetterie</a>
<?php else: ?>
2024-09-20 10:14:43 +02:00
<a class="ticket-link" title="Entrée libre" disabled tabindex="-1"><?php snippet('ticket') ?>Entrée libre</a>
<?php endif ?>
2024-09-12 15:39:44 +02:00
<?php elseif ($session['bookableStock'] == 0): ?>
2024-09-20 10:14:43 +02:00
<a class="ticket-link" title="Séance complète" disabled tabindex="-1"><?php snippet('ticket') ?>Complet</a>
2024-09-12 15:39:44 +02:00
<?php elseif ($session['bookableStock'] < (($session['totalStock'] / 100) * 25)): ?>
2024-09-20 10:14:43 +02:00
<a class="ticket-link" title="Plateforme de réservation" href="<?= $session['ticketingUrl'] ?>" target="_blank" tabindex="-1"><?php snippet('ticket') ?>Plus que quelques places !</a>
2024-09-12 15:39:44 +02:00
<?php else: ?>
2024-09-20 10:14:43 +02:00
<a class="ticket-link" title="Plateforme de réservation" href="<?= $session['ticketingUrl'] ?>" target="_blank" tabindex="-1"><?php snippet('ticket') ?>Billetterie</a>
2024-09-12 15:39:44 +02:00
<?php endif ?>
</div>
2024-09-02 17:09:53 +02:00
</div>
2024-09-20 10:14:43 +02:00
<a class="event-link" href="<?= $session['event-url'] ?>" title="En savoir plus" tabindex="-1"></a>
2024-09-02 16:32:21 +02:00
</li>
2024-09-04 15:56:19 +02:00
</template>
2024-09-02 14:02:13 +02:00
<?php endforeach ?>
2024-09-02 16:32:21 +02:00
</ul>
2024-08-30 15:16:41 +02:00
<?php endslot() ?>
<?php endsnippet() ?>
<?php endif ?>
<?php endforeach ?>
</section>
</div>
</template>
2024-08-30 14:37:13 +02:00
</div>
</div>
2024-08-28 19:11:58 +02:00
<?php snippet('footer') ?>