mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
180 lines
5.1 KiB
PHP
180 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class Actor extends Model
|
|
{
|
|
protected string $table = 'actors';
|
|
protected array $fillable = [
|
|
'name',
|
|
'thumbnail_path',
|
|
'metadata'
|
|
];
|
|
|
|
protected array $casts = [
|
|
'metadata' => 'array'
|
|
];
|
|
|
|
/**
|
|
* Get all movies this actor is associated with
|
|
*/
|
|
public function movies()
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT m.*, s.display_name as source_name
|
|
FROM movies m
|
|
JOIN sources s ON m.source_id = s.id
|
|
JOIN actor_movie am ON m.id = am.movie_id
|
|
WHERE am.actor_id = :actor_id
|
|
ORDER BY m.release_date DESC, m.title ASC
|
|
");
|
|
$stmt->execute(['actor_id' => $this->id]);
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
/**
|
|
* Get all TV shows this actor is associated with
|
|
*/
|
|
public function tvShows()
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT ts.*, s.display_name as source_name
|
|
FROM tv_shows ts
|
|
JOIN sources s ON ts.source_id = s.id
|
|
JOIN actor_tv_show ats ON ts.id = ats.tv_show_id
|
|
WHERE ats.actor_id = :actor_id
|
|
ORDER BY ts.first_air_date DESC, ts.title ASC
|
|
");
|
|
$stmt->execute(['actor_id' => $this->id]);
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
/**
|
|
* Get all adult videos this actor is associated with
|
|
*/
|
|
public function adultVideos()
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT av.*, s.display_name as source_name
|
|
FROM adult_videos av
|
|
JOIN sources s ON av.source_id = s.id
|
|
JOIN actor_adult_video aav ON av.id = aav.adult_video_id
|
|
WHERE aav.actor_id = :actor_id
|
|
ORDER BY av.release_date DESC, av.title ASC
|
|
");
|
|
$stmt->execute(['actor_id' => $this->id]);
|
|
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
/**
|
|
* Get actor statistics
|
|
*/
|
|
public function getStats(): array
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT
|
|
COUNT(DISTINCT am.movie_id) as movie_count,
|
|
COUNT(DISTINCT ats.tv_show_id) as tv_show_count,
|
|
COUNT(DISTINCT aav.adult_video_id) as adult_video_count,
|
|
COUNT(DISTINCT am.movie_id) + COUNT(DISTINCT ats.tv_show_id) + COUNT(DISTINCT aav.adult_video_id) as total_media_count
|
|
FROM actors a
|
|
LEFT JOIN actor_movie am ON a.id = am.actor_id
|
|
LEFT JOIN actor_tv_show ats ON a.id = ats.actor_id
|
|
LEFT JOIN actor_adult_video aav ON a.id = aav.actor_id
|
|
WHERE a.id = :actor_id
|
|
");
|
|
$stmt->execute(['actor_id' => $this->id]);
|
|
return $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
/**
|
|
* Link actor to a movie
|
|
*/
|
|
public function linkToMovie(int $movieId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
INSERT IGNORE INTO actor_movie (actor_id, movie_id)
|
|
VALUES (:actor_id, :movie_id)
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'movie_id' => $movieId
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Link actor to a TV show
|
|
*/
|
|
public function linkToTvShow(int $tvShowId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
INSERT IGNORE INTO actor_tv_show (actor_id, tv_show_id)
|
|
VALUES (:actor_id, :tv_show_id)
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'tv_show_id' => $tvShowId
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Link actor to an adult video
|
|
*/
|
|
public function linkToAdultVideo(int $adultVideoId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
INSERT IGNORE INTO actor_adult_video (actor_id, adult_video_id)
|
|
VALUES (:actor_id, :adult_video_id)
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'adult_video_id' => $adultVideoId
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Unlink actor from a movie
|
|
*/
|
|
public function unlinkFromMovie(int $movieId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
DELETE FROM actor_movie
|
|
WHERE actor_id = :actor_id AND movie_id = :movie_id
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'movie_id' => $movieId
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Unlink actor from a TV show
|
|
*/
|
|
public function unlinkFromTvShow(int $tvShowId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
DELETE FROM actor_tv_show
|
|
WHERE actor_id = :actor_id AND tv_show_id = :tv_show_id
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'tv_show_id' => $tvShowId
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Unlink actor from an adult video
|
|
*/
|
|
public function unlinkFromAdultVideo(int $adultVideoId): bool
|
|
{
|
|
$stmt = $this->pdo->prepare("
|
|
DELETE FROM actor_adult_video
|
|
WHERE actor_id = :actor_id AND adult_video_id = :adult_video_id
|
|
");
|
|
return $stmt->execute([
|
|
'actor_id' => $this->id,
|
|
'adult_video_id' => $adultVideoId
|
|
]);
|
|
}
|
|
}
|