Actualiser api.php

This commit is contained in:
2026-07-01 16:46:16 +02:00
parent 44137a4030
commit dc60e1a72b
+20 -18
View File
@@ -787,27 +787,29 @@ case 'save_config':
break; break;
case 'get_films': case 'get_films':
// 1. Récupération des critiques // 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(); $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) // CORRECTION : Utilisation du & pour modifier le tableau original
foreach ($critiques as $row) { foreach ($critiques 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); // Sécurité pour libérer la référence
unset($row);
// 2. Récupération de la vidéothèque // 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(); $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 // LOGGING : Utile pour voir dans php_errors.log si les tables sont vides
echo json_encode([ error_log("API get_films - Critiques trouvées: " . count($critiques) . " | Vidéothèque: " . count($videotheque));
'critiques' => $critiques,
'videotheque' => $videotheque echo json_encode([
]); 'critiques' => $critiques,
break; 'videotheque' => $videotheque
]);
break;
case 'save_film': case 'save_film':
checkAuth($pdo); checkAuth($pdo);