From 22f1f8ca1c9e9ae924560631caf06cd04e10957d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sat, 10 Sep 2022 18:25:21 +0200 Subject: [PATCH] . --- app/Http/Controllers/FrontController.php | 23 ++++++++++++++++------- public/.htaccess | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 66e00a1..ba72d9d 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Collection; +use App\Models\CollectionList; use App\Models\Song; use Cubist\Backpack\Http\Controllers\CubistPWAController; @@ -21,8 +22,10 @@ class FrontController extends Controller if (null === $collection) { return self::defaultCollection(); } - $songs = $this->_getSongsOfCollection($collection->id); - return view('collection', ['songs' => $songs, 'collection' => $collection, 'collection_songs' => $songs]); + $lists = CollectionList::where('collection', $collection->id)->get(); + $songs = $this->_getSongsOfCollection($collection->id, $lists); + + return view('collection', ['songs' => $songs, 'collection' => $collection, 'collection_songs' => $songs, 'collection_lists' => $lists]); } public function song($collection, $song) @@ -35,13 +38,19 @@ class FrontController extends Controller if (null === $song) { abort(404); } - $collectionSongs = Song::whereRaw('json_contains(collections, \'["' . $collection->id . '"]\')')->get(); - return view('song', ['song' => $song, 'collection' => $collection, 'collection_songs' => $this->_getSongsOfCollection($collection->id)]); + $lists = CollectionList::where('collection', $collection->id)->get(); + return view('song', ['song' => $song, 'collection' => $collection, 'collection_songs' => $this->_getSongsOfCollection($collection->id, $lists), 'collection_lists' => $lists]); } - protected function _getSongsOfCollection($id) + protected function _getSongsOfCollection($id, $lists) { - return Song::whereRaw('json_contains(collections, \'["' . $id . '"]\')')->orderBy('title')->get(); + /** @var Song $q */ + $q = Song::whereRaw('json_contains(collections, \'["' . $id . '"]\')'); + foreach ($lists as $list) { + $q->orWhereRaw('json_contains(collections, \'["' . $id . '_' . $list->id . '"]\')'); + } + return $q->orderBy('title')->get(); + } public function manifest($collection) @@ -64,7 +73,7 @@ class FrontController extends Controller $icons[count($icons) - 1]['purpose'] = 'maskable'; $res = ['name' => $collection->name, - 'short_name' => $collection->shortname?:$collection->name, + 'short_name' => $collection->shortname ?: $collection->name, 'description' => '', 'display' => 'standalone', 'orientation' => 'any', diff --git a/public/.htaccess b/public/.htaccess index 3aec5e2..8046faa 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -9,6 +9,8 @@ RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + RewriteRule ^rodadocavaco-2021(.*)$ /rodadocavaco/$1 [L,R=308] + # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ -- 2.39.5