Actualiser api.php
This commit is contained in:
@@ -786,26 +786,28 @@ case 'save_config':
|
|||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user