From cb55dd29e1721b5a1df0a5b9aca06171d7ae56c3 Mon Sep 17 00:00:00 2001 From: horus Date: Sat, 19 Sep 2020 20:28:21 +0200 Subject: remove hard coded season order --- app/Http/Controllers/AnimeController.php | 11 ++++++++++- app/helpers.php | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index f2cc73e..5769efd 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -107,7 +107,7 @@ class AnimeController extends Controller { #$anime = $anime->setTable('anime'); $anime = $anime->where('airing_status', env('ANIME_IS_AIRING')); $anime = $anime->orderBy('season_year', 'desc'); - $anime = $anime->orderByRaw('FIELD(season_name, "Summer", "Fall", "Winter", "Spring")'); + $anime = $anime->orderByRaw('FIELD(season_name, ' . $this->_getFieldSeasonName() . ')'); $anime = $anime->orderBy('score_today', 'desc'); $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('watching', 'desc'); @@ -117,6 +117,15 @@ class AnimeController extends Controller { return view('list_anime', ["all_anime" => $anime, "most_suprising_anime" => $most_surprising_anime, "title" => "Currently Airing"]); } + private function _getFieldSeasonName() { + $first = (int)date("m"); + $second = nextSeason($first); + $third = nextSeason($second); + $fourth = nextSeason($third); + + return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"'; + } + public function showSurprisingAnime() { $anime = new Anime; $most_surprising_anime = $anime->setTable('view_anime_index'); diff --git a/app/helpers.php b/app/helpers.php index 4c946f7..c96b972 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -70,7 +70,7 @@ function getAiringStatusCode($airing_status) { function getSeason( $month = null ){ if ( is_null($month) ) { - $month = date("m"); + $month = (int)date("m"); } switch( $month ) { case 1: @@ -88,6 +88,19 @@ function getSeason( $month = null ){ } } +function nextSeason( $month = null ){ + if ( is_null($month) ) { + $month = (int)date("m"); + } + + $next = $month + 3; + if ( $next > 12 ) { + $next = $next - 12; + } + + return $next; +} + function escapeLike($string){ $search = array('%', '_'); $replace = array('\%', '\_'); -- cgit v1.2.3