Skip to content

Commit e2a56ee

Browse files
actioussanwtfzdotnet
authored andcommitted
Add implementation for recommendations (#179)
* Add implementation for recommendations * Edited credits
1 parent 45f59e7 commit e2a56ee

17 files changed

Lines changed: 191 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* This file is part of the Tmdb PHP API created by Michael Roterman.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @package Tmdb
9+
* @author Eugenia Schneider <eugenia@werstreamt.es>
10+
* @copyright (c) 2018, Eugenia Schneider
11+
* @version 0.0.1
12+
*/
13+
require_once '../../../vendor/autoload.php';
14+
require_once '../../../apikey.php';
15+
16+
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
17+
$client = new \Tmdb\Client($token);
18+
19+
$recommendedMovies = $client->getMoviesApi()->getRecommendations(87421);
20+
21+
var_dump($recommendedMovies);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* This file is part of the Tmdb PHP API created by Michael Roterman.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @package Tmdb
9+
* @author Michael Roterman <michael@wtfz.net>
10+
* @copyright (c) 2013, Michael Roterman
11+
* @version 0.0.1
12+
*/
13+
require_once '../../../vendor/autoload.php';
14+
require_once '../../../apikey.php';
15+
16+
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
17+
$client = new \Tmdb\Client($token);
18+
19+
$repository = new \Tmdb\Repository\MovieRepository($client);
20+
$collection = $repository->getRecommendations(87421);
21+
22+
var_dump($collection);

lib/Tmdb/Api/Movies.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ public function getSimilar($movie_id, array $parameters = [], array $headers = [
137137
return $this->get('movie/' . $movie_id . '/similar', $parameters, $headers);
138138
}
139139

140+
/**
141+
* Get the recommended movies for a specific movie id.
142+
*
143+
* @param $movie_id
144+
* @param array $parameters
145+
* @param array $headers
146+
* @return mixed
147+
*/
148+
public function getRecommendations($movie_id, array $parameters = [], array $headers = [])
149+
{
150+
return $this->get('movie/' . $movie_id . '/recommendations', $parameters, $headers);
151+
}
152+
140153
/**
141154
* Get the reviews for a particular movie id.
142155
*

lib/Tmdb/Api/Tv.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ public function getSimilar($tvshow_id, array $parameters = [], array $headers =
230230
return $this->get('tv/' . $tvshow_id . '/similar', $parameters, $headers);
231231
}
232232

233+
/**
234+
* Get the recommended TV shows for a specific tv id.
235+
*
236+
* @param $tvshow_id
237+
* @param array $parameters
238+
* @param array $headers
239+
* @return mixed
240+
*/
241+
public function getRecommendations($tvshow_id, array $parameters = [], array $headers = [])
242+
{
243+
return $this->get('tv/' . $tvshow_id . '/recommendations', $parameters, $headers);
244+
}
245+
233246
/**
234247
* This method lets users get the status of whether or not the TV show has been rated
235248
* or added to their favourite or watch lists.

lib/Tmdb/Factory/TvFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ public function create(array $data = [])
226226
$tvShow->setSimilar($this->createResultCollection($data['similar']));
227227
}
228228

229+
if (array_key_exists('recommendations', $data) && $data['recommendations'] !== null) {
230+
$tvShow->setRecommendations($this->createResultCollection($data['recommendations']));
231+
}
232+
229233
if (array_key_exists('languages', $data) && $data['languages'] !== null) {
230234
$collection = new GenericCollection();
231235

lib/Tmdb/Model/Movie.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ class Movie extends AbstractModel
211211
*/
212212
protected $similar;
213213

214+
/**
215+
* @var GenericCollection
216+
*/
217+
protected $recommendations;
218+
214219
/**
215220
* @var GenericCollection
216221
*/
@@ -276,6 +281,7 @@ public function __construct()
276281
$this->releases = new GenericCollection();
277282
$this->release_dates = new GenericCollection();
278283
$this->similar = new GenericCollection();
284+
$this->recommendations = new GenericCollection();
279285
$this->translations = new GenericCollection();
280286
$this->videos = new Videos();
281287
}
@@ -906,6 +912,17 @@ public function setSimilar($similar)
906912
return $this;
907913
}
908914

915+
/**
916+
* @param GenericCollection $recommendations
917+
* @return $this
918+
*/
919+
public function setRecommendations($recommendations)
920+
{
921+
$this->recommendations = $recommendations;
922+
923+
return $this;
924+
}
925+
909926
/**
910927
* @return GenericCollection|Movie[]
911928
*/
@@ -914,6 +931,14 @@ public function getSimilar()
914931
return $this->similar;
915932
}
916933

934+
/**
935+
* @return GenericCollection|Movie[]
936+
*/
937+
public function getRecommendations()
938+
{
939+
return $this->recommendations;
940+
}
941+
917942
/**
918943
* @return GenericCollection|Movie[]
919944
* @deprecated Use getSimilar instead

lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class AppendToResponse extends BaseAppendToResponse
3232
const RELEASE_DATES = 'release_dates';
3333
const TRANSLATIONS = 'translations';
3434
const SIMILAR = 'similar';
35+
const RECOMMENDATIONS = 'recommendations';
3536
const REVIEWS = 'reviews';
3637
const LISTS = 'lists';
3738
const CHANGES = 'changes';

lib/Tmdb/Model/Tv.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ class Tv extends AbstractModel
210210
*/
211211
protected $similar;
212212

213+
/**
214+
* @var GenericCollection
215+
*/
216+
protected $recommendations;
217+
213218
/**
214219
* @var GenericCollection
215220
*/
@@ -275,6 +280,7 @@ public function __construct()
275280
$this->changes = new GenericCollection();
276281
$this->keywords = new GenericCollection();
277282
$this->similar = new GenericCollection();
283+
$this->recommendations = new GenericCollection();
278284
$this->contentRatings = new GenericCollection();
279285
$this->alternativeTitles = new GenericCollection();
280286
}
@@ -944,6 +950,17 @@ public function setSimilar($similar)
944950
return $this;
945951
}
946952

953+
/**
954+
* @param GenericCollection $recommendations
955+
* @return $this
956+
*/
957+
public function setRecommendations($recommendations)
958+
{
959+
$this->recommendations = $recommendations;
960+
961+
return $this;
962+
}
963+
947964
/**
948965
* @return GenericCollection
949966
*/
@@ -952,6 +969,14 @@ public function getSimilar()
952969
return $this->similar;
953970
}
954971

972+
/**
973+
* @return GenericCollection
974+
*/
975+
public function getRecommendations()
976+
{
977+
return $this->recommendations;
978+
}
979+
955980
/**
956981
* @return GenericCollection
957982
*/

lib/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class AppendToResponse extends BaseAppendToResponse
2828
const CHANGES = 'changes';
2929
const KEYWORDS = 'keywords';
3030
const SIMILAR = 'similar';
31+
const RECOMMENDATIONS = 'recommendations';
3132
const CONTENT_RATINGS = 'content_ratings';
3233
const ALTERNATIVE_TITLES = 'alternative_titles';
3334
}

lib/Tmdb/Repository/MovieRepository.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function load($id, array $parameters = [], array $headers = [])
6969
AppendToResponse::RELEASE_DATES,
7070
AppendToResponse::REVIEWS,
7171
AppendToResponse::SIMILAR,
72+
AppendToResponse::RECOMMENDATIONS,
7273
AppendToResponse::TRANSLATIONS,
7374
AppendToResponse::VIDEOS,
7475
])
@@ -207,6 +208,22 @@ public function getSimilar($id, array $parameters = [], array $headers = [])
207208
return $movie->getSimilar();
208209
}
209210

211+
/**
212+
* Get the recommended movies for a specific movie id.
213+
*
214+
* @param $id
215+
* @param $parameters
216+
* @param $headers
217+
* @return null|\Tmdb\Model\AbstractModel
218+
*/
219+
public function getRecommendations($id, array $parameters = [], array $headers = [])
220+
{
221+
$data = $this->getApi()->getRecommendations($id, $this->parseQueryParameters($parameters), $headers);
222+
$movie = $this->getFactory()->create(['recommendations' => $data]);
223+
224+
return $movie->getRecommendations();
225+
}
226+
210227
/**
211228
* Get the reviews for a particular movie id.
212229
*

0 commit comments

Comments
 (0)