Actualiser api.php

This commit is contained in:
2026-07-01 16:40:46 +02:00
parent 6641a20319
commit f549ceabfc
+23 -21
View File
@@ -785,28 +785,30 @@ case 'save_config':
$stmt->execute([$name, encryptData($val)]); $stmt->execute([$name, encryptData($val)]);
echo json_encode(["success" => true]); echo json_encode(["success" => true]);
break; break;
case 'get_films': case 'get_films':
$sql = " // 1. Récupération des critiques
SELECT id, title, year, director, poster, rating, review, NULL AS description, streaming, 'critique' AS type, NULL AS format $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();
FROM critiques
UNION ALL // Correction des notes (format entier si rond)
SELECT id, title, year, director, poster, NULL AS rating, NULL AS review, description, NULL AS streaming, 'videotheque' AS type, format foreach ($critiques as $row) {
FROM videotheque if ($row['rating'] !== null) {
ORDER BY id DESC $ratingVal = (float)$row['rating'];
"; $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal;
$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;
}
} }
unset($row); }
echo json_encode($result); unset($row);
break;
// 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': case 'save_film':
checkAuth($pdo); checkAuth($pdo);
$type = $data['type'] ?? 'critique'; $type = $data['type'] ?? 'critique';