Skip to content

Commit

Permalink
Add position to additional sorting place
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Dec 8, 2023
1 parent 7494a0e commit 0a2df1c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Domain/Movie/MovieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function fetchWatchDatesForMovieIds(int $userId, array $movieIds) : array
"SELECT watched_at, plays, comment, movie_id
FROM movie_user_watch_dates
WHERE user_id = ? and movie_id in ($placeholders)
ORDER BY watched_at DESC",
ORDER BY watched_at DESC, position DESC",
[
$userId,
...$movieIds
Expand Down Expand Up @@ -784,6 +784,11 @@ public function fetchUniqueWatchedMoviesPaginated(
default => 'LOWER(title)'
};

$sortByWatchDatePosition = '';
if ($sortBySanitized === 'watched_at') {
$sortByWatchDatePosition = "mh.position $sortOrder, ";
}

$whereQuery = 'WHERE m.title LIKE ? ';

if (empty($releaseYear) === false) {
Expand Down Expand Up @@ -817,7 +822,7 @@ public function fetchUniqueWatchedMoviesPaginated(
LEFT JOIN genre g on mg.genre_id = g.id
$whereQuery
GROUP BY m.id, title, release_date, watched_at, rating
ORDER BY $sortBySanitized $sortOrder, LOWER(title) asc
ORDER BY $sortBySanitized $sortOrder,$sortByWatchDatePosition LOWER(title) asc
) a
WHERE rn = 1
LIMIT $offset, $limit
Expand Down

0 comments on commit 0a2df1c

Please sign in to comment.