From 24583ef2b3e7185f3a3e12cd1566bdada6d2f743 Mon Sep 17 00:00:00 2001 From: horus Date: Thu, 1 Oct 2020 01:15:59 +0200 Subject: add form to change season --- app/Http/Controllers/AnimeController.php | 31 ++++++++++++++++++--- app/Libraries/Background.php | 4 ++- app/helpers.php | 46 ++++++++++++++++++++++++++++++++ resources/sass/app.scss | 6 +++++ resources/views/list_anime.blade.php | 45 ++++++++++++++++++++++++++----- routes/web.php | 2 ++ 6 files changed, 123 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index 73c8842..e99f2f1 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -113,8 +113,12 @@ class AnimeController extends Controller { #$anime = $anime->setTable('anime'); $anime = $anime->where('airing_status', env('ANIME_IS_AIRING')); + $anime = $anime->orWhere( function( $q ) { + $q->where('season_year', date("Y")); + $q->where('season_name', getSeason()); + }); $anime = $anime->orderBy('season_year', 'desc'); - $anime = $anime->orderByRaw('FIELD(season_name, ' . $this->_getFieldSeasonName() . ')'); + $anime = $anime->orderByRaw('FIELD(season_name, ' . getFieldSeasonName() . ')'); $anime = $anime->orderBy('score_today', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('watching', 'desc'); @@ -179,7 +183,7 @@ class AnimeController extends Controller { } $count = $anime->count(); $anime = $anime->orderBy('season_year', 'desc'); - $anime = $anime->orderByRaw('FIELD(season_name, "Summer", "Fall", "Winter", "Spring")'); + $anime = $anime->orderByRaw('FIELD(season_name, ' . getFieldSeasonName() . ')'); $anime = $anime->orderBy('score_today', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('watching', 'desc'); @@ -203,8 +207,29 @@ class AnimeController extends Controller { $anime = $anime->orderBy('score_today', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('watching', 'desc'); - $sanime = $anime->paginate(12); + $sanime = $anime->get(); + #$sanime = $anime->paginate(12); return view('list_anime', ["all_anime" => $sanime, "title" => $season_name . " Season " . $season_year]); } + + public function changeSeason(Request $request) { + $input= explode("-", $request->input("season")); + $season_name = $input[0]; + $season_year = $input[1]; + + switch( strtolower($season_name) ) { + case("winter"): $season_name = "Winter"; break; + case("spring"): $season_name = "Spring"; break; + case("summer"): $season_name = "Summer"; break; + case("fall"): $season_name = "Fall"; break; + default: $saeson_name = getSeason(); + } + + if ( ! preg_match("/\d{4}/", $season_year) ) { + $season_year = date("Y"); + } + + return redirect('/anime/season/' . $season_year . '/' . $season_name); + } } diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index afd92b3..e89e00c 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -171,7 +171,9 @@ class Background { sleep(5); } - echo "Got stats for " . $counter . " anime.\n"; + if ( 0 < $counter ) { + echo "Got stats for " . $counter . " anime.\n"; + } } public function checkIfIsAiring() { diff --git a/app/helpers.php b/app/helpers.php index c5a227c..7214626 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,4 +1,5 @@ -
- @php echo getSeason() @endphp @php echo date("Y") @endphp -
++ {{ getSeason() }} {{ date("Y") }} +
+ @endif + + @if ( "airing_anime" == \Request::route()->getName() || "season" == \Request::route()->getName() ) +