1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Jikan\MyAnimeList\MalClient;
class AnimeStats extends Model {
/*
private $mal_id;
private $season_year;
private $season_name;
private $score;
private $scored_by;
private $rank;
private $popularity;
private $members;
private $favorites;
private $watching;
private $completed;
private $onhold;
private $dropped;
private $plan_to_watch;
private $score_1;
private $score_2;
private $score_3;
private $score_4;
private $score_5;
private $score_6;
private $score_7;
private $score_8;
private $score_9;
private $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'
];
public function __construct() {
}
public function fill( $id, $season_year = 0, $season_name = "" ) {
$this->mal_id = $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;
}
try {
$animeInfo = $jikan->getAnime(
(new \Jikan\Request\Anime\AnimeRequest( $this->mal_id ))
);
} catch (\Exception $e) {
echo "Error requesting AnimeInfo for " . $this->mal_id ."\n";
echo "Message: " . $e->getMessage();
echo "\n\n";
return false;
}
$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();
try {
$animeStats = $jikan->getAnimeStats(
(new \Jikan\Request\Anime\AnimeStatsRequest( $this->mal_id ))
);
} catch (\Exception $e) {
echo "Error requesting AnimeStats for " . $this->mal_id ."\n";
echo "Message: " . $e->getMessage();
echo "\n\n";
return false;
}
$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();
if ( isset($scores[1] )) {
$this->score_1 = $scores[1]->getVotes();
} else {
$this->score_1 = 0;
}
if ( isset($scores[2]) ) {
$this->score_2 = $scores[2]->getVotes();
} else {
$this->score_2 = 0;
}
if ( isset($scores[3]) ) {
$this->score_3 = $scores[3]->getVotes();
} else {
$this->score_3 = 0;
}
if ( isset($scores[4]) ) {
$this->score_4 = $scores[4]->getVotes();
} else {
$this->score_4 = 0;
}
if ( isset($scores[5]) ) {
$this->score_5 = $scores[5]->getVotes();
} else {
$this->score_5 = 0;
}
if ( isset($scores[6]) ) {
$this->score_6 = $scores[6]->getVotes();
} else {
$this->score_6 = 0;
}
if ( isset($scores[7]) ) {
$this->score_7 = $scores[7]->getVotes();
} else {
$this->score_7 = 0;
}
if ( isset($scores[8]) ) {
$this->score_8 = $scores[8]->getVotes();
} else {
$this->score_8 = 0;
}
if ( isset($scores[9]) ) {
$this->score_9 = $scores[9]->getVotes();
} else {
$this->score_9 = 0;
}
if ( isset($scores[10]) ) {
$this->score_10 = $scores[10]->getVotes();
} else {
$this->score_10 = 0;
}
return true;
}
public function anime() {
return $this->belongsTo('App\Anime', 'mal_id', 'mal_id');
}
}
|