namespace App\Http\Controllers;
use App\Models\Collection;
+use App\Models\CollectionList;
use App\Models\Song;
use Cubist\Backpack\Http\Controllers\CubistPWAController;
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)
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)
$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',