summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/CinemaController.php
diff options
context:
space:
mode:
authorDeveloper2026-06-27 04:03:30 +0200
committerDeveloper2026-06-27 04:03:30 +0200
commit972cd677ab19a6603214f8d61c5f4014a7e5ac4e (patch)
tree067341f9cb34d346c5af08873ae96f4532c2be58 /app/Http/Controllers/CinemaController.php
parenta2199efc94bf7ff26e7dd1f3db9e9ae0e4e4cc3a (diff)
downloadcurious-972cd677ab19a6603214f8d61c5f4014a7e5ac4e.tar.gz
feat: add sort buttons to cinema listing
Order options: Hacker News Mentions (default), Rating, Number of Votes, Accolades, Release Date. Active sort is highlighted in primary color.
Diffstat (limited to 'app/Http/Controllers/CinemaController.php')
-rw-r--r--app/Http/Controllers/CinemaController.php14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/Http/Controllers/CinemaController.php b/app/Http/Controllers/CinemaController.php
index 160ca33..d79d037 100644
--- a/app/Http/Controllers/CinemaController.php
+++ b/app/Http/Controllers/CinemaController.php
@@ -7,8 +7,14 @@ use Illuminate\Http\Request;
class CinemaController extends Controller
{
- public function cinema()
+ public function cinema(Request $request)
{
+ $order = $request->input('order', 'ref_count');
+ $validOrders = ['ref_count', 'score', 'num_votes', 'num_accolades', 'start_year'];
+ if (! in_array($order, $validOrders)) {
+ $order = 'ref_count';
+ }
+
$refCounts = DB::connection('cinema')
->table('links')
->select('links.param', DB::raw('COUNT(*) as ref_count'))
@@ -31,6 +37,8 @@ class CinemaController extends Controller
'imdb.title_type',
'imdb.runtime_minutes',
'imdb.has_people',
+ 'imdb.average_rating as score',
+ 'imdb.num_accolades',
DB::raw('COALESCE(ref.ref_count, 0) as ref_count')
)
->leftJoinSub($refCounts, 'ref', function ($join) {
@@ -39,7 +47,7 @@ class CinemaController extends Controller
->whereNotNull('imdb.primary_title')
->whereNotNull('imdb.wiki_article')
->where('imdb.title_type', 'movie')
- ->orderBy('ref_count', 'desc')
+ ->orderBy($order, 'desc')
->simplePaginate(12);
$total = DB::connection('cinema')
@@ -49,7 +57,7 @@ class CinemaController extends Controller
->where('title_type', 'movie')
->count();
- return view('cinema', ['movies' => $movies, 'count' => $total]);
+ return view('cinema', ['movies' => $movies, 'count' => $total, 'order' => $order]);
}
public function show($id)