Skip to content

Commit

Permalink
Merge pull request #41 from srichter/add_tv_networks
Browse files Browse the repository at this point in the history
Add Logo Result, Name Result, and TVNetwork item
  • Loading branch information
vfalies authored Mar 7, 2020
2 parents ce30fce + 537aba9 commit 1161510
Show file tree
Hide file tree
Showing 17 changed files with 1,284 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.8] - 2020-03-07
### Added

- Add Logo Result, Name Result, and TVNetwork item (SRichter contributor)

## [1.7.1] - 2020-03-07
### Added

- Add missing unit tests

## [1.7] - 2020-01-17
### Added

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Features actualy supported :
- Collection
- Company
- Genres
- TV Network
- Account
- Authentification
- Movies / TV Shows rating
Expand Down
67 changes: 67 additions & 0 deletions src/VfacTmdb/Interfaces/Items/TVNetworkInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Tmdb package.
*
* (c) Vincent Faliès <vincent@vfac.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Vincent Faliès <vincent@vfac.fr>
* @copyright Copyright (c) 2017-2020
*/


namespace VfacTmdb\Interfaces\Items;

/**
* Interface for TVNetwork type object
* @package Tmdb
* @author Steve Richter <steve@nerdbra.in>
* @copyright Copyright (c) 2017-2020
*/
interface TVNetworkInterface
{

/**
* Id
* @return int
*/
public function getId() : int;

/**
* Name
* @return string
*/
public function getName() : string;

/**
* Headquarters
* @return string
*/
public function getHeadquarters() : string;

/**
* Homepage
* @return string
*/
public function getHomepage() : string;

/**
* Origin country
* @return string
*/
public function getOriginCountry() : string;

/**
* Logos list
* @return \Generator
*/
public function getLogos() : \Generator;

/**
* Alternative names list
* @return \Generator
*/
public function getAlternativeNames() : \Generator;
}
15 changes: 15 additions & 0 deletions src/VfacTmdb/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,19 @@ public function getCompany(int $company_id, array $options = array()) : Items\Co

return $company;
}

/**
* Get TV Network details
* @param int $network_id
* @param array $options
* @return Items\TVNetwork
* @author Steve Richter <steve@nerdbra.in>
*/
public function getTVNetwork(int $network_id, array $options = array()) : Items\TVNetwork
{
$this->logger->debug('Starting getting tvnetwork', array('network_id' => $network_id, 'options' => $options));
$tvnetwork = new Items\TVNetwork($this->tmdb, $network_id, $options);

return $tvnetwork;
}
}
1 change: 0 additions & 1 deletion src/VfacTmdb/Items/MovieVideos.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ public function getVideos() : \Generator
}
}
}

}
129 changes: 129 additions & 0 deletions src/VfacTmdb/Items/TVNetwork.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Tmdb package.
*
* (c) Vincent Faliès <vincent@vfac.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Vincent Faliès <vincent@vfac.fr>
* @copyright Copyright (c) 2017-2020
*/


namespace VfacTmdb\Items;

use VfacTmdb\Abstracts\Item;
use VfacTmdb\Interfaces\Items\TVNetworkInterface;
use VfacTmdb\Interfaces\TmdbInterface;
use VfacTmdb\Results;

/**
* TVNetwork class
* @package Tmdb
* @author Steve Richter <steve@nerdbra.in>
* @copyright Copyright (c) 2017-2020
*/
class TVNetwork extends Item implements TVNetworkInterface
{
/**
* Constructor
* @param TmdbInterface $tmdb
* @param int $network_id
* @param array $options
*/
public function __construct(TmdbInterface $tmdb, int $network_id, array $options = array())
{
parent::__construct($tmdb, $network_id, $options, 'network');
}

/**
* Get TV Network id
* @return int
*/
public function getId() : int
{
return $this->id;
}

/**
* Get TV Network name
* @return string
*/
public function getName() : string
{
if (isset($this->data->name)) {
return $this->data->name;
}
return '';
}

/**
* Get TV Network headquarters
* @return string
*/
public function getHeadquarters() : string
{
if (isset($this->data->headquarters)) {
return $this->data->headquarters;
}
return '';
}

/**
* Get TV Network homepage
* @return string
*/
public function getHomepage() : string
{
if (isset($this->data->homepage)) {
return $this->data->homepage;
}
return '';
}

/**
* Get TV Network origin country
* @return string
*/
public function getOriginCountry() : string
{
if (isset($this->data->origin_country)) {
return $this->data->origin_country;
}
return '';
}

/**
* Alternative names list
* @return \Generator|Results\AlternativeName
*/
public function getAlternativeNames() : \Generator
{
$params = [];
$this->tmdb->checkOptionLanguage($this->params, $params);
$data = $this->tmdb->getRequest('network/' . (int) $this->id . '/alternative_names', $params);

foreach ($data->results as $n) {
$name = new Results\AlternativeName($this->tmdb, $this->id, $n);
yield $name;
}
}

/**
* Logos list
* @return \Generator|Results\Logo
*/
public function getLogos() : \Generator
{
$params = [];
$this->tmdb->checkOptionLanguage($this->params, $params);
$data = $this->tmdb->getRequest('network/' . (int) $this->id . '/images', $params);

foreach ($data->logos as $logo) {
$image = new Results\Logo($this->tmdb, $this->id, $logo);
yield $image;
}
}
}
86 changes: 86 additions & 0 deletions src/VfacTmdb/Results/AlternativeName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php declare(strict_types = 1);
/**
* This file is part of the Tmdb package.
*
* (c) Vincent Faliès <vincent@vfac.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Vincent Faliès <vincent@vfac.fr>
* @copyright Copyright (c) 2017-2020
*/


namespace VfacTmdb\Results;

use VfacTmdb\Abstracts\Results;
use VfacTmdb\Interfaces\TmdbInterface;

/**
* Class to manipulate a name result
* @package Tmdb
* @author Steve Richter <steve@nerdbra.in>
* @copyright Copyright (c) 2017-2020
*/
class AlternativeName extends Results
{
/**
* Id
* @var int
*/
protected $id;
/**
* Name
* @var string
*/
protected $name;
/**
* Type
* @var string
*/
protected $type;

/**
* Constructor
* @param TmdbInterface $tmdb
* @param int $id
* @param \stdClass $result
*/
public function __construct(TmdbInterface $tmdb, int $id, \stdClass $result)
{
$result->id = $id;
parent::__construct($tmdb, $result);

$this->id = (int) $id;
$this->name = $result->name;
$this->type = $result->type;
}

/**
* Id
* @return int
*/
public function getId() : int
{
return $this->id;
}

/**
* Name
* @return string
*/
public function getName() : string
{
return $this->name;
}

/**
* Type
* @return string
*/
public function getType() : string
{
return $this->type;
}
}
Loading

0 comments on commit 1161510

Please sign in to comment.