mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
Stuff i guess ?
This commit is contained in:
@@ -177,9 +177,9 @@ class Game extends Model
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare("
|
||||
SELECT g.*, s.display_name as source_name
|
||||
SELECT g.*, g.platform as source_name
|
||||
FROM games g
|
||||
JOIN sources s ON g.source_id = s.id
|
||||
|
||||
WHERE g.game_key = :game_key
|
||||
ORDER BY g.platform, g.source_id
|
||||
");
|
||||
@@ -215,9 +215,9 @@ class Game extends Model
|
||||
|
||||
// Enhance each game with platform details
|
||||
foreach ($games as &$game) {
|
||||
$game['platforms'] = array_unique(explode(',', $game['platforms']));
|
||||
$game['source_ids'] = array_unique(explode(',', $game['source_ids']));
|
||||
$game['genres'] = array_unique(array_filter(explode(',', $game['genres'])));
|
||||
$game['platforms'] = !empty($game['platforms']) ? array_unique(explode(',', $game['platforms'])) : [];
|
||||
$game['source_ids'] = !empty($game['source_ids']) ? array_unique(explode(',', $game['source_ids'])) : [];
|
||||
$game['genres'] = !empty($game['genres']) ? array_unique(array_filter(explode(',', $game['genres']))) : [];
|
||||
}
|
||||
|
||||
return $games;
|
||||
@@ -298,7 +298,7 @@ class Game extends Model
|
||||
/**
|
||||
* Get grouped games with pagination and search support
|
||||
*/
|
||||
public static function getGroupedGamesWithPagination(\PDO $pdo, int $page, int $perPage, string $search = '', array $genres = [], array $platforms = []): array
|
||||
public static function getGroupedGamesWithPagination(\PDO $pdo, int $page, int $perPage, string $search = '', array $genres = [], array $platforms = [], string $sort = 'title_asc'): array
|
||||
{
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
@@ -313,7 +313,9 @@ class Game extends Model
|
||||
MAX(last_played_at) as last_played_at,
|
||||
SUM(playtime_minutes) as total_playtime,
|
||||
MAX(completion_percentage) as max_completion,
|
||||
GROUP_CONCAT(DISTINCT genre ORDER BY genre) as genres
|
||||
GROUP_CONCAT(DISTINCT genre ORDER BY genre) as genres,
|
||||
MAX(release_date) as release_date,
|
||||
MAX(added_at) as added_at
|
||||
FROM games
|
||||
WHERE game_key IS NOT NULL
|
||||
";
|
||||
@@ -343,7 +345,24 @@ class Game extends Model
|
||||
$sql .= " AND platform IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY game_key, title ORDER BY last_played_at DESC, total_playtime DESC LIMIT :limit OFFSET :offset";
|
||||
// Add sorting
|
||||
$sortOptions = [
|
||||
'title_asc' => 'title ASC',
|
||||
'title_desc' => 'title DESC',
|
||||
'year_asc' => 'release_date ASC NULLS LAST',
|
||||
'year_desc' => 'release_date DESC NULLS LAST',
|
||||
'playtime_asc' => 'total_playtime ASC',
|
||||
'playtime_desc' => 'total_playtime DESC',
|
||||
'completion_asc' => 'max_completion ASC NULLS LAST',
|
||||
'completion_desc' => 'max_completion DESC NULLS LAST',
|
||||
'added_asc' => 'added_at ASC NULLS LAST',
|
||||
'added_desc' => 'added_at DESC NULLS LAST',
|
||||
'last_played_asc' => 'last_played_at ASC NULLS LAST',
|
||||
'last_played_desc' => 'last_played_at DESC NULLS LAST'
|
||||
];
|
||||
|
||||
$sortClause = $sortOptions[$sort] ?? 'title ASC';
|
||||
$sql .= " GROUP BY game_key, title ORDER BY $sortClause LIMIT :limit OFFSET :offset";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindValue(':limit', $perPage, \PDO::PARAM_INT);
|
||||
@@ -358,20 +377,52 @@ class Game extends Model
|
||||
|
||||
// Enhance each game with platform details
|
||||
foreach ($games as &$game) {
|
||||
$game['platforms'] = array_unique(explode(',', $game['platforms']));
|
||||
$game['source_ids'] = array_unique(explode(',', $game['source_ids']));
|
||||
$game['genres'] = array_unique(array_filter(explode(',', $game['genres'])));
|
||||
$game['platforms'] = !empty($game['platforms']) ? array_unique(explode(',', $game['platforms'])) : [];
|
||||
$game['source_ids'] = !empty($game['source_ids']) ? array_unique(explode(',', $game['source_ids'])) : [];
|
||||
$game['genres'] = !empty($game['genres']) ? array_unique(array_filter(explode(',', $game['genres']))) : [];
|
||||
}
|
||||
|
||||
return $games;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific genres
|
||||
* Get all unique genres from the games table
|
||||
* Combines both Playnite JSON genres and regular genre field
|
||||
*/
|
||||
public function getGenres(): array
|
||||
{
|
||||
return $this->genres_json ?? [];
|
||||
// First get genres from the regular genre field
|
||||
$stmt = $this->pdo->query("SELECT DISTINCT genre FROM {$this->table} WHERE genre IS NOT NULL AND genre != ''");
|
||||
$genres = [];
|
||||
$results = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
// Flatten and deduplicate genres
|
||||
foreach ($results as $genreList) {
|
||||
$genreArray = array_map('trim', explode(',', $genreList));
|
||||
$genres = array_merge($genres, $genreArray);
|
||||
}
|
||||
|
||||
// Also get genres from Playnite JSON data
|
||||
$stmt = $this->pdo->query("SELECT genres_json FROM {$this->table} WHERE genres_json IS NOT NULL AND genres_json != '[]'");
|
||||
$jsonGenres = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
foreach ($jsonGenres as $json) {
|
||||
$decoded = json_decode($json, true);
|
||||
if (is_array($decoded)) {
|
||||
foreach ($decoded as $genre) {
|
||||
if (is_array($genre) && isset($genre['Name'])) {
|
||||
$genres[] = $genre['Name'];
|
||||
} elseif (is_string($genre)) {
|
||||
$genres[] = $genre;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$genres = array_unique($genres);
|
||||
sort($genres);
|
||||
|
||||
return array_values(array_filter($genres));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,6 +448,16 @@ class Game extends Model
|
||||
{
|
||||
return $this->tags_json ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unique platforms from the games table
|
||||
*/
|
||||
public function getPlatforms(): array
|
||||
{
|
||||
$stmt = $this->pdo->query("SELECT DISTINCT platform FROM {$this->table} WHERE platform IS NOT NULL AND platform != '' ORDER BY platform");
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Playnite-specific features
|
||||
|
||||
Reference in New Issue
Block a user