From f549ceabfc6050c61a69ece31b4297284e6cd1db Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 1 Jul 2026 16:40:46 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/api.php b/api.php index c35053b..0f63ab5 100644 --- a/api.php +++ b/api.php @@ -785,28 +785,30 @@ case 'save_config': $stmt->execute([$name, encryptData($val)]); echo json_encode(["success" => true]); break; - - case 'get_films': - $sql = " - SELECT id, title, year, director, poster, rating, review, NULL AS description, streaming, 'critique' AS type, NULL AS format - FROM critiques - UNION ALL - SELECT id, title, year, director, poster, NULL AS rating, NULL AS review, description, NULL AS streaming, 'videotheque' AS type, format - FROM videotheque - ORDER BY id DESC - "; - $result = $pdo->query($sql)->fetchAll(); - // IMPORTANT : Utilisation du pointeur `&` pour que la modification soit effective dans $result - foreach ($result as $row) { - if ($row['rating'] !== null) { - $ratingVal = (float)$row['rating']; - $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal; - } + +case 'get_films': + // 1. Récupération des critiques + $critiques = $pdo->query("SELECT id, title, year, director, poster, rating, review, NULL AS description, streaming, 'critique' AS type, NULL AS format FROM critiques ORDER BY id DESC")->fetchAll(); + + // Correction des notes (format entier si rond) + foreach ($critiques as $row) { + if ($row['rating'] !== null) { + $ratingVal = (float)$row['rating']; + $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal; } - unset($row); - echo json_encode($result); - break; - + } + unset($row); + + // 2. Récupération de la vidéothèque + $videotheque = $pdo->query("SELECT id, title, year, director, poster, NULL AS rating, NULL AS review, description, NULL AS streaming, 'videotheque' AS type, format FROM videotheque ORDER BY id DESC")->fetchAll(); + + // 3. Retourne les deux listes séparées + echo json_encode([ + 'critiques' => $critiques, + 'videotheque' => $videotheque + ]); + break; + case 'save_film': checkAuth($pdo); $type = $data['type'] ?? 'critique';