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
192
193
194
195
196
197
|
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Anime;
use App\AnimeStats;
use Carbon\Carbon;
class AnimeController extends Controller {
/**
* Shows the index page.
*
* @return Response
*/
public function showAnime($mal_id, $slug = "") {
$anime = Anime::where('mal_id', $mal_id)->get()->first();
if ( is_null($anime) ) {
abort(404);
}
/**
* Redirects to correct slug.
*/
if ( $slug != Str::slug($anime->title_pref) ) {
return redirect()->route('anime', ["mal_id" => $anime->mal_id, "slug" => Str::slug($anime->title_pref)]);
}
$anime["stats"] = $anime->getStats()->orderBy('created_at', 'asc')->get();
foreach( $anime["stats"] as $stats ) {
if ( ! is_null($stats->score) ) {
$score[] = $stats->score;
$rank[] = $stats->rank;
$created_at_score[] = $stats->created_at->toDateString();
}
$created_at[] = $stats->created_at->toDateString();
$popularity[] = $stats->popularity;
$members[] = $stats->members;
$favorites[] = $stats->favorites;
$watching[] = $stats->watching;
$completed[] = $stats->completed;
$onhold[] = $stats->onhold;
$dropped[] = $stats->dropped;
$plan_to_watch[] = $stats->plan_to_watch;
$scored_by[] = $stats->scored_by;
$score_1[] = $stats->score_1;
$score_2[] = $stats->score_2;
$score_3[] = $stats->score_3;
$score_4[] = $stats->score_4;
$score_5[] = $stats->score_5;
$score_6[] = $stats->score_6;
$score_7[] = $stats->score_7;
$score_8[] = $stats->score_8;
$score_9[] = $stats->score_9;
$score_10[] = $stats->score_10;
}
if ( isset($score) ) {
$anime["score"] = $score;
$anime["rank"] = $rank;
$anime["chart_label_score"] = $created_at_score;
}
$anime["popularity"] = $popularity;
$anime["members"] = $members;
$anime["favorites"] = $favorites;
$anime["watching"] = $watching;
$anime["onhold"] = $onhold;
$anime["plan_to_watch"] = $plan_to_watch;
$anime["completed"] = $completed;
$anime["dropped"] = $dropped;
$anime["scored_by"] = $scored_by;
$anime["score_1"] = $score_1;
$anime["score_2"] = $score_2;
$anime["score_3"] = $score_3;
$anime["score_4"] = $score_4;
$anime["score_5"] = $score_5;
$anime["score_6"] = $score_6;
$anime["score_7"] = $score_7;
$anime["score_8"] = $score_8;
$anime["score_9"] = $score_9;
$anime["score_10"] = $score_10;
$anime["chart_label"] = $created_at;
$anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0];
return view('anime', [ "anime" => $anime ]);
}
public function showCurrentAnime() {
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
#$anime = $anime->setTable('anime');
$anime = $anime->where('airing_status', env('ANIME_IS_AIRING'));
$anime = $anime->orderBy('season_year', 'desc');
$anime = $anime->orderByRaw('FIELD(season_name, ' . $this->_getFieldSeasonName() . ')');
$anime = $anime->orderBy('score_today', 'desc');
$anime = $anime->orderBy('members', 'desc');
$anime = $anime->orderBy('watching', 'desc');
$anime = $anime->get();
#$anime = $anime->simplePaginate(10);
return view('list_anime', ["all_anime" => $anime, "title" => "Currently Airing"]);
}
private function _getFieldSeasonName() {
$first = (int)date("m");
$second = nextSeason($first);
$third = nextSeason($second);
$fourth = nextSeason($third);
return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"';
}
public function showSurprisingAnime() {
$anime = new Anime;
$most_surprising_anime = $anime->setTable('view_anime_index');
$most_surprising_anime = $most_surprising_anime->paginate(12);
#$most_surprising_anime = $most_surprising_anime->simplePaginate(10);
#$most_surprising_anime = $most_surprising_anime->get();
#return view('surprising_anime', ["surprising_anime" => $most_surprising_anime, "title" => "Most Surprising"]);
return view('list_anime', ["all_anime" => $most_surprising_anime, "title" => "Most Surprising Anime"]);
}
public function showTopAnime() {
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
$anime = $anime->orderBy('score_today', 'desc');
#$top_anime = $anime->simplePaginate(10);
#$top_anime = $anime->get();
$top_anime = $anime->paginate(12);
#return view('top_anime', ["top_anime" => $top_anime, "title" => "Top"]);
return view('list_anime', ["all_anime" => $top_anime, "title" => "Top Anime of all Time"]);
}
public function search(Request $request) {
$search_unsafe = explode(",", $request->input("q"));
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
foreach($search_unsafe as $q) {
$q_raw = escapeLike($q);
$q = "%".$q_raw."%";
/*
$anime = $anime->where('title_eng', 'like', $q)
->orWhere('title_rom', 'like', $q)
->orWhere('title_nat', 'like', $q)
->orWhere('title_pref', 'like', $q)
->orWhere('synopsis', 'like', $q);
*/
$anime = $anime->where('title_eng', 'like', $q)
->orWhere('mal_id', '=', $q_raw)
->orWhere('title_pref', 'like', $q)
->orWhere('synopsis', 'like', $q);
}
$count = $anime->count();
$anime = $anime->orderBy('season_year', 'desc');
$anime = $anime->orderByRaw('FIELD(season_name, "Summer", "Fall", "Winter", "Spring")');
$anime = $anime->orderBy('score_today', 'desc');
$anime = $anime->orderBy('members', 'desc');
$anime = $anime->orderBy('watching', 'desc');
$sanime = $anime->paginate(12);
return view('list_anime', ["all_anime" => $sanime, "title" => "Search", "count" => $count]);
}
public function showSeason($season_name, $season_year) {
$season_name = ucfirst($season_name);
$anime = new Anime;
$anime = $anime->setTable('view_anime_index');
$anime = $anime->where('season_name', '=', $season_name)->where('season_year', '=', $season_year);
$anime = $anime->orderBy('score_today', 'desc');
$anime = $anime->orderBy('members', 'desc');
$anime = $anime->orderBy('watching', 'desc');
$sanime = $anime->paginate(12);
return view('list_anime', ["all_anime" => $sanime, "title" => $season_name . " Season " . $season_year]);
}
}
|