diff options
| -rw-r--r-- | app/Anime.php | 8 | ||||
| -rw-r--r-- | app/AnimeStats.php | 15 | ||||
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 4 | ||||
| -rw-r--r-- | app/Libraries/AnimeSeason.php | 13 | ||||
| -rw-r--r-- | database/migrations/2020_02_23_235746_create_anime_table.php | 44 | ||||
| -rw-r--r-- | database/migrations/2020_02_23_235949_create_stats_table.php | 61 | ||||
| -rw-r--r-- | database/migrations/2020_02_24_005015_add_fk_stats.php | 32 |
7 files changed, 168 insertions, 9 deletions
diff --git a/app/Anime.php b/app/Anime.php index e19e214..ac5c650 100644 --- a/app/Anime.php +++ b/app/Anime.php @@ -10,6 +10,7 @@ use Jikan\MyAnimeList\MalClient; class Anime extends Model { + /* public $id; public $mal_id; @@ -22,6 +23,7 @@ class Anime extends Model { public $title_pref; public $type; + */ private $animeInfo; @@ -53,6 +55,12 @@ class Anime extends Model { } } + /* + public function getStats() { + return $this->hasMany('App\AnimeStats'); + } +*/ + protected function getInfo() { return $this->animeInfo; } diff --git a/app/AnimeStats.php b/app/AnimeStats.php index fc69468..3bc6d25 100644 --- a/app/AnimeStats.php +++ b/app/AnimeStats.php @@ -1,11 +1,14 @@ <?php namespace App; +use Illuminate\Database\Eloquent\Model; use Jikan\MyAnimeList\MalClient; -class AnimeStats extends Anime { +#class AnimeStats extends Anime { +class AnimeStats extends Model { + /* public $mal_id; public $season_year; @@ -34,17 +37,18 @@ class AnimeStats extends Anime { public $score_8; public $score_9; public $score_10; + */ /** * Eloquent ORM */ protected $table = 'stats'; - protected $fillable = ['mal_id','season_year','season_name','score','scored_by','rank','popularity','members','favorites', 'watching','completed','onhold','dropped','plan_to_watch', 'score_1','score_2','score_3','score_4','score_5','score_6','score_7','score_8','score_9','score_10']: + protected $fillable = ['mal_id','season_year','season_name','score','scored_by','rank','popularity','members','favorites', 'watching','completed','onhold','dropped','plan_to_watch', 'score_1','score_2','score_3','score_4','score_5','score_6','score_7','score_8','score_9','score_10']; public function __construct( $id, $season_year = 0, $season_name = "" ) { $this->mal_id = $id; - parent::__construct($this->mal_id); + #parent::__construct($this->mal_id); $jikan = new Malclient; @@ -63,7 +67,10 @@ class AnimeStats extends Anime { } */ - $animeInfo = $this->getInfo(); + #$animeInfo = $this->getInfo(); + $animeInfo = $jikan->getAnime( + (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) + ); $this->score = $animeInfo->getScore(); $this->scored_by = $animeInfo->getScoredBy(); $this->rank = $animeInfo->getRank(); diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 40bffa6..e254c50 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -40,7 +40,7 @@ class IndexController extends Controller { #$stats = new AnimeScore( 21 ); #var_dump($stats); - echo "<pre>"; - var_dump($season); + #echo "<pre>"; + #var_dump($season); } } diff --git a/app/Libraries/AnimeSeason.php b/app/Libraries/AnimeSeason.php index acdb34f..1bc3655 100644 --- a/app/Libraries/AnimeSeason.php +++ b/app/Libraries/AnimeSeason.php @@ -1,6 +1,8 @@ <?php namespace App\Libraries; +use Illuminate\Support\Facades\DB; + use App\Libraries\AnimeSeason; use App\Anime; use App\AnimeStats; @@ -19,6 +21,7 @@ class AnimeSeason { public $anime; public function __construct() { + #Anime::where('mal_id', 2 ); $jikan = new MalClient; $season = $jikan->getSeasonal( @@ -33,17 +36,21 @@ class AnimeSeason { foreach($season->anime as $entry) { $count++; + #Anime::where('mal_id', $entry->getMalID() ); $anime = new Anime( $entry->getMalID() ); - $anime->save(); + + if( ! DB::table('anime')->where('mal_id', $entry->getMalID() )->exists() ) { + $anime->save(); + } $animeStats = new AnimeStats( $entry->getMalID(), $this->year, $this->name ); $this->anime[] = $animeStats; - $animeStats->create(); + $animeStats->save(); /* echo "<pre>"; - var_dump($anime); + var_dump($animeStats); */ if ( $count == 1) { diff --git a/database/migrations/2020_02_23_235746_create_anime_table.php b/database/migrations/2020_02_23_235746_create_anime_table.php new file mode 100644 index 0000000..985812e --- /dev/null +++ b/database/migrations/2020_02_23_235746_create_anime_table.php @@ -0,0 +1,44 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +class CreateAnimeTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('anime', function (Blueprint $table) { + $table->bigIncrements('id'); + + $table->unsignedBigInteger('mal_id')->unique()->default('0'); + + $table->string('url')->default(''); + $table->string('image_url')->default(''); + + $table->string('title_eng')->default(''); + $table->string('title_rom')->default(''); + $table->string('title_nat')->default(''); + $table->string('title_pref')->default(''); + + $table->string('type')->default(''); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('anime'); + } +} diff --git a/database/migrations/2020_02_23_235949_create_stats_table.php b/database/migrations/2020_02_23_235949_create_stats_table.php new file mode 100644 index 0000000..142374c --- /dev/null +++ b/database/migrations/2020_02_23_235949_create_stats_table.php @@ -0,0 +1,61 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +class CreateStatsTable extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('stats', function (Blueprint $table) { + $table->bigIncrements('id'); + + $table->unsignedBigInteger('mal_id')->default(0); + + $table->string('season_name')->default(''); + $table->integer('season_year')->default(0); + + $table->float('score')->default(0); + $table->integer('scored_by')->default(0); + $table->integer('rank')->default(0); + $table->integer('popularity')->default(0); + $table->integer('members')->default(0); + $table->integer('favorites')->default(0); + + $table->integer('watching')->default(0); + $table->integer('completed')->default(0); + $table->integer('onhold')->default(0); + $table->integer('dropped')->default(0); + $table->integer('plan_to_watch')->default(0); + + $table->integer('score_1')->default(0); + $table->integer('score_2')->default(0); + $table->integer('score_3')->default(0); + $table->integer('score_4')->default(0); + $table->integer('score_5')->default(0); + $table->integer('score_6')->default(0); + $table->integer('score_7')->default(0); + $table->integer('score_8')->default(0); + $table->integer('score_9')->default(0); + $table->integer('score_10')->default(0); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('stats'); + } +} diff --git a/database/migrations/2020_02_24_005015_add_fk_stats.php b/database/migrations/2020_02_24_005015_add_fk_stats.php new file mode 100644 index 0000000..3a6a66a --- /dev/null +++ b/database/migrations/2020_02_24_005015_add_fk_stats.php @@ -0,0 +1,32 @@ +<?php + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +class AddFkStats extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('stats', function (Blueprint $table) { + $table->foreign('mal_id')->references('mal_id')->on('anime'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('stats', function (Blueprint $table) { + // + }); + } +} |
