From 74e73666e5f79fe5862bc9cd2c8d244004c381b4 Mon Sep 17 00:00:00 2001
From: horus
Date: Tue, 24 Mar 2020 17:18:39 +0100
Subject: Integrate chart.js to display anime stats.
---
app/AnimeStats.php | 1 +
app/Console/Kernel.php | 3 ++-
app/Http/Controllers/AnimeController.php | 21 +++++++++++++++++++--
app/helpers.php | 12 ++++++++++++
4 files changed, 34 insertions(+), 3 deletions(-)
create mode 100644 app/helpers.php
(limited to 'app')
diff --git a/app/AnimeStats.php b/app/AnimeStats.php
index 765d24f..a4f3396 100644
--- a/app/AnimeStats.php
+++ b/app/AnimeStats.php
@@ -112,6 +112,7 @@ class AnimeStats extends Model {
echo "Error requesting AnimeStats for " . $this->mal_id ."\n";
echo "Message: " . $e->getMessage();
echo "\n\n";
+ return;
}
$this->watching = $animeStats->getWatching();
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 2bb1fea..8c12616 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -56,11 +56,12 @@ class Kernel extends ConsoleKernel
$helper->setIsWatchingForAll();
echo "\nsetCalendarForAll(): \n";
$helper->setCalendarForAll();
- })->dailyAt('19:30');
+ })->twiceDaily(7, 19);
#})->everyMinute();
$schedule->call( function(){
$background = new Background();
+ echo"saveEnhancementForAll()\n";
$background->saveEnhancementForAll();
})->weeklyOn(1, '15:30');
#})->everyMinute();
diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php
index d43b1f8..9bbd3e8 100644
--- a/app/Http/Controllers/AnimeController.php
+++ b/app/Http/Controllers/AnimeController.php
@@ -20,17 +20,34 @@ class AnimeController extends Controller {
public function showAnime($mal_id) {
$anime = Anime::where('mal_id', $mal_id)->get()->first();
+ if ( is_null($anime) ) {
+ abort(404);
+ }
$anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get();
foreach( $anime["stats"] as $stats ) {
$score[] = $stats->score;
- $scored_at[] = $stats->created_at->toDateString();
+ $created_at[] = $stats->created_at->toDateString();
+ $rank[] = $stats->rank;
+ $popularity[] = $stats->popularity;
+ $members[] = $stats->members;
+ $favorites[] = $stats->favorites;
}
$anime["score"] = $score;
- $anime["score_label"] = $scored_at;
+ $anime["rank"] = $rank;
+ $anime["popularity"] = $popularity;
+ $anime["members"] = $members;
+ $anime["favorites"] = $favorites;
+ $anime["chart_label"] = $created_at;
$anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0];
return view('anime', [ "anime" => $anime ]);
}
+
+ public function showAllAnime() {
+ $anime = Anime::get();
+
+ return view('index_anime', ["all_anime" => $anime]);
+ }
}
diff --git a/app/helpers.php b/app/helpers.php
new file mode 100644
index 0000000..bac4f0e
--- /dev/null
+++ b/app/helpers.php
@@ -0,0 +1,12 @@
+", $string);
+ $string = str_replace("</i>", "", $string);
+ $string = str_replace("<b>", "", $string);
+ $string = str_replace("</b>", "", $string);
+ $string = str_replace("<br>", "
", $string);
+ $string = str_replace("%%br%%", "
", $string);
+
+ return $string;
+}
--
cgit v1.2.3