diff options
| author | horus | 2020-10-01 01:15:59 +0200 |
|---|---|---|
| committer | horus | 2020-10-01 01:15:59 +0200 |
| commit | 24583ef2b3e7185f3a3e12cd1566bdada6d2f743 (patch) | |
| tree | b3ca7e1bc909e3b4c64d112c2394a7834a014bc7 | |
| parent | e6194704303c4e5ad44c1bb9d6c2e17fe5eb133b (diff) | |
| download | senpai-24583ef2b3e7185f3a3e12cd1566bdada6d2f743.tar.gz | |
add form to change season
| -rw-r--r-- | app/Http/Controllers/AnimeController.php | 31 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 4 | ||||
| -rw-r--r-- | app/helpers.php | 46 | ||||
| -rw-r--r-- | resources/sass/app.scss | 6 | ||||
| -rw-r--r-- | resources/views/list_anime.blade.php | 45 | ||||
| -rw-r--r-- | 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 +use Illuminate\Support\Facades\DB; use Carbon\Carbon; function replaceSpecialChars($string) { @@ -105,6 +106,37 @@ function nextSeason( $month = null ){ return $next; } +function lastSeason( $month = null ){ + if ( is_null($month) ) { + $month = (int)date("m"); + } + + $last = $month - 3; + if ( $last <= 0 ) { + $last = $last + 12; + } + + return $last; +} + +function getFieldSeasonName() { + $first = (int)date("m"); + $second = lastSeason($first); + $third = lastSeason($second); + $fourth = lastSeason($third); + + return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"'; +} + +function getFieldSeasonNameNext() { + $first = (int)date("m"); + $second = nextSeason($first); + $third = nextSeason($second); + $fourth = nextSeason($third); + + return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"'; +} + function escapeLike($string){ $search = array('%', '_'); $replace = array('\%', '\_'); @@ -145,3 +177,17 @@ function camo($url) { return $url; } + +function getChangeSeasonOptions() { + return DB::select(' + SELECT DISTINCT season_name,season_year + FROM anime + WHERE + season_name IS NOT NULL + AND + season_name != "" + AND + season_year IS NOT NULL + ORDER BY season_year DESC, FIELD(season_name, ' . getFieldSeasonName() . ') ASC' + ); +} diff --git a/resources/sass/app.scss b/resources/sass/app.scss index 521c226..8e30317 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -12,6 +12,12 @@ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04); } +.page-header { + @extend .jumbotron; + background-color: rgb(255,255,255,0.5); + padding: 2rem; +} + @media( max-width: 500px ) { body { background: url(/img/sakamoto-mobile.jpg) no-repeat left center fixed; diff --git a/resources/views/list_anime.blade.php b/resources/views/list_anime.blade.php index 32ad79b..df1971f 100644 --- a/resources/views/list_anime.blade.php +++ b/resources/views/list_anime.blade.php @@ -1,15 +1,46 @@ @extends('layouts.app') @section('content') + <div class="container" id="index"> -<div class="jumbotron"> - <h1>{{ $title }}</h1> - @if ( "airing_anime" == \Request::route()->getName() ) - <p class="lead text-muted"> - @php echo getSeason() @endphp @php echo date("Y") @endphp - </p> +<div class="page-header"> + <div class="row"> + @if ( "airing_anime" == \Request::route()->getName() || "season" == \Request::route()->getName() ) + <div class="col-6"> + @endif + + <h1>{{ $title }}</h1> + @if ( "airing_anime" == \Request::route()->getName() ) + <p class="lead text-muted"> + {{ getSeason() }} {{ date("Y") }} + </p> + @endif + + @if ( "airing_anime" == \Request::route()->getName() || "season" == \Request::route()->getName() ) + </div> + @endif + + @if ( "airing_anime" == \Request::route()->getName() || "season" == \Request::route()->getName() ) + <!-- Change Season --> + <div class="col-6"> + <form id="season_change" action="/changeSeason/" method="get"> + <div class="form-group"> + <label for="season_switcher"> + <h3>Change Season</h3> + </label> + <select name="season" id="season_switcher" class="custom-select" required> + @foreach( getChangeSeasonOptions() as $season ) + <option value="{{ $season->season_name }}-{{ $season->season_year }}">{{ $season->season_name }} {{ $season->season_year }}</option> + @endforeach + </select> + </div> + <button class="btn btn-primary" type="submit"> Go! </button> + </form> + </div> @endif + + </div> </div> <div class="row"> @foreach($all_anime as $anime) @@ -17,7 +48,7 @@ @once </div> - <div class="jumbotron"> + <div id="continuing" class="jumbotron" style="margin-top: 2rem;"> <h2>Continuing from earlier Seasons</h2> </div> diff --git a/routes/web.php b/routes/web.php index 9c05426..bd37c46 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,6 +25,8 @@ Route::get('/anime/{mal_id}/{slug?}', 'AnimeController@showAnime')->name('anime' Route::get('/api/anime/{mal_id}', 'ApiController@getAnime'); +Route::get('/changeSeason', 'AnimeController@changeSeason')->name('change_season'); + Route::get('/ical/{username}', 'IndexController@ical'); Route::get('/create/user/{param}', 'IndexController@createUser'); Route::get('/save', 'IndexController@saveWatchingAnime'); |
