mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
Remove obsolete test scripts and add new API controllers for dashboard and game management
- Deleted test scripts: test_jellyfin_execution.php, test_stash.php, test_xbvr.php, test_xbvr_sync.php, vite.config.js - Added DashboardController for fetching dashboard statistics and recent activity - Added GameController for managing games, including fetching all games, game details, and games by category - Introduced various check scripts to validate database structures and data integrity for adult videos, games, gender data, posters, and TV show actors
This commit is contained in:
@@ -356,62 +356,93 @@ class TvShow extends Model
|
||||
|
||||
public function getSeasonsWithEpisodes(): array
|
||||
{
|
||||
// Get all episodes for this TV show, grouped by season
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT season_number,
|
||||
COUNT(*) as episode_count,
|
||||
SUM(CASE WHEN watched = 1 THEN 1 ELSE 0 END) as watched_episodes
|
||||
FROM tv_episodes
|
||||
WHERE tv_show_id = :tv_show_id
|
||||
GROUP BY season_number
|
||||
ORDER BY season_number ASC
|
||||
");
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
$seasonStats = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$seasons = [];
|
||||
|
||||
// For each season, get the episodes and create a season object
|
||||
foreach ($seasonStats as $stat) {
|
||||
$seasonNumber = $stat['season_number'];
|
||||
|
||||
// Get episodes for this season
|
||||
try {
|
||||
// Get all episodes for this TV show, grouped by season
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT e.*
|
||||
FROM tv_episodes e
|
||||
WHERE e.tv_show_id = :tv_show_id AND e.season_number = :season_number
|
||||
ORDER BY e.episode_number ASC
|
||||
SELECT season_number,
|
||||
COUNT(*) as episode_count,
|
||||
SUM(CASE WHEN watched = 1 THEN 1 ELSE 0 END) as watched_episodes
|
||||
FROM tv_episodes
|
||||
WHERE tv_show_id = :tv_show_id
|
||||
GROUP BY season_number
|
||||
ORDER BY season_number ASC
|
||||
");
|
||||
$stmt->execute([
|
||||
'tv_show_id' => $this->id,
|
||||
'season_number' => $seasonNumber
|
||||
]);
|
||||
$episodes = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
$seasonStats = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Add actors for each episode
|
||||
foreach ($episodes as &$episode) {
|
||||
$episodeStmt = $this->pdo->prepare("
|
||||
SELECT a.*
|
||||
FROM actors a
|
||||
JOIN actor_tv_episode ate ON a.id = ate.actor_id
|
||||
WHERE ate.tv_episode_id = :tv_episode_id
|
||||
ORDER BY a.name ASC
|
||||
$seasons = [];
|
||||
|
||||
// For each season, get the episodes and create a season object
|
||||
foreach ($seasonStats as $stat) {
|
||||
$seasonNumber = $stat['season_number'];
|
||||
|
||||
// Get episodes for this season
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT e.*
|
||||
FROM tv_episodes e
|
||||
WHERE e.tv_show_id = :tv_show_id AND e.season_number = :season_number
|
||||
ORDER BY e.episode_number ASC
|
||||
");
|
||||
$episodeStmt->execute(['tv_episode_id' => $episode['id']]);
|
||||
$episode['actors'] = $episodeStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->execute([
|
||||
'tv_show_id' => $this->id,
|
||||
'season_number' => $seasonNumber
|
||||
]);
|
||||
$episodes = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Add actors for each episode
|
||||
foreach ($episodes as &$episode) {
|
||||
try {
|
||||
$episodeStmt = $this->pdo->prepare("
|
||||
SELECT a.*
|
||||
FROM actors a
|
||||
JOIN actor_tv_episode ate ON a.id = ate.actor_id
|
||||
WHERE ate.tv_episode_id = :tv_episode_id
|
||||
ORDER BY a.name ASC
|
||||
");
|
||||
$episodeStmt->execute(['tv_episode_id' => $episode['id']]);
|
||||
$episode['actors'] = $episodeStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
} catch (\Exception $e) {
|
||||
$episode['actors'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Create a season object (simulating the old seasons table structure)
|
||||
$seasons[] = [
|
||||
'id' => null, // No seasons table, so no ID
|
||||
'season_number' => $seasonNumber,
|
||||
'episode_count' => (int)$stat['episode_count'],
|
||||
'watched_episodes' => (int)$stat['watched_episodes'],
|
||||
'episodes' => $episodes
|
||||
];
|
||||
}
|
||||
|
||||
// Create a season object (simulating the old seasons table structure)
|
||||
$seasons[] = [
|
||||
'id' => null, // No seasons table, so no ID
|
||||
'season_number' => $seasonNumber,
|
||||
'episode_count' => (int)$stat['episode_count'],
|
||||
'watched_episodes' => (int)$stat['watched_episodes'],
|
||||
'episodes' => $episodes
|
||||
];
|
||||
return $seasons;
|
||||
} catch (\Exception $e) {
|
||||
// Return empty array if tables don't exist or query fails
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $seasons;
|
||||
/**
|
||||
* Get all actors for this TV show (from all episodes)
|
||||
*/
|
||||
public function getActors(): array
|
||||
{
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT DISTINCT a.*
|
||||
FROM actors a
|
||||
JOIN actor_tv_episode ate ON a.id = ate.actor_id
|
||||
JOIN tv_episodes te ON ate.tv_episode_id = te.id
|
||||
WHERE te.tv_show_id = :tv_show_id
|
||||
ORDER BY a.name ASC
|
||||
");
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
} catch (\Exception $e) {
|
||||
// Return empty array if tables don't exist or query fails
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -471,6 +502,147 @@ public static function getAvailableGenres(\PDO $pdo): array
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available sources from TV shows
|
||||
*/
|
||||
public static function getAvailableSources(\PDO $pdo): array
|
||||
{
|
||||
$stmt = $pdo->query("
|
||||
SELECT DISTINCT s.display_name
|
||||
FROM tv_shows t
|
||||
JOIN sources s ON t.source_id = s.id
|
||||
WHERE t.source_id IS NOT NULL
|
||||
ORDER BY s.display_name
|
||||
");
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all TV shows with filtering and pagination
|
||||
*/
|
||||
public function findAll(array $filters = [], int $limit = null, int $offset = 0): array
|
||||
{
|
||||
$sql = "
|
||||
SELECT t.*, s.display_name as source_name
|
||||
FROM tv_shows t
|
||||
LEFT JOIN sources s ON t.source_id = s.id
|
||||
";
|
||||
$params = [];
|
||||
$whereClauses = [];
|
||||
|
||||
// Search filter
|
||||
if (!empty($filters['search'])) {
|
||||
$whereClauses[] = "(t.title LIKE :search OR t.overview LIKE :search)";
|
||||
$params['search'] = "%{$filters['search']}%";
|
||||
}
|
||||
|
||||
// Genre filter
|
||||
if (!empty($filters['genre'])) {
|
||||
$whereClauses[] = "t.genre = :genre";
|
||||
$params['genre'] = $filters['genre'];
|
||||
}
|
||||
|
||||
// Year filter
|
||||
if (!empty($filters['year'])) {
|
||||
$whereClauses[] = "YEAR(t.first_air_date) = :year";
|
||||
$params['year'] = $filters['year'];
|
||||
}
|
||||
|
||||
// Source filter
|
||||
if (!empty($filters['sources'])) {
|
||||
$sources = is_array($filters['sources']) ? $filters['sources'] : [$filters['sources']];
|
||||
$placeholders = [];
|
||||
foreach ($sources as $index => $source) {
|
||||
$placeholders[] = ":source_{$index}";
|
||||
$params["source_{$index}"] = $source;
|
||||
}
|
||||
$whereClauses[] = "s.display_name IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
// Combine WHERE clauses
|
||||
if (!empty($whereClauses)) {
|
||||
$sql .= " WHERE " . implode(' AND ', $whereClauses);
|
||||
}
|
||||
|
||||
// Add ordering and pagination
|
||||
$sql .= " ORDER BY t.first_air_date DESC, t.title ASC";
|
||||
|
||||
if ($limit) {
|
||||
$sql .= " LIMIT :limit OFFSET :offset";
|
||||
$params['limit'] = $limit;
|
||||
$params['offset'] = $offset;
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Process metadata to extract additional fields
|
||||
foreach ($results as &$tvShow) {
|
||||
if (!empty($tvShow['metadata'])) {
|
||||
$metadata = json_decode($tvShow['metadata'], true);
|
||||
|
||||
// Extract additional fields from metadata if available
|
||||
// This can be expanded based on your metadata structure
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count TV shows with filters
|
||||
*/
|
||||
public function count(array $filters = []): int
|
||||
{
|
||||
$sql = "
|
||||
SELECT COUNT(*) as total
|
||||
FROM tv_shows t
|
||||
LEFT JOIN sources s ON t.source_id = s.id
|
||||
";
|
||||
$params = [];
|
||||
$whereClauses = [];
|
||||
|
||||
// Search filter
|
||||
if (!empty($filters['search'])) {
|
||||
$whereClauses[] = "(t.title LIKE :search OR t.overview LIKE :search)";
|
||||
$params['search'] = "%{$filters['search']}%";
|
||||
}
|
||||
|
||||
// Genre filter
|
||||
if (!empty($filters['genre'])) {
|
||||
$whereClauses[] = "t.genre = :genre";
|
||||
$params['genre'] = $filters['genre'];
|
||||
}
|
||||
|
||||
// Year filter
|
||||
if (!empty($filters['year'])) {
|
||||
$whereClauses[] = "YEAR(t.first_air_date) = :year";
|
||||
$params['year'] = $filters['year'];
|
||||
}
|
||||
|
||||
// Source filter
|
||||
if (!empty($filters['sources'])) {
|
||||
$sources = is_array($filters['sources']) ? $filters['sources'] : [$filters['sources']];
|
||||
$placeholders = [];
|
||||
foreach ($sources as $index => $source) {
|
||||
$placeholders[] = ":source_{$index}";
|
||||
$params["source_{$index}"] = $source;
|
||||
}
|
||||
$whereClauses[] = "s.display_name IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
// Combine WHERE clauses
|
||||
if (!empty($whereClauses)) {
|
||||
$sql .= " WHERE " . implode(' AND ', $whereClauses);
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
return (int)$result['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available years from TV shows' first_air_date
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user