Add auto couple movie
This commit is contained in:
+22
-1
@@ -10,8 +10,29 @@ class Movie {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function add($userId, $tmdbId, $title, $poster, $type) {
|
public function add($userId, $tmdbId, $title, $poster, $type) {
|
||||||
|
// 1. On insère le film
|
||||||
$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]);
|
$stmt->execute([$userId, $tmdbId, $title, $poster, $type]);
|
||||||
|
|
||||||
|
// 2. On récupère l'ID du partenaire (supposons que tu as une table 'users' avec un champ 'partner_id')
|
||||||
|
$stmt = $this->db->prepare("SELECT partner_id FROM users WHERE id = ?");
|
||||||
|
$stmt->execute([$userId]);
|
||||||
|
$partnerId = $stmt->fetchColumn();
|
||||||
|
|
||||||
|
// 3. Si un partenaire existe, on cherche s'il a déjà ce film
|
||||||
|
if ($partnerId) {
|
||||||
|
$stmt = $this->db->prepare("SELECT id FROM movies WHERE user_id = ? AND tmdb_id = ? AND is_common = 0");
|
||||||
|
$stmt->execute([$partnerId, $tmdbId]);
|
||||||
|
$partnerMovie = $stmt->fetch();
|
||||||
|
|
||||||
|
// 4. Si le partenaire a le film, on bascule les DEUX en "common"
|
||||||
|
if ($partnerMovie) {
|
||||||
|
$stmt = $this->db->prepare("UPDATE movies SET is_common = 1 WHERE tmdb_id = ? AND (user_id = ? OR user_id = ?)");
|
||||||
|
$stmt->execute([$tmdbId, $userId, $partnerId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function share($movieId, $userId) {
|
public function share($movieId, $userId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user