mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
basic filter D:
This commit is contained in:
@@ -262,16 +262,34 @@ class Game extends Model
|
||||
/**
|
||||
* Get total count of games for pagination
|
||||
*/
|
||||
public static function getTotalCount(\PDO $pdo, string $search = ''): int
|
||||
public static function getTotalCount(\PDO $pdo, string $search = '', array $genres = [], array $platforms = []): int
|
||||
{
|
||||
$sql = "SELECT COUNT(*) as count FROM games";
|
||||
$sql = "SELECT COUNT(*) as count FROM games WHERE game_key IS NOT NULL";
|
||||
$params = [];
|
||||
|
||||
if (!empty($search)) {
|
||||
$sql .= " WHERE title LIKE :search";
|
||||
$sql .= " AND title LIKE :search";
|
||||
$params['search'] = "%{$search}%";
|
||||
}
|
||||
|
||||
if (!empty($genres)) {
|
||||
$placeholders = [];
|
||||
foreach ($genres as $index => $genre) {
|
||||
$placeholders[] = ":genre_{$index}";
|
||||
$params["genre_{$index}"] = $genre;
|
||||
}
|
||||
$sql .= " AND genre IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
if (!empty($platforms)) {
|
||||
$placeholders = [];
|
||||
foreach ($platforms as $index => $platform) {
|
||||
$placeholders[] = ":platform_{$index}";
|
||||
$params["platform_{$index}"] = $platform;
|
||||
}
|
||||
$sql .= " AND platform IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
return (int) $stmt->fetch()['count'];
|
||||
@@ -280,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
|
||||
public static function getGroupedGamesWithPagination(\PDO $pdo, int $page, int $perPage, string $search = '', array $genres = [], array $platforms = []): array
|
||||
{
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
@@ -307,6 +325,24 @@ class Game extends Model
|
||||
$params['search'] = "%{$search}%";
|
||||
}
|
||||
|
||||
if (!empty($genres)) {
|
||||
$placeholders = [];
|
||||
foreach ($genres as $index => $genre) {
|
||||
$placeholders[] = ":genre_{$index}";
|
||||
$params["genre_{$index}"] = $genre;
|
||||
}
|
||||
$sql .= " AND genre IN (" . implode(',', $placeholders) . ")";
|
||||
}
|
||||
|
||||
if (!empty($platforms)) {
|
||||
$placeholders = [];
|
||||
foreach ($platforms as $index => $platform) {
|
||||
$placeholders[] = ":platform_{$index}";
|
||||
$params["platform_{$index}"] = $platform;
|
||||
}
|
||||
$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";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
@@ -379,51 +415,31 @@ class Game extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific series
|
||||
* Get available genres for filtering
|
||||
*/
|
||||
public function getSeries(): array
|
||||
public static function getAvailableGenres(\PDO $pdo): array
|
||||
{
|
||||
return $this->series_json ?? [];
|
||||
$stmt = $pdo->query("
|
||||
SELECT DISTINCT genre
|
||||
FROM games
|
||||
WHERE genre IS NOT NULL AND genre != ''
|
||||
ORDER BY genre
|
||||
");
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Playnite-specific age ratings
|
||||
* Get available platforms for filtering
|
||||
*/
|
||||
public function getAgeRatings(): array
|
||||
public static function getAvailablePlatforms(\PDO $pdo): 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}";
|
||||
$stmt = $pdo->query("
|
||||
SELECT DISTINCT platform
|
||||
FROM games
|
||||
WHERE platform IS NOT NULL AND platform != ''
|
||||
ORDER BY platform
|
||||
");
|
||||
return $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,4 +451,3 @@ class Game extends Model
|
||||
!empty($this->links_json) || !empty($this->background_image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user