actors the i dont know xD

This commit is contained in:
Lars Behrends
2025-11-07 13:20:48 +01:00
parent 5d86fcfda9
commit 3f2f80de11
10 changed files with 602 additions and 135 deletions

View File

@@ -130,7 +130,7 @@ class TvShow extends Model
/**
* Get all TV shows with pagination and optional search
*/
public static function getAllWithPagination(\PDO $pdo, int $page, int $perPage, string $search = '', array $genres = [], array $years = []): array
public static function getAllWithPagination(\PDO $pdo, int $page, int $perPage, string $search = '', array $genres = [], array $years = [], string $sort = 'title_asc'): array
{
$offset = ($page - 1) * $perPage;
@@ -166,7 +166,20 @@ class TvShow extends Model
$sql .= $whereClause . " YEAR(first_air_date) IN (" . implode(',', $placeholders) . ")";
}
$sql .= " ORDER BY t.title ASC LIMIT :limit OFFSET :offset";
// Add sorting
$sortMap = [
'title_asc' => 't.title ASC',
'title_desc' => 't.title DESC',
'year_desc' => 't.first_air_date DESC NULLS LAST',
'year_asc' => 't.first_air_date ASC NULLS LAST',
'rating_desc' => 't.rating DESC NULLS LAST',
'rating_asc' => 't.rating ASC NULLS LAST',
'recent' => 't.created_at DESC',
'oldest' => 't.created_at ASC',
];
$sortClause = $sortMap[$sort] ?? 't.title ASC';
$sql .= " ORDER BY {$sortClause} LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':limit', $perPage, \PDO::PARAM_INT);