From 38843f78bfbd27969df853377696dc8f8c71a921 Mon Sep 17 00:00:00 2001 From: horus Date: Mon, 24 Feb 2020 00:52:12 +0100 Subject: Adds models for score tracking. --- .gitignore | 2 + app/Anime.php | 49 ++++++++++++---- app/AnimeScore.php | 77 ++++++++++++++++++++++++++ app/AnimeWatching.php | 22 ++++++++ app/Http/Controllers/.IndexController.php.swp | Bin 12288 -> 0 bytes app/Http/Controllers/IndexController.php | 6 ++ app/Libraries/AnimeSchedule.php | 4 +- app/Libraries/AnimeSeason.php | 13 +++++ 8 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 app/AnimeScore.php create mode 100644 app/AnimeWatching.php delete mode 100644 app/Http/Controllers/.IndexController.php.swp diff --git a/.gitignore b/.gitignore index 0f7df0f..21c4d03 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ Homestead.json Homestead.yaml npm-debug.log yarn-error.log + +*.swp diff --git a/app/Anime.php b/app/Anime.php index b13f785..1e8fb95 100644 --- a/app/Anime.php +++ b/app/Anime.php @@ -1,30 +1,55 @@ id = $id; + + if ( $parse_info ) { + $jikan = new Malclient; + + $this->animeInfo = $jikan->getAnime( + (new \Jikan\Request\Anime\AnimeRequest( $this->id )) + ); + + $this->url = $this->animeInfo->GetUrl(); + $this->image_url = $this->animeInfo->getImageUrl(); + + $this->title_eng = $this->animeInfo->getTitleEnglish(); + $this->title_rom = $this->animeInfo->getTitle(); + $this->title_nat = $this->animeInfo->getTitleJapanese(); + $this->title_pref = $this->animeInfo->getTitle(); + + $this->type = $this->animeInfo->getType(); + } } + + protected function getInfo() { + return $this->animeInfo; + } + } diff --git a/app/AnimeScore.php b/app/AnimeScore.php new file mode 100644 index 0000000..9f150d0 --- /dev/null +++ b/app/AnimeScore.php @@ -0,0 +1,77 @@ +id = $id; + + parent::__construct($this->id); + + $jikan = new Malclient; + + $animeInfo = $this->getInfo(); + $this->score = $animeInfo->getScore(); + $this->scored_by = $animeInfo->getScoredBy(); + $this->rank = $animeInfo->getRank(); + $this->popularity = $animeInfo->getPopularity(); + $this->members = $animeInfo->getMembers(); + $this->favorites = $animeInfo->getFavorites(); + + $animeStats = $jikan->getAnimeStats( + (new \Jikan\Request\Anime\AnimeStatsRequest( $this->id )) + ); + + $this->watching = $animeStats->getWatching(); + $this->completed = $animeStats->getCompleted(); + $this->onhold = $animeStats->getOnHold(); + $this->dropped = $animeStats->getDropped(); + $this->plan_to_watch = $animeStats->getPlanToWatch(); + + $scores = $animeStats->getScores(); + + $this->score_1 = $scores[1]->getVotes(); + $this->score_2 = $scores[2]->getVotes(); + $this->score_3 = $scores[3]->getVotes(); + $this->score_4 = $scores[4]->getVotes(); + $this->score_5 = $scores[5]->getVotes(); + $this->score_6 = $scores[6]->getVotes(); + $this->score_7 = $scores[7]->getVotes(); + $this->score_8 = $scores[8]->getVotes(); + $this->score_9 = $scores[9]->getVotes(); + $this->score_10 = $scores[10]->getVotes(); + } + +} diff --git a/app/AnimeWatching.php b/app/AnimeWatching.php new file mode 100644 index 0000000..0ffa112 --- /dev/null +++ b/app/AnimeWatching.php @@ -0,0 +1,22 @@ +"; + var_dump($season); } } diff --git a/app/Libraries/AnimeSchedule.php b/app/Libraries/AnimeSchedule.php index c81d0f7..4c16f11 100644 --- a/app/Libraries/AnimeSchedule.php +++ b/app/Libraries/AnimeSchedule.php @@ -2,7 +2,7 @@ namespace App\Libraries; use App\Libraries\AnimeSchedule; -use App\Anime; +use App\AnimeWatching; use Carbon\Carbon; use Jikan\MyAnimeList\MalClient; @@ -48,7 +48,7 @@ class AnimeSchedule { (new \Jikan\Request\Anime\AnimeRequest( $entry->getMalID() )) ); - $anime = new Anime( $entry->getMalID() ); + $anime = new AnimeWatching( $entry->getMalID(), false ); $anime->title_eng = $data->title->english; $anime->title_rom = $data->title->romaji; diff --git a/app/Libraries/AnimeSeason.php b/app/Libraries/AnimeSeason.php index cc01ff7..a234d5c 100644 --- a/app/Libraries/AnimeSeason.php +++ b/app/Libraries/AnimeSeason.php @@ -3,6 +3,7 @@ namespace App\Libraries; use App\Libraries\AnimeSeason; use App\Anime; +use App\AnimeScore; use Carbon\Carbon; @@ -27,6 +28,18 @@ class AnimeSeason { $this->year = $season->seasonYear; $this->name= $season->seasonName; + + $count = 0; + foreach($season->anime as $entry) { + $count++; + $anime = new AnimeScore( $entry->getMalID() ); + $this->anime[] = $anime; + $anime->save(); + + if ( $count == 5) { + return; + } + } } } -- cgit v1.2.3