Actualiser api.php
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user