mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
impoort stuff!
This commit is contained in:
@@ -25,9 +25,27 @@ class Game extends Model
|
||||
'is_favorite',
|
||||
'metadata',
|
||||
'platform_achievements',
|
||||
'platform_stats',
|
||||
'source_id',
|
||||
'last_played_at'
|
||||
'background_image',
|
||||
'cover_image',
|
||||
'icon',
|
||||
'genres_json',
|
||||
'developers_json',
|
||||
'publishers_json',
|
||||
'tags_json',
|
||||
'features_json',
|
||||
'links_json',
|
||||
'series_json',
|
||||
'age_ratings_json',
|
||||
'play_count',
|
||||
'install_size',
|
||||
'completion_status',
|
||||
'critic_score',
|
||||
'community_score',
|
||||
'user_score',
|
||||
'is_custom_game',
|
||||
'installation_status',
|
||||
'added_at',
|
||||
'modified_at'
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
@@ -39,7 +57,23 @@ class Game extends Model
|
||||
'release_date' => 'date',
|
||||
'last_played_at' => 'datetime',
|
||||
'platform_achievements' => 'array',
|
||||
'platform_stats' => 'array'
|
||||
'critic_score' => 'int',
|
||||
'community_score' => 'int',
|
||||
'user_score' => 'int',
|
||||
'play_count' => 'int',
|
||||
'install_size' => 'int',
|
||||
'installation_status' => 'int',
|
||||
'is_custom_game' => 'bool',
|
||||
'added_at' => 'datetime',
|
||||
'modified_at' => 'datetime',
|
||||
'genres_json' => 'array',
|
||||
'developers_json' => 'array',
|
||||
'publishers_json' => 'array',
|
||||
'tags_json' => 'array',
|
||||
'features_json' => 'array',
|
||||
'links_json' => 'array',
|
||||
'series_json' => 'array',
|
||||
'age_ratings_json' => 'array'
|
||||
];
|
||||
|
||||
public function source()
|
||||
@@ -295,4 +329,110 @@ class Game extends Model
|
||||
|
||||
return $games;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific genres
|
||||
*/
|
||||
public function getGenres(): array
|
||||
{
|
||||
return $this->genres_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific developers
|
||||
*/
|
||||
public function getDevelopers(): array
|
||||
{
|
||||
return $this->developers_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific publishers
|
||||
*/
|
||||
public function getPublishers(): array
|
||||
{
|
||||
return $this->publishers_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific tags
|
||||
*/
|
||||
public function getTags(): array
|
||||
{
|
||||
return $this->tags_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific features
|
||||
*/
|
||||
public function getFeatures(): array
|
||||
{
|
||||
return $this->features_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific links
|
||||
*/
|
||||
public function getLinks(): array
|
||||
{
|
||||
return $this->links_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific series
|
||||
*/
|
||||
public function getSeries(): array
|
||||
{
|
||||
return $this->series_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific age ratings
|
||||
*/
|
||||
public function getAgeRatings(): array
|
||||
{
|
||||
return $this->age_ratings_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted install size
|
||||
*/
|
||||
public function getFormattedInstallSize(): string
|
||||
{
|
||||
if (!$this->install_size) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$bytes = $this->install_size;
|
||||
$i = 0;
|
||||
|
||||
while ($bytes >= 1024 && $i < count($units) - 1) {
|
||||
$bytes /= 1024;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return round($bytes, 2) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Steam store URL if available
|
||||
*/
|
||||
public function getSteamUrl(): ?string
|
||||
{
|
||||
if (!$this->steam_app_id) {
|
||||
return null;
|
||||
}
|
||||
return "https://store.steampowered.com/app/{$this->steam_app_id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if game has rich Playnite data
|
||||
*/
|
||||
public function hasPlayniteData(): bool
|
||||
{
|
||||
return !empty($this->genres_json) || !empty($this->tags_json) ||
|
||||
!empty($this->links_json) || !empty($this->background_image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,19 +37,32 @@ class TvShow extends Model
|
||||
];
|
||||
|
||||
/**
|
||||
* Get all actors associated with this TV show
|
||||
* Remove an actor from this TV show
|
||||
*/
|
||||
public function actors()
|
||||
public function removeActor(int $actorId): bool
|
||||
{
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT a.*
|
||||
FROM actors a
|
||||
JOIN actor_tv_show ats ON a.id = ats.actor_id
|
||||
WHERE ats.tv_show_id = :tv_show_id
|
||||
ORDER BY a.name ASC
|
||||
DELETE FROM actor_tv_show
|
||||
WHERE tv_show_id = :tv_show_id AND actor_id = :actor_id
|
||||
");
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
return $stmt->execute([
|
||||
'tv_show_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
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,35 +164,51 @@ class TvShow extends Model
|
||||
}
|
||||
|
||||
public function getSeasonsWithEpisodes(): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT s.*,
|
||||
COUNT(e.id) as episode_count,
|
||||
SUM(CASE WHEN e.watched = 1 THEN 1 ELSE 0 END) as watched_episodes
|
||||
FROM seasons s
|
||||
LEFT JOIN episodes e ON s.id = e.season_id
|
||||
WHERE s.tv_show_id = :tv_show_id
|
||||
GROUP BY s.id
|
||||
ORDER BY s.season_number ASC
|
||||
");
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
$seasons = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// Get episodes for each season
|
||||
foreach ($seasons as &$season) {
|
||||
{
|
||||
// Get all episodes for this TV show, grouped by season
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT e.*,
|
||||
(SELECT COUNT(*) FROM user_episodes WHERE episode_id = e.id AND watched = 1) as watch_count
|
||||
FROM episodes e
|
||||
WHERE e.season_id = :season_id
|
||||
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(['season_id' => $season['id']]);
|
||||
$season['episodes'] = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
$stmt->execute(['tv_show_id' => $this->id]);
|
||||
$seasonStats = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
return $seasons;
|
||||
}
|
||||
$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
|
||||
");
|
||||
$stmt->execute([
|
||||
'tv_show_id' => $this->id,
|
||||
'season_number' => $seasonNumber
|
||||
]);
|
||||
$episodes = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get similar TV shows based on genres
|
||||
|
||||
Reference in New Issue
Block a user