Skip to content
This repository was archived by the owner on Jan 1, 2021. It is now read-only.

Commit 65a6ebc

Browse files
committed
Added genres to all responses.
1 parent 7a14068 commit 65a6ebc

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

app/Helpers/Helper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public static function get_from_imdb_py($path, $selection, $rememberMinutes = 60
3737
foreach ($movies as $movie)
3838
{
3939
$movie->genres = explode(",", $movie->genres);
40+
$movie->adult = $movie->adult == 1;
41+
unset($movie->type);
4042
$with_genres[] = $movie;
4143
}
4244

app/Http/Controllers/API/DiscoverController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function recommendations(Request $request) {
5757
{
5858
abort(422, "Please add some movies before using our recommendation engine :)");
5959
}
60-
$movies_db = DB::select("SELECT mo.id, mo.popularity, mo.imdb_id, mo.title, mo.overview, mo.vote_average, mo.vote_count, mo.tagline, mo.poster_path, mo.release_date, mo.release_year, mo.trailer_key, mo.trailer_site, mo.backdrop_path, mo.homepage, mo.runtime, mo.countO FROM ( SELECT m.*, r.recommended_id, r.tmdbid, r.id as rid, count(m.id) as countO FROM movies m, recommendations r WHERE m.id = r.recommended_id AND r.tmdbid in ($ids) AND r.recommended_id not in ($ids$ignoredIds) AND m.adult = 0 GROUP BY m.id ) as mo;");
60+
$movies_db = DB::select("SELECT mo.id, mo.popularity, mo.imdb_id, mo.title, mo.overview, mo.vote_average, mo.vote_count, mo.tagline, mo.poster_path, mo.release_date, mo.release_year, mo.trailer_key, mo.trailer_site, mo.backdrop_path, mo.homepage, mo.runtime, mo.countO, mo.genres, mo.runtime, mo.adult FROM ( SELECT m.*, r.recommended_id, r.tmdbid, r.id as rid, count(m.id) as countO FROM movies m, recommendations r WHERE m.id = r.recommended_id AND r.tmdbid in ($ids) AND r.recommended_id not in ($ids$ignoredIds) AND m.adult = 0 GROUP BY m.id ) as mo;");
6161
$movies = json_decode(json_encode($movies_db), true);
6262

6363
$this->count_max = maximum($movies, "countO");
@@ -67,8 +67,17 @@ public function recommendations(Request $request) {
6767
usort($movies, array($this, "compare_score"));
6868

6969
$movies = array_slice($movies, 0, 30);
70+
$resp = [];
7071

71-
return response()->json($movies);
72+
foreach ($movies as $movie) {
73+
unset($movie["countO"]);
74+
$movie["genres"] = explode(",", $movie["genres"]);
75+
$movie["adult"] = $movie["adult"] == 1;
76+
$resp[] = $movie;
77+
}
78+
79+
80+
return response()->json($resp);
7281
}
7382

7483
function score ($elem)

app/Mapping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function vote($direction = 1)
8282
{
8383
return;
8484
}
85-
85+
8686
$ip = md5($_SERVER['REMOTE_ADDR']);
8787
if (Event::whereIn("type", [EventType::AddedMapping, EventType::ApproveMapping, EventType::DisapproveMapping])->where("mappings_id", "=", $this->id)->where("ip", "=", $ip)->whereBetween("date", array(Carbon::now()->addDays(-1), Carbon::now()))->first())
8888
{

app/Movie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function toArray()
3535
$arr["physical_release"] = $physical_release->release_date;
3636
$arr["physical_release_note"] = $physical_release->note;
3737
}
38-
$arr["genre_ids"] = explode(",", $this->genres);
39-
unset($arr["genres"]);
38+
$arr["genres"] = explode(",", $this->genres);
39+
//unset($arr["genres"]);
4040
return $arr;
4141
}
4242

0 commit comments

Comments
 (0)