dates de distribution fixes et site màj dynamiquement

This commit is contained in:
Pierre Martin
2025-11-16 21:41:11 +01:00
parent d4c06939b8
commit 21c34a2cd9
4 changed files with 439 additions and 78 deletions
+63
View File
@@ -0,0 +1,63 @@
# Gestion des distributions
## Comment mettre à jour les dates de distribution
Les dates de distribution sont gérées dans le fichier `distributions.php`.
### Ajouter une nouvelle distribution
Ajouter une entrée dans le tableau :
```php
[
'date' => '2026-07-11', // Format YYYY-MM-DD
'lieu' => 'grange', // 'grange' ou 'secours'
'type' => 'normal' // 'normal', 'special' ou 'annulee'
]
```
### Distribution spéciale
Pour une distribution avec un label spécial (ex: Noël, Guinguette) :
```php
[
'date' => '2025-12-17',
'lieu' => 'grange',
'type' => 'special',
'label' => '🎅 Distribution de Noël 🎅'
]
```
### Distribution annulée
Pour indiquer une date où il n'y a pas de distribution :
```php
[
'date' => '2026-02-14',
'lieu' => null,
'type' => 'annulee',
'label' => 'Pas de distribution',
'raison' => 'Salon des vins et producteurs locaux'
]
```
### Lieux disponibles
- `'grange'` : La Grange de FIC (7 rue du Vieux Moulin)
- `'secours'` : Secours Populaire (28 rue Guillaume Berdeil)
## Comment ça marche
Le script PHP :
1. Charge les distributions depuis `distributions.php`
2. Trouve automatiquement la prochaine distribution
3. Affiche le calendrier avec :
- Les dates passées en grisé
- La prochaine date en surbrillance verte
- Les dates futures en vert clair
- Les dates annulées en rouge
Les dates sont triées chronologiquement et la première date future devient automatiquement "Prochaine distribution".
+208
View File
@@ -0,0 +1,208 @@
<?php
/**
* Fonctions utilitaires pour gérer les distributions
*/
/**
* Charge les distributions depuis le fichier de configuration
*/
function chargerDistributions(): array {
return require __DIR__ . '/distributions.php';
}
/**
* Trouve la prochaine distribution
*/
function trouverProchaineDistribution(array $distributions): ?array {
$maintenant = new DateTime();
foreach ($distributions as $distrib) {
$date = new DateTime($distrib['date']);
if ($date >= $maintenant) {
return $distrib;
}
}
return null;
}
/**
* Vérifie si une distribution est passée
*/
function estPassee(array $distribution): bool {
$maintenant = new DateTime();
$date = new DateTime($distribution['date']);
return $date < $maintenant;
}
/**
* Formate une date de distribution
*/
function formaterDate(string $date): string {
$dateObj = new DateTime($date);
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::LONG,
IntlDateFormatter::NONE
);
// Retirer l'année si c'est l'année courante
$dateFormatee = $formatter->format($dateObj);
// Ajouter le jour de la semaine si ce n'est pas un samedi
$jourSemaine = $dateObj->format('N'); // 1=lundi, 6=samedi
if ($jourSemaine != 6) {
$joursTraduction = [
1 => 'Lundi',
2 => 'Mardi',
3 => 'Mercredi',
4 => 'Jeudi',
5 => 'Vendredi',
7 => 'Dimanche'
];
return $joursTraduction[$jourSemaine] . ' ' . $dateObj->format('d') . ' ' .
ucfirst($formatter->format($dateObj));
}
return ucfirst($dateFormatee);
}
/**
* Formate une date courte (pour le calendrier)
*/
function formaterDateCourte(string $date): string {
$dateObj = new DateTime($date);
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::LONG,
IntlDateFormatter::NONE,
'Europe/Paris',
IntlDateFormatter::GREGORIAN,
'd MMMM yyyy'
);
// Vérifier si ce n'est pas un samedi
$jourSemaine = $dateObj->format('N');
if ($jourSemaine != 6) {
$joursTraduction = [
1 => 'Lundi',
2 => 'Mardi',
3 => 'Mercredi',
4 => 'Jeudi',
5 => 'Vendredi',
7 => 'Dimanche'
];
return '<strong>' . $joursTraduction[$jourSemaine] . '</strong> ' .
$formatter->format($dateObj);
}
return $formatter->format($dateObj);
}
/**
* Formate une date complète avec jour de la semaine
*/
function formaterDateComplete(DateTime $date): string {
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::NONE,
'Europe/Paris',
IntlDateFormatter::GREGORIAN,
'EEEE d MMMM'
);
return ucfirst($formatter->format($date));
}
/**
* Formate une date pour le calendrier
*/
function formaterDateCalendrier(DateTime $date): string {
$formatter = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::LONG,
IntlDateFormatter::NONE,
'Europe/Paris',
IntlDateFormatter::GREGORIAN,
'd MMMM yyyy'
);
return $formatter->format($date);
}
/**
* Retourne l'info du lieu de distribution
*/
function getLieuInfo(string $lieu): array {
$lieux = [
'grange' => [
'nom' => 'La Grange',
'adresse' => '7 rue du Vieux Moulin',
'url' => 'https://www.openstreetmap.org/#map=19/43.51294/1.32234',
'description' => 'à « La Grange » de <abbr title="Frouzins Initiatives Citoyennes">FIC</abbr> 7 rue du Vieux Moulin'
],
'secours' => [
'nom' => 'Secours Populaire',
'adresse' => '28 rue Guillaume Berdeil',
'url' => 'https://www.openstreetmap.org/?mlat=43.516927&mlon=1.319663#map=19/43.516927/1.319663',
'description' => 'au Secours Populaire de Frouzins 28 rue Guillaume Berdeil'
]
];
return $lieux[$lieu] ?? [];
}
/**
* Classe CSS pour le type de distribution
*/
function getClasseDistribution(array $distribution, bool $estProchaine): string {
if ($estProchaine) {
return 'bg-green-500';
}
if (estPassee($distribution)) {
return 'bg-gray-50 opacity-50';
}
if ($distribution['type'] === 'annulee') {
return 'bg-red-100';
}
return 'bg-green-100';
}
/**
* Classe CSS pour le texte
*/
function getClasseTexte(array $distribution, bool $estProchaine): string {
if ($estProchaine) {
return 'text-white';
}
if ($distribution['type'] === 'annulee') {
return 'text-red-800';
}
if (estPassee($distribution)) {
return 'text-gray-800';
}
return 'text-green-800';
}
/**
* Label du statut
*/
function getLabelStatut(array $distribution, bool $estProchaine): ?string {
if ($estProchaine) {
return 'Prochaine';
}
if (estPassee($distribution)) {
return 'Passée';
}
return null;
}
+109
View File
@@ -0,0 +1,109 @@
<?php
/**
* Configuration des distributions Les Frouzivores
*
* Chaque distribution peut avoir :
* - date : la date au format 'YYYY-MM-DD'
* - lieu : 'grange' ou 'secours'
* - type : 'normal', 'special', 'annulee'
* - label : optionnel, pour les événements spéciaux
*/
return [
[
'date' => '2025-09-13',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2025-09-27',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2025-10-11',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2025-10-25',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2025-11-08',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2025-11-22',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2025-12-17',
'lieu' => 'grange',
'type' => 'special',
'label' => '🎅 Distribution de Noël 🎅'
],
[
'date' => '2026-01-10',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2026-01-24',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2026-02-14',
'lieu' => null,
'type' => 'annulee',
'label' => 'Pas de distribution',
'raison' => 'Salon des vins et producteurs locaux'
],
[
'date' => '2026-02-28',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2026-03-14',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2026-03-28',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2026-04-11',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2026-04-25',
'lieu' => 'secours',
'type' => 'normal'
],
[
'date' => '2026-05-27',
'lieu' => 'secours',
'type' => 'special',
'label' => ''
],
[
'date' => '2026-06-13',
'lieu' => 'grange',
'type' => 'normal'
],
[
'date' => '2026-07-01',
'lieu' => 'grange',
'type' => 'special',
'label' => '🍻 La Guinguette 👯'
]
];
+59 -78
View File
@@ -1,3 +1,9 @@
<?php
require_once __DIR__ . '/distributions-utils.php';
$distributions = chargerDistributions();
$prochaineDistribution = trouverProchaineDistribution($distributions);
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<head> <head>
@@ -40,6 +46,11 @@
ligne et une distribution conviviale à Frouzins. ligne et une distribution conviviale à Frouzins.
</p> </p>
<?php if ($prochaineDistribution && $prochaineDistribution['type'] !== 'annulee'): ?>
<?php
$dateObj = new DateTime($prochaineDistribution['date']);
$lieuInfo = getLieuInfo($prochaineDistribution['lieu']);
?>
<div <div
class="mt-12 bg-white rounded-lg shadow-lg p-6 max-w-2xl mx-auto" class="mt-12 bg-white rounded-lg shadow-lg p-6 max-w-2xl mx-auto"
> >
@@ -49,26 +60,25 @@
<i class="fas fa-calendar text-xl"></i> <i class="fas fa-calendar text-xl"></i>
<span class="text-lg font-semibold">Prochaine distribution</span> <span class="text-lg font-semibold">Prochaine distribution</span>
</div> </div>
<p class="text-2xl font-bold text-gray-900">Samedi 11 octobre</p> <p class="text-2xl font-bold text-gray-900">
<?= formaterDateComplete($dateObj) ?>
</p>
<p class="text-xs text-gray-600">10h-12h</p> <p class="text-xs text-gray-600">10h-12h</p>
<p class="text-gray-600 mt-2"> <p class="text-gray-600 mt-2">
<!-- <a
href="https://www.openstreetmap.org/#map=19/43.51294/1.32234"
class="text-green-600 hover:underline"
>
à « La Grange » de
<abbr title="Frouzins Initiatives Citoyennes">FIC</abbr> 7 rue
du Vieux Moulin
</a> -->
<a <a
href="https://www.openstreetmap.org/?mlat=43.516927&mlon=1.319663#map=19/43.516927/1.319663" href="<?= htmlspecialchars($lieuInfo['url']) ?>"
class="text-green-600 hover:underline" class="text-green-600 hover:underline"
> >
au Secours Populaire de Frouzins 28 rue Guillaume Berdeil <?= $lieuInfo['description'] ?>
</a> </a>
</p> </p>
<?php if (!empty($prochaineDistribution['label'])): ?>
<p class="text-lg font-semibold text-green-600 mt-4">
<?= htmlspecialchars($prochaineDistribution['label']) ?>
</p>
<?php endif; ?>
<div class="mt-8"> <div class="mt-8">
<a <a
href="https://www.local.direct/les-frouzivores" href="https://www.local.direct/les-frouzivores"
@@ -79,6 +89,7 @@
</a> </a>
</div> </div>
</div> </div>
<?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
@@ -232,8 +243,8 @@
</p> </p>
<p class="mt-4 text-lg text-gray-500"> <p class="mt-4 text-lg text-gray-500">
Ajoutez un ou plusieurs produits portant la mention « au profit du Ajoutez un ou plusieurs produits portant la mention « au profit du
secours populaire » à votre panier. Ils seront remis aux secours populaire » à votre panier. Ils seront remis aux
bénéficiaires dans les jours qui suivent la distribution. bénéficiaires dans les jours qui suivent la distribution.
</p> </p>
<p class="mt-4 text-lg text-gray-600 font-bold"> <p class="mt-4 text-lg text-gray-600 font-bold">
@@ -265,79 +276,49 @@
</p> </p>
</div> </div>
<div class="mt-12 grid grid-cols-2 gap-4 md:grid-cols-4"> <div class="mt-12 grid grid-cols-2 gap-4 md:grid-cols-4">
<div class="bg-gray-50 rounded-lg p-4 text-center opacity-50"> <?php foreach ($distributions as $distribution): ?>
<p class="text-lg font-medium text-gray-800">24 septembre 2025</p> <?php
<p class="text-sm text-gray-600 font-semibold">Passée</p> $dateObj = new DateTime($distribution['date']);
</div> $estProchaine = $prochaineDistribution &&
<div class="bg-green-500 rounded-lg p-4 text-center"> $distribution['date'] === $prochaineDistribution['date'];
<p class="text-lg font-medium text-white">11 octobre 2025</p> $classe = getClasseDistribution($distribution, $estProchaine);
<p class="text-sm text-white font-semibold">Prochaine</p> $classeTexte = getClasseTexte($distribution, $estProchaine);
</div> $labelStatut = getLabelStatut($distribution, $estProchaine);
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">25 octobre 2025</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">8 novembre 2025</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">22 novembre 2025</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center"> // Déterminer si c'est un jour spécial (pas samedi)
<p class="text-lg font-medium text-green-800"> $jourSemaine = $dateObj->format('N');
<strong>Mercredi</strong> 17 décembre 2025 $estJourSpecial = $jourSemaine != 6;
?>
<div class="<?= $classe ?> rounded-lg p-4 text-center">
<p class="text-lg font-medium <?= $classeTexte ?>">
<?php if ($estJourSpecial): ?>
<?php
$formatterJour = new IntlDateFormatter('fr_FR', IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'Europe/Paris', IntlDateFormatter::GREGORIAN, 'EEEE');
echo '<strong>' . ucfirst($formatterJour->format($dateObj)) . '</strong> ';
?>
<?php endif; ?>
<?= formaterDateCalendrier($dateObj) ?>
</p> </p>
<p class="text-sm text-green-600 font-semibold">
🎅 Distribution de Noël 🎅
</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center"> <?php if ($labelStatut): ?>
<p class="text-lg font-medium text-green-800">10 janvier 2026</p> <p class="text-sm <?= $classeTexte ?> font-semibold">
</div> <?= htmlspecialchars($labelStatut) ?>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">24 janvier 2026</p>
</div>
<div class="bg-red-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-red-800">14 février 2026</p>
<p class="text-sm text-red-600 font-semibold">
Pas de distribution
</p> </p>
<p class="text-sm text-red-600"> <?php endif; ?>
Salon des vins et producteurs locaux
</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center"> <?php if (!empty($distribution['label'])): ?>
<p class="text-lg font-medium text-green-800">28 février 2026</p> <p class="text-sm <?= $classeTexte ?> font-semibold">
</div> <?= htmlspecialchars($distribution['label']) ?>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">14 mars 2026</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">28 mars 2026</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">11 avril 2026</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">25 avril 2026</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">
<strong>Mercredi</strong> 27 mai 2026
</p> </p>
</div> <?php endif; ?>
<div class="bg-green-100 rounded-lg p-4 text-center">
<p class="text-lg font-medium text-green-800">13 juin 2026</p>
</div>
<div class="bg-green-100 rounded-lg p-4 text-center"> <?php if (isset($distribution['raison'])): ?>
<p class="text-lg font-medium text-green-800">1 juillet 2025</p> <p class="text-sm <?= $classeTexte ?>">
<p class="text-sm text-green-600 font-semibold"> <?= htmlspecialchars($distribution['raison']) ?>
🍻 La Guinguette 👯
</p> </p>
<?php endif; ?>
</div> </div>
<?php endforeach; ?>
</div> </div>
</div> </div>
</div> </div>