Skip to content

Commit bfb64ee

Browse files
committed
Merge pull request #90 from php-tmdb/issue/85-tv-alternative-titles
Issue/85 tv alternative titles
2 parents 693f4f2 + 81d2f5e commit bfb64ee

File tree

8 files changed

+152
-23
lines changed

8 files changed

+152
-23
lines changed
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 Michael Roterman <[email protected]>
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+
$result = $client->getTvApi()->getAlternativeTitles(1396);
20+
21+
var_dump($result);
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 <[email protected]>
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\TvRepository($client);
20+
$tvShow = $repository->getAlternativeTitles(1396);
21+
22+
var_dump($tvShow);

lib/Tmdb/Api/Tv.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,15 @@ public function rateTvShow($id, $rating)
257257
{
258258
return $this->postJson('tv/' . $id . '/rating', ['value' => (float) $rating]);
259259
}
260+
261+
/**
262+
* Get the alternative titles for a specific show ID.
263+
*
264+
* @param integer $id
265+
* @return mixed
266+
*/
267+
public function getAlternativeTitles($id)
268+
{
269+
return $this->get('tv/' . $id . '/alternative_titles');
270+
}
260271
}

lib/Tmdb/Factory/TvFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ public function create(array $data = [])
258258
$tvShow->setCreatedBy($collection);
259259
}
260260

261+
if (array_key_exists('alternative_titles', $data) && array_key_exists('results', $data['alternative_titles'])) {
262+
$tvShow->setAlternativeTitles(
263+
$this->createGenericCollection($data['alternative_titles']['results'], new Tv\AlternativeTitle())
264+
);
265+
}
266+
261267
return $this->hydrate($tvShow, $data);
262268
}
263269

lib/Tmdb/Model/Tv.php

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ class Tv extends AbstractModel
215215
*/
216216
protected $productionCompanies;
217217

218+
/**
219+
* Alternative titles
220+
*
221+
* @var GenericCollection
222+
*/
223+
protected $alternativeTitles;
224+
218225
/**
219226
* Properties that are available in the API
220227
*
@@ -250,19 +257,20 @@ class Tv extends AbstractModel
250257
*/
251258
public function __construct()
252259
{
253-
$this->genres = new Genres();
254-
$this->networks = new GenericCollection();
255-
$this->originCountry = new GenericCollection();
256-
$this->seasons = new GenericCollection();
257-
$this->credits = new CreditsCollection();
258-
$this->externalIds = new ExternalIds();
259-
$this->images = new Images();
260-
$this->translations = new GenericCollection();
261-
$this->videos = new Videos();
262-
$this->changes = new GenericCollection();
263-
$this->keywords = new GenericCollection();
264-
$this->similar = new GenericCollection();
265-
$this->contentRatings = new GenericCollection();
260+
$this->genres = new Genres();
261+
$this->networks = new GenericCollection();
262+
$this->originCountry = new GenericCollection();
263+
$this->seasons = new GenericCollection();
264+
$this->credits = new CreditsCollection();
265+
$this->externalIds = new ExternalIds();
266+
$this->images = new Images();
267+
$this->translations = new GenericCollection();
268+
$this->videos = new Videos();
269+
$this->changes = new GenericCollection();
270+
$this->keywords = new GenericCollection();
271+
$this->similar = new GenericCollection();
272+
$this->contentRatings = new GenericCollection();
273+
$this->alternativeTitles = new GenericCollection();
266274
}
267275

268276
/**
@@ -956,4 +964,23 @@ public function setProductionCompanies($productionCompanies)
956964

957965
return $this;
958966
}
967+
968+
/**
969+
* @param \Tmdb\Model\Common\GenericCollection $alternativeTitles
970+
* @return $this
971+
*/
972+
public function setAlternativeTitles($alternativeTitles)
973+
{
974+
$this->alternativeTitles = $alternativeTitles;
975+
976+
return $this;
977+
}
978+
979+
/**
980+
* @return \Tmdb\Model\Common\GenericCollection
981+
*/
982+
public function getAlternativeTitles()
983+
{
984+
return $this->alternativeTitles;
985+
}
959986
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 <[email protected]>
10+
* @copyright (c) 2013, Michael Roterman
11+
* @version 0.0.1
12+
*/
13+
namespace Tmdb\Model\Tv;
14+
15+
use Tmdb\Model\Movie\AlternativeTitle as BaseAlternativeTitle;
16+
17+
/**
18+
* Class AlternativeTitle
19+
* @package Tmdb\Model\Tv
20+
*/
21+
class AlternativeTitle extends BaseAlternativeTitle
22+
{
23+
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
*/
2121
class AppendToResponse extends BaseAppendToResponse
2222
{
23-
const CREDITS = 'credits';
24-
const EXTERNAL_IDS = 'external_ids';
25-
const IMAGES = 'images';
26-
const TRANSLATIONS = 'translations';
27-
const VIDEOS = 'videos';
28-
const CHANGES = 'changes';
29-
const KEYWORDS = 'keywords';
30-
const SIMILAR = 'similar';
31-
const CONTENT_RATINGS = 'content_ratings';
23+
const CREDITS = 'credits';
24+
const EXTERNAL_IDS = 'external_ids';
25+
const IMAGES = 'images';
26+
const TRANSLATIONS = 'translations';
27+
const VIDEOS = 'videos';
28+
const CHANGES = 'changes';
29+
const KEYWORDS = 'keywords';
30+
const SIMILAR = 'similar';
31+
const CONTENT_RATINGS = 'content_ratings';
32+
const ALTERNATIVE_TITLES = 'alternative_titles';
3233
}

lib/Tmdb/Repository/TvRepository.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Tmdb\Factory\TvFactory;
1616
use Tmdb\Model\Collection\Videos;
1717
use Tmdb\Model\Common\AccountStates;
18+
use Tmdb\Model\Common\GenericCollection;
1819
use Tmdb\Model\Common\Video;
1920
use Tmdb\Model\Lists\Result;
2021
use Tmdb\Model\Tv;
@@ -51,7 +52,8 @@ public function load($id, array $parameters = [], array $headers = [])
5152
AppendToResponse::SIMILAR,
5253
AppendToResponse::KEYWORDS,
5354
AppendToResponse::CHANGES,
54-
AppendToResponse::CONTENT_RATINGS
55+
AppendToResponse::CONTENT_RATINGS,
56+
AppendToResponse::ALTERNATIVE_TITLES
5557
])
5658
];
5759
}
@@ -161,6 +163,22 @@ public function getVideos($id, array $parameters = [], array $headers = [])
161163
return $tv->getVideos();
162164
}
163165

166+
/**
167+
* Get the alternative titles for a specific show ID.
168+
*
169+
* @param $id
170+
* @param $parameters
171+
* @param $headers
172+
* @return GenericCollection|Tv\AlternativeTitle[]
173+
*/
174+
public function getAlternativeTitles($id, array $parameters = [], array $headers = [])
175+
{
176+
$data = $this->getApi()->getAlternativeTitles($id, $this->parseQueryParameters($parameters), $headers);
177+
$tv = $this->getFactory()->create(['alternative_titles' => $data]);
178+
179+
return $tv->getAlternativeTitles();
180+
}
181+
164182
/**
165183
* Return the Tvs API Class
166184
*

0 commit comments

Comments
 (0)