1: <?php
2: namespace Duyplus\TMDBApi\Classes\Data;
3:
4: use Duyplus\TMDBApi\Classes\Data\Movie;
5:
6: class Collection
7: {
8: //------------------------------------------------------------------------------
9: // Class Variables
10: //------------------------------------------------------------------------------
11:
12: private $crawl;
13:
14: /**
15: * Construct Class
16: *
17: * @param array $data An array with the data of the Collection
18: */
19: public function __construct($data)
20: {
21: $this->crawl = $data;
22: }
23:
24: //------------------------------------------------------------------------------
25: // Get Variables
26: //------------------------------------------------------------------------------
27:
28: /**
29: * Get the Collection's id
30: *
31: * @return int
32: */
33: public function getID()
34: {
35: return $this->crawl['id'];
36: }
37:
38: /**
39: * Get the Collection's name
40: *
41: * @return string
42: */
43: public function getName()
44: {
45: return $this->crawl['name'];
46: }
47:
48: /**
49: * Get the Collection's poster
50: *
51: * @return string
52: */
53: public function getPoster()
54: {
55: return $this->crawl['poster_path'];
56: }
57:
58: /**
59: * Get the Collection's backdrop
60: *
61: * @return string
62: */
63: public function getBackdrop()
64: {
65: return $this->crawl['backdrop_path'];
66: }
67:
68: /**
69: * Get the Collection's movies
70: *
71: * @return Movie[]
72: */
73: public function getMovies()
74: {
75: $movies = [];
76:
77: foreach ($this->crawl['parts'] as $data) {
78: $movies[] = new Movie($data);
79: }
80:
81: return $movies;
82: }
83:
84: /**
85: * Get Generic.<br>
86: * Get a item of the array, you should not get used to use this, better use specific get's.
87: *
88: * @param string $item The item of the $data array you want
89: * @return array|mixed|null Returns the entire data array, a specific item, or null if the item does not exist.
90: */
91: public function get($item = '')
92: {
93: if (empty($item)) {
94: return $this->crawl;
95: }
96: if (array_key_exists($item, $this->crawl)) {
97: return $this->crawl[$item];
98: }
99: return null;
100: }
101:
102: /**
103: * Get the JSON representation of the Collection
104: *
105: * @return string
106: */
107: public function getJSON()
108: {
109: return json_encode($this->crawl, JSON_PRETTY_PRINT);
110: }
111: }