Fix function calling

This commit is contained in:
2026-07-11 11:23:31 +02:00
parent b2787a4b8e
commit 96f9c6c7f8
+8 -21
View File
@@ -9,46 +9,33 @@ class Movie {
$this->db = $db;
}
// Ajoute un film (toujours en perso par défaut)
public function add($userId, $tmdbId, $title, $poster, $type) {
// 1. On vérifie si le film existe déjà pour cet utilisateur
$stmt = $this->db->prepare("SELECT id FROM movies WHERE user_id = ? AND tmdb_id = ?");
$stmt->execute([$userId, $tmdbId]);
if ($stmt->fetch()) {
// Le film est déjà dans la liste de cet utilisateur
return false;
}
// 2. Sinon, on insère
$stmt = $this->db->prepare("INSERT INTO movies (user_id, tmdb_id, title, poster_path, media_type, is_common) VALUES (?, ?, ?, ?, ?, 0)");
return $stmt->execute([$userId, $tmdbId, $title, $poster, $type]);
}
// Bascule un film en "Commune"
public function share($movieId, $userId) {
// On vérifie que le film appartient bien à l'utilisateur avant de le partager
$stmt = $this->db->prepare("UPDATE movies SET is_common = 1 WHERE id = ? AND user_id = ?");
return $stmt->execute([$movieId, $userId]);
}
// Récupère les 3 listes
public function getAllLists($myId, $partnerId) {
// 1. Perso (mes films non partagés)
$stmt = $this->db->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 0");
// C'est celle-ci qui manquait !
public function getLists($myId, $partnerId) {
// 1. Perso
$stmt = $this->db->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 0 ORDER BY added_at DESC");
$stmt->execute([$myId]);
$perso = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 2. Partenaire (ses films non partagés)
// 2. Partenaire
$partner = [];
if ($partnerId) {
$stmt = $this->db->prepare("SELECT * FROM movies WHERE user_id = ? AND is_common = 0");
$stmt = $this->db->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. Commune (tous les films avec is_common = 1)
$stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1");
// 3. Commune
$stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1 ORDER BY added_at DESC");
$stmt->execute();
$common = $stmt->fetchAll(PDO::FETCH_ASSOC);