mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
...
This commit is contained in:
@@ -39,7 +39,11 @@ class Movie extends Model
|
||||
|
||||
public function source()
|
||||
{
|
||||
return new Source($this->pdo);
|
||||
$stmt = $this->pdo->prepare("SELECT * FROM sources WHERE id = :source_id");
|
||||
$stmt->execute(['source_id' => $this->source_id]);
|
||||
$sourceData = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
return $sourceData ? new Source($this->pdo, $sourceData) : null;
|
||||
}
|
||||
|
||||
public function markAsWatched(): bool
|
||||
@@ -88,7 +92,7 @@ class Movie extends Model
|
||||
SUM(runtime_minutes) as total_runtime
|
||||
FROM movies
|
||||
");
|
||||
return $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public static function getRecent(\PDO $pdo, int $limit = 10): array
|
||||
@@ -102,7 +106,7 @@ class Movie extends Model
|
||||
LIMIT :limit
|
||||
");
|
||||
$stmt->execute(['limit' => $limit]);
|
||||
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
public static function getTotalCount(\PDO $pdo, string $search = ''): int
|
||||
@@ -162,4 +166,64 @@ class Movie extends Model
|
||||
$stmt->execute(['limit' => $limit]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all actors associated with this movie
|
||||
*/
|
||||
public function actors()
|
||||
{
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT a.*
|
||||
FROM actors a
|
||||
JOIN actor_movie am ON a.id = am.actor_id
|
||||
WHERE am.movie_id = :movie_id
|
||||
ORDER BY a.name ASC
|
||||
");
|
||||
$stmt->execute(['movie_id' => $this->id]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an actor to this movie
|
||||
*/
|
||||
public function addActor(int $actorId): bool
|
||||
{
|
||||
$stmt = $this->pdo->prepare("
|
||||
INSERT IGNORE INTO actor_movie (movie_id, actor_id)
|
||||
VALUES (:movie_id, :actor_id)
|
||||
");
|
||||
return $stmt->execute([
|
||||
'movie_id' => $this->id,
|
||||
'actor_id' => $actorId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an actor from this movie
|
||||
*/
|
||||
public function removeActor(int $actorId): bool
|
||||
{
|
||||
$stmt = $this->pdo->prepare("
|
||||
DELETE FROM actor_movie
|
||||
WHERE movie_id = :movie_id AND actor_id = :actor_id
|
||||
");
|
||||
return $stmt->execute([
|
||||
'movie_id' => $this->id,
|
||||
'actor_id' => $actorId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cast field with actor names
|
||||
*/
|
||||
public function updateCastField(): bool
|
||||
{
|
||||
$actors = $this->actors();
|
||||
$actorNames = array_column($actors, 'name');
|
||||
$castString = implode(', ', $actorNames);
|
||||
|
||||
return $this->update($this->id, [
|
||||
'cast' => $castString
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user