summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Http/Controllers/AnimeController.php31
-rw-r--r--app/Libraries/Background.php4
-rw-r--r--app/helpers.php46
3 files changed, 77 insertions, 4 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'
+ );
+}