Actualiser api.php

This commit is contained in:
2026-07-01 16:40:46 +02:00
parent 6641a20319
commit f549ceabfc
+14 -12
View File
@@ -787,24 +787,26 @@ case 'save_config':
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
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) { if ($row['rating'] !== null) {
$ratingVal = (float)$row['rating']; $ratingVal = (float)$row['rating'];
$row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal; $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal;
} }
} }
unset($row); unset($row);
echo json_encode($result);
// 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; break;
case 'save_film': case 'save_film':