44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
// models/Movie.php
|
|
|
|
class Movie {
|
|
private $db;
|
|
|
|
public function __construct($db) {
|
|
$this->db = $db;
|
|
}
|
|
|
|
public function add($userId, $tmdbId, $title, $poster, $type) {
|
|
$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]);
|
|
}
|
|
|
|
public function share($movieId, $userId) {
|
|
$stmt = $this->db->prepare("UPDATE movies SET is_common = 1 WHERE id = ? AND user_id = ?");
|
|
return $stmt->execute([$movieId, $userId]);
|
|
}
|
|
|
|
// 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
|
|
$partner = [];
|
|
if ($partnerId) {
|
|
$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
|
|
$stmt = $this->db->prepare("SELECT * FROM movies WHERE is_common = 1 ORDER BY added_at DESC");
|
|
$stmt->execute();
|
|
$common = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
return ["perso" => $perso, "partner" => $partner, "common" => $common];
|
|
}
|
|
} |