diff options
| -rw-r--r-- | app/Anime.php | 9 | ||||
| -rw-r--r-- | app/AnimeStats.php (renamed from app/AnimeScore.php) | 31 | ||||
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 2 | ||||
| -rw-r--r-- | app/Libraries/AnimeSeason.php | 20 |
4 files changed, 49 insertions, 13 deletions
diff --git a/app/Anime.php b/app/Anime.php index 1e8fb95..e19e214 100644 --- a/app/Anime.php +++ b/app/Anime.php @@ -1,4 +1,7 @@ <?php +/** + * https://stackoverflow.com/questions/26863439/in-laravel-eloquent-inserts-an-empty-record-to-table + */ namespace App; use Illuminate\Database\Eloquent\Model; @@ -8,6 +11,7 @@ use Jikan\MyAnimeList\MalClient; class Anime extends Model { public $id; + public $mal_id; public $url; public $image_url; @@ -25,15 +29,16 @@ class Anime extends Model { * Eloquent ORM */ protected $table = 'anime'; + protected $fillable = ['mal_id','url','image_url','title_eng','title_rom','title_nat','title_pref','type',]; public function __construct( $id, $parse_info = true ) { - $this->id = $id; + $this->mal_id = $id; if ( $parse_info ) { $jikan = new Malclient; $this->animeInfo = $jikan->getAnime( - (new \Jikan\Request\Anime\AnimeRequest( $this->id )) + (new \Jikan\Request\Anime\AnimeRequest( $this->mal_id )) ); $this->url = $this->animeInfo->GetUrl(); diff --git a/app/AnimeScore.php b/app/AnimeStats.php index 9f150d0..fc69468 100644 --- a/app/AnimeScore.php +++ b/app/AnimeStats.php @@ -4,7 +4,12 @@ namespace App; use Jikan\MyAnimeList\MalClient; -class AnimeScore extends Anime { +class AnimeStats extends Anime { + + public $mal_id; + + public $season_year; + public $season_name; public $score; public $scored_by; @@ -34,14 +39,30 @@ class AnimeScore extends Anime { * 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']: - public function __construct( $id ) { - $this->id = $id; + public function __construct( $id, $season_year = 0, $season_name = "" ) { + $this->mal_id = $id; - parent::__construct($this->id); + parent::__construct($this->mal_id); $jikan = new Malclient; +# if ( 0 == $season_year || "" == $season_name ) { + $season = $jikan->getSeasonal( + (new \Jikan\Request\Seasonal\SeasonalRequest( + )) + ); + + $this->season_year = $season->seasonYear; + $this->season_name= $season->seasonName; + /* + } else { + $this->season_year = $season_year; + $this->season_name= $season_name; + } +*/ + $animeInfo = $this->getInfo(); $this->score = $animeInfo->getScore(); $this->scored_by = $animeInfo->getScoredBy(); @@ -51,7 +72,7 @@ class AnimeScore extends Anime { $this->favorites = $animeInfo->getFavorites(); $animeStats = $jikan->getAnimeStats( - (new \Jikan\Request\Anime\AnimeStatsRequest( $this->id )) + (new \Jikan\Request\Anime\AnimeStatsRequest( $this->mal_id )) ); $this->watching = $animeStats->getWatching(); diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index e6a263b..40bffa6 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -6,7 +6,7 @@ use Illuminate\Http\Request; use App\Libraries\AnimeSchedule; use App\Libraries\AnimeSeason; -use App\AnimeScore; +use App\AnimeStats; class IndexController extends Controller { /** diff --git a/app/Libraries/AnimeSeason.php b/app/Libraries/AnimeSeason.php index a234d5c..acdb34f 100644 --- a/app/Libraries/AnimeSeason.php +++ b/app/Libraries/AnimeSeason.php @@ -3,7 +3,7 @@ namespace App\Libraries; use App\Libraries\AnimeSeason; use App\Anime; -use App\AnimeScore; +use App\AnimeStats; use Carbon\Carbon; @@ -27,16 +27,26 @@ class AnimeSeason { ); $this->year = $season->seasonYear; - $this->name= $season->seasonName; + $this->name = $season->seasonName; $count = 0; foreach($season->anime as $entry) { $count++; - $anime = new AnimeScore( $entry->getMalID() ); - $this->anime[] = $anime; + + $anime = new Anime( $entry->getMalID() ); $anime->save(); - if ( $count == 5) { + $animeStats = new AnimeStats( $entry->getMalID(), $this->year, $this->name ); + $this->anime[] = $animeStats; + + $animeStats->create(); + + /* + echo "<pre>"; + var_dump($anime); + */ + + if ( $count == 1) { return; } } |
