Add movies lists

This commit is contained in:
2026-07-11 10:55:59 +02:00
parent 45e5f8d6c6
commit d8aa88a8fb
2 changed files with 115 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
// models/Movie.php
class Movie {
private $conn;
public function __construct($db) {
$this->conn = $db;
}
// Ajouter un film
public function add($userId, $tmdbId, $title, $posterPath, $mediaType, $isCommon) {
$query = "INSERT INTO movies (user_id, tmdb_id, title, poster_path, media_type, is_common)
VALUES (:user_id, :tmdb_id, :title, :poster_path, :media_type, :is_common)";
$stmt = $this->conn->prepare($query);
try {
$stmt->execute([
':user_id' => $userId,
':tmdb_id' => $tmdbId,
':title' => $title,
':poster_path' => $posterPath,
':media_type' => $mediaType,
':is_common' => $isCommon ? 1 : 0
]);
return ["success" => true, "message" => "Film ajouté avec succès."];
} catch (PDOException $e) {
return ["success" => false, "message" => "Erreur lors de l'ajout : " . $e->getMessage()];
}
}
// Récupérer les 3 listes d'un coup
public function getLists($userId, $partnerId) {
// 1. Liste perso
$stmt = $this->conn->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 0 ORDER BY added_at DESC");
$stmt->execute([$userId]);
$perso = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 2. Liste du partenaire (vide si pas de partenaire)
$partner = [];
if ($partnerId) {
$stmt = $this->conn->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 0 ORDER BY added_at DESC");
$stmt->execute([$partnerId]);
$partner = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// 3. Liste commune (toi + partenaire si lié, sinon juste toi)
if ($partnerId) {
$stmt = $this->conn->prepare("SELECT * FROM movies WHERE (user_id = ? OR user_id = ?) AND is_common = 1 ORDER BY added_at DESC");
$stmt->execute([$userId, $partnerId]);
} else {
$stmt = $this->conn->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 1 ORDER BY added_at DESC");
$stmt->execute([$userId]);
}
$common = $stmt->fetchAll(PDO::FETCH_ASSOC);
return [
"success" => true,
"lists" => [
"perso" => $perso,
"partner" => $partner,
"common" => $common
]
];
}
}