mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
actors the i dont know xD
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user