summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2020-02-24 00:52:12 +0100
committerhorus2020-02-24 00:52:12 +0100
commit38843f78bfbd27969df853377696dc8f8c71a921 (patch)
treed40f35eda1c39e727c73a7037e20d463ef03aaf1
parent2cd1589d6ae7095770e8c5dda10b138861d70501 (diff)
downloadsenpai-38843f78bfbd27969df853377696dc8f8c71a921.tar.gz
Adds models for score tracking.
-rw-r--r--.gitignore2
-rw-r--r--app/Anime.php49
-rw-r--r--app/AnimeScore.php77
-rw-r--r--app/AnimeWatching.php22
-rw-r--r--app/Http/Controllers/.IndexController.php.swpbin12288 -> 0 bytes
-rw-r--r--app/Http/Controllers/IndexController.php6
-rw-r--r--app/Libraries/AnimeSchedule.php4
-rw-r--r--app/Libraries/AnimeSeason.php13
8 files changed, 159 insertions, 14 deletions
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 @@
<?php
namespace App;
+use Illuminate\Database\Eloquent\Model;
-class Anime {
+use Jikan\MyAnimeList\MalClient;
+
+class Anime extends Model {
public $id;
+ public $url;
+ public $image_url;
+
public $title_eng;
public $title_rom;
public $title_nat;
public $title_pref;
- public $airing_at;
- public $time_until_airing;
- public $episode;
- public $duration;
+ public $type;
- public $episodes_complete;
- public $episodes_watched;
- public $score_user;
- public $score;
+ private $animeInfo;
- public $rank;
- public $popularity;
+ /**
+ * Eloquent ORM
+ */
+ protected $table = 'anime';
- public function __construct( $id ) {
+ public function __construct( $id, $parse_info = true ) {
$this->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 @@
+<?php
+
+namespace App;
+
+use Jikan\MyAnimeList\MalClient;
+
+class AnimeScore extends Anime {
+
+ public $score;
+ public $scored_by;
+ public $rank;
+ public $popularity;
+ public $members;
+ public $favorites;
+
+ public $watching;
+ public $completed;
+ public $onhold;
+ public $dropped;
+ public $plan_to_watch;
+
+ public $score_1;
+ public $score_2;
+ public $score_3;
+ public $score_4;
+ public $score_5;
+ public $score_6;
+ public $score_7;
+ public $score_8;
+ public $score_9;
+ public $score_10;
+
+ /**
+ * Eloquent ORM
+ */
+ protected $table = 'stats';
+
+ public function __construct( $id ) {
+ $this->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 @@
+<?php
+
+namespace App;
+
+class AnimeWatching extends Anime {
+
+ public $title_pref;
+
+ public $airing_at;
+ public $time_until_airing;
+ public $episode;
+ public $duration;
+
+ public $episodes_complete;
+ public $episodes_watched;
+ public $score_user;
+
+ public $score;
+ public $rank;
+ public $popularity;
+
+}
diff --git a/app/Http/Controllers/.IndexController.php.swp b/app/Http/Controllers/.IndexController.php.swp
deleted file mode 100644
index efd5752..0000000
--- a/app/Http/Controllers/.IndexController.php.swp
+++ /dev/null
Binary files differ
diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php
index c77de48..e6a263b 100644
--- a/app/Http/Controllers/IndexController.php
+++ b/app/Http/Controllers/IndexController.php
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Libraries\AnimeSchedule;
use App\Libraries\AnimeSeason;
+use App\AnimeScore;
class IndexController extends Controller {
/**
@@ -36,5 +37,10 @@ class IndexController extends Controller {
public function test($param = null) {
$season = new AnimeSeason();
+ #$stats = new AnimeScore( 21 );
+
+ #var_dump($stats);
+ echo "<pre>";
+ 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;
+ }
+ }
}
}