From 6c965f51c3905e477b99932369221052c7ee9ace Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sun, 24 Sep 2023 12:04:23 +0200 Subject: [PATCH] . --- app/Http/Controllers/FrontController.php | 70 +++++++++++++++--------- app/Models/CollectionList.php | 1 + 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index cf46f83..9702983 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -17,7 +17,8 @@ use Notion\Pages\Properties\RichTextProperty; use Notion\Pages\Properties\Title; -class FrontController extends Controller { +class FrontController extends Controller +{ public static $notionFileFields = [ 'demos' => ['notion' => 'Démos Voix', 'cat' => '🎤 Démos'], 'instru' => ['notion' => 'Instru', 'cat' => '🎸 Instru'], @@ -26,11 +27,13 @@ class FrontController extends Controller { 'archives' => ['notion' => 'Archives et autres fichiers', 'cat' => '🗃️ Archives'] ]; - public static function defaultCollection() { + public static function defaultCollection() + { return redirect('/' . Collection::withoutGlobalScope('ownerclause')->find(1)->slug); } - public function collection($name) { + public function collection($name) + { $collection = Collection::withoutGlobalScope('ownerclause')->where('slug', $name)->first(); if (null === $collection) { return self::defaultCollection(); @@ -43,7 +46,7 @@ class FrontController extends Controller { return $this->notionCollection($collection); } - $lists = CollectionList::withoutGlobalScope('ownerclause')->where('collection', $collection->id)->orderBy('id','desc')->get(); + $lists = CollectionList::withoutGlobalScope('ownerclause')->where('collection', $collection->id)->orderBy('order_num', 'DESC')->orderBy('id', 'DESC')->get(); $songs = $this->_getSongsOfCollection($collection->id, $lists); return view('collection', ['menu' => true, 'songs' => $songs, 'collection' => $collection, 'collection_songs' => $songs, 'collection_lists' => $lists]); @@ -52,13 +55,15 @@ class FrontController extends Controller { /** * @throws \Exception */ - public function notionCollection($collection) { + public function notionCollection($collection) + { $songs = self::getSongsOfNotionCollection($collection); return view('notion_collection', ['menu' => true, 'notion' => true, 'songs' => $songs, 'collection' => $collection, 'collection_songs' => $songs]); } - public function checkPassword(Collection $collection) { + public function checkPassword(Collection $collection) + { if (!$collection->password) { return false; } @@ -76,7 +81,8 @@ class FrontController extends Controller { return view('login', ['menu' => false, 'collection' => $collection, 'error' => $error]); } - public function song($collection, $song) { + public function song($collection, $song) + { /** @var Collection $collection */ $collection = Collection::withoutGlobalScope('ownerclause')->where('slug', $collection)->first(); if (null === $collection) { @@ -95,7 +101,7 @@ class FrontController extends Controller { } - $lists = CollectionList::withoutGlobalScope('ownerclause')->where('collection', $collection->id)->orderBy('id','desc')->get(); + $lists = CollectionList::withoutGlobalScope('ownerclause')->where('collection', $collection->id)->orderBy('id', 'desc')->get(); $partition = false; $lyrics_html = ''; @@ -132,7 +138,8 @@ class FrontController extends Controller { return view('song', ['menu' => true, 'lyrics_html' => $lyrics_html, 'song' => $song, 'collection' => $collection, 'partition' => $partition, 'collection_songs' => $this->_getSongsOfCollection($collection->id, $lists), 'collection_lists' => $lists]); } - protected function notionSong($collection, $song) { + protected function notionSong($collection, $song) + { $partition = false; $u = $song . '.html'; @@ -146,7 +153,8 @@ class FrontController extends Controller { return view('notion_song', ['menu' => true, 'notion' => true, 'lyrics_html' => $lyrics_html, 'song' => $song, 'collection' => $collection, 'collection_songs' => $songs]); } - protected function _getSongsOfCollection($id, $lists) { + protected function _getSongsOfCollection($id, $lists) + { /** @var Song $q */ $q = Song::withoutGlobalScope('ownerclause')->whereRaw('json_contains(collections, \'["' . $id . '"]\')'); foreach ($lists as $list) { @@ -161,7 +169,8 @@ class FrontController extends Controller { * @return \App\Notion\Song[] * @throws \Exception */ - public static function getSongsOfNotionCollection($collection, $force = false) { + public static function getSongsOfNotionCollection($collection, $force = false) + { $cacheKey = 'songs_notion_' . $collection->notion_database . '_' . $collection->id; $ttl = 900; if ($force) { @@ -175,7 +184,8 @@ class FrontController extends Controller { } - protected static function _getSongsOfNotionCollection($collection) { + protected static function _getSongsOfNotionCollection($collection) + { $audios = ['mp3', 'm4a', 'wav']; $notion = Notion::create($collection->notion_key); @@ -253,7 +263,8 @@ class FrontController extends Controller { * @param $block RichTextProperty|BlockInterface * @return string */ - protected static function _blockToHtml($block) { + protected static function _blockToHtml($block) + { $start = '

'; $end = '

'; if ($block instanceof Paragraph) { @@ -277,7 +288,8 @@ class FrontController extends Controller { * @param $rt RichText * @return string */ - protected static function _richTextToHtml($rt) { + protected static function _richTextToHtml($rt) + { $start = ''; $end = ''; @@ -302,7 +314,8 @@ class FrontController extends Controller { return $start . nl2br($rt->plainText) . $end; } - public static function parseFileNameFromAmazonURL($url) { + public static function parseFileNameFromAmazonURL($url) + { $u = parse_url($url); $p = explode('/', $u['path']); $f = array_pop($p); @@ -313,7 +326,8 @@ class FrontController extends Controller { return str_replace('_', ' ', $f); } - public static function parseExtensionFromAmazonURL($url) { + public static function parseExtensionFromAmazonURL($url) + { $u = parse_url($url); $p = explode('/', $u['path']); $f = array_pop($p); @@ -321,7 +335,8 @@ class FrontController extends Controller { return array_pop($e); } - public function manifest($collection) { + public function manifest($collection) + { $collection = Collection::withoutGlobalScope('ownerclause')->where('slug', $collection)->first(); if (null === $collection) { abort(404); @@ -340,20 +355,21 @@ class FrontController extends Controller { $icons[count($icons) - 1]['purpose'] = 'maskable'; $res = ['name' => $collection->name, - 'short_name' => $collection->shortname ?: $collection->name, - 'description' => '', - 'display' => 'standalone', - 'orientation' => 'any', - 'background_color' => $collection->splashscreen_color, - 'theme_color' => $collection->theme_color, - 'start_url' => '/' . $collection->slug, - 'scope' => '/' . $collection->slug, - 'icons' => $icons]; + 'short_name' => $collection->shortname ?: $collection->name, + 'description' => '', + 'display' => 'standalone', + 'orientation' => 'any', + 'background_color' => $collection->splashscreen_color, + 'theme_color' => $collection->theme_color, + 'start_url' => '/' . $collection->slug, + 'scope' => '/' . $collection->slug, + 'icons' => $icons]; return response(json_encode($res))->header('Content-Type', 'application/manifest+json'); } - public function downloadAssets($songId) { + public function downloadAssets($songId) + { /** @var Song $song */ $song = Song::withoutGlobalScope('ownerclause')->find($songId); $fields = ['partition', 'lyrics_doc']; diff --git a/app/Models/CollectionList.php b/app/Models/CollectionList.php index fa2d433..b8b3065 100644 --- a/app/Models/CollectionList.php +++ b/app/Models/CollectionList.php @@ -33,5 +33,6 @@ class CollectionList extends CubistMagicAbstractModel parent::setFields(); $this->addField('name', Text::class, __('Nom'), ['column' => true]); $this->addField('collection', SelectFromModel::class, __('Collection'), ['column' => true, 'optionsmodel' => Collection::class]); + $this->addField('order_num', Integer::class, __('Ordre')); } } -- 2.39.5