Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/init_client.php';
|
||||
|
||||
|
||||
if (!isset($_GET['praticien_id'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => $translations['id_praticien_manquant']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$praticien_id = intval($_GET['praticien_id']);
|
||||
|
||||
// Récupérer la durée d'un rendez-vous
|
||||
$stmt = $pdo->prepare("SELECT duree_rdv FROM praticien WHERE id = ?");
|
||||
$stmt->execute([$praticien_id]);
|
||||
$duree_minutes = (int)$stmt->fetchColumn();
|
||||
if (!$duree_minutes) {
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$date_debut = new DateTimeImmutable();
|
||||
$date_fin = $date_debut->modify('+3 weeks');
|
||||
|
||||
// Récupérer toutes les disponibilités du praticien
|
||||
$stmt = $pdo->prepare("SELECT jour_semaine, heure_debut, heure_fin FROM disponibilite WHERE praticien_id = ?");
|
||||
$stmt->execute([$praticien_id]);
|
||||
$dispos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Récupérer tous les rendez-vous déjà réservés dans cette période
|
||||
$stmt = $pdo->prepare("SELECT date_rdv FROM rendez_vous WHERE praticien_id = ? AND date_rdv BETWEEN ? AND ?");
|
||||
$stmt->execute([$praticien_id, $date_debut->format('Y-m-d H:i:s'), $date_fin->format('Y-m-d H:i:s')]);
|
||||
$reservations_existantes = array_map(function($r) {
|
||||
return (new DateTimeImmutable($r['date_rdv']))->format('Y-m-d H:i');
|
||||
}, $stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
|
||||
$events = [];
|
||||
|
||||
$periode = new DatePeriod(
|
||||
$date_debut,
|
||||
new DateInterval('P1D'),
|
||||
$date_fin
|
||||
);
|
||||
|
||||
foreach ($periode as $jour) {
|
||||
$jour_semaine = (int)$jour->format('N'); // 1 = lundi, 7 = dimanche
|
||||
|
||||
|
||||
foreach ($dispos as $dispo) {
|
||||
if ((int)$dispo['jour_semaine'] !== $jour_semaine) continue;
|
||||
|
||||
$heure_debut = DateTime::createFromFormat('H:i:s', $dispo['heure_debut']);
|
||||
$heure_fin = DateTime::createFromFormat('H:i:s', $dispo['heure_fin']);
|
||||
if (!$heure_debut || !$heure_fin) continue;
|
||||
|
||||
$debut_creneau = (new DateTimeImmutable($jour->format('Y-m-d') . ' ' . $heure_debut->format('H:i:s')));
|
||||
$fin_creneau = (new DateTimeImmutable($jour->format('Y-m-d') . ' ' . $heure_fin->format('H:i:s')));
|
||||
|
||||
while ($debut_creneau->add(new DateInterval('PT' . $duree_minutes . 'M')) <= $fin_creneau) {
|
||||
$fin = $debut_creneau->add(new DateInterval('PT' . $duree_minutes . 'M'));
|
||||
$start_str = $debut_creneau->format('Y-m-d H:i');
|
||||
|
||||
if (!in_array($start_str, $reservations_existantes)) {
|
||||
$events[] = [
|
||||
'title' => $debut_creneau->format('H:i'),
|
||||
'start' => $debut_creneau->format(DateTime::ATOM),
|
||||
'end' => $fin->format(DateTime::ATOM)
|
||||
];
|
||||
}
|
||||
|
||||
$debut_creneau = $fin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($events);
|
||||
Reference in new issue
Block a user