Fix function calling
This commit is contained in:
+8
-21
@@ -9,46 +9,33 @@ class Movie {
|
|||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajoute un film (toujours en perso par défaut)
|
|
||||||
public function add($userId, $tmdbId, $title, $poster, $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)");
|
$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]);
|
return $stmt->execute([$userId, $tmdbId, $title, $poster, $type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bascule un film en "Commune"
|
|
||||||
public function share($movieId, $userId) {
|
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 = ?");
|
$stmt = $this->db->prepare("UPDATE movies SET is_common = 1 WHERE id = ? AND user_id = ?");
|
||||||
return $stmt->execute([$movieId, $userId]);
|
return $stmt->execute([$movieId, $userId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupère les 3 listes
|
// C'est celle-ci qui manquait !
|
||||||
public function getAllLists($myId, $partnerId) {
|
public function getLists($myId, $partnerId) {
|
||||||
// 1. Perso (mes films non partagés)
|
// 1. Perso
|
||||||
$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([$myId]);
|
$stmt->execute([$myId]);
|
||||||
$perso = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$perso = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
// 2. Partenaire (ses films non partagés)
|
// 2. Partenaire
|
||||||
$partner = [];
|
$partner = [];
|
||||||
if ($partnerId) {
|
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]);
|
$stmt->execute([$partnerId]);
|
||||||
$partner = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$partner = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Commune (tous les films avec is_common = 1)
|
// 3. Commune
|
||||||
$stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1");
|
$stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1 ORDER BY added_at DESC");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$common = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$common = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user