From b958d948765befed9093feece1fa4dfc89e88f72 Mon Sep 17 00:00:00 2001 From: Whykioh Date: Sat, 11 Jul 2026 11:13:35 +0200 Subject: [PATCH] Fix twice issue --- models/Movie.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/models/Movie.php b/models/Movie.php index c7111fb..5900913 100644 --- a/models/Movie.php +++ b/models/Movie.php @@ -10,9 +10,19 @@ class Movie { } // Ajoute un film (toujours en perso par défaut) - public function add($userId, $tmdbId, $title, $posterPath, $type) { + 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, $posterPath, $type]); + return $stmt->execute([$userId, $tmdbId, $title, $poster, $type]); } // Bascule un film en "Commune"