|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Tmdb package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Vincent Faliès <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Vincent Faliès <[email protected]> |
|
11
|
|
|
* @copyright Copyright (c) 2017-2021 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace VfacTmdb\Results; |
|
15
|
|
|
|
|
16
|
|
|
use VfacTmdb\Abstracts\Results; |
|
17
|
|
|
use VfacTmdb\Interfaces\TmdbInterface; |
|
18
|
|
|
use VfacTmdb\Interfaces\Results\ItemChangeResultsInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class to manipulate an ItemChange result |
|
22
|
|
|
* @package Tmdb |
|
23
|
|
|
* @author Steve Richter <[email protected]> |
|
24
|
|
|
* @copyright Copyright (c) 2021 |
|
25
|
|
|
*/ |
|
26
|
|
|
class ItemChange extends Results implements ItemChangeResultsInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Id |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $id; |
|
33
|
|
|
/** |
|
34
|
|
|
* Key |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $key; |
|
38
|
|
|
/** |
|
39
|
|
|
* Action |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $action; |
|
43
|
|
|
/** |
|
44
|
|
|
* Time |
|
45
|
|
|
* @var \DateTime |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $time; |
|
48
|
|
|
/** |
|
49
|
|
|
* iso_639_1 |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $iso_639_1 = null; |
|
53
|
|
|
/** |
|
54
|
|
|
* iso_3166_1 |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $iso_3166_1 = null; |
|
58
|
|
|
/** |
|
59
|
|
|
* Value |
|
60
|
|
|
* @var array |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $value; |
|
63
|
|
|
/** |
|
64
|
|
|
* Original value |
|
65
|
|
|
* @var array |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $original_value = null; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Constructor |
|
71
|
|
|
* @param TmdbInterface $tmdb |
|
72
|
|
|
* @param \stdClass $result |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __construct(TmdbInterface $tmdb, \stdClass $result) |
|
75
|
|
|
{ |
|
76
|
|
|
$result = $this->initResultObject($result); |
|
77
|
|
|
|
|
78
|
|
|
parent::__construct($tmdb, $result); |
|
79
|
|
|
|
|
80
|
|
|
// Populate data |
|
81
|
|
|
$this->id = $this->data->id; |
|
82
|
|
|
$this->key = $this->data->key; |
|
83
|
|
|
$this->action = $this->data->action; |
|
84
|
|
|
$this->time = $this->data->time; |
|
85
|
|
|
$this->iso_639_1 = $this->data->iso_639_1; |
|
86
|
|
|
$this->iso_3166_1 = $this->data->iso_3166_1; |
|
87
|
|
|
$this->value = $this->data->value; |
|
88
|
|
|
$this->original_value = $this->data->original_value; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* initResultObject |
|
93
|
|
|
* @param \stdClass $result |
|
94
|
|
|
* @return \stdClass |
|
95
|
|
|
*/ |
|
96
|
|
|
private function initResultObject(\stdClass $result) : \stdClass |
|
97
|
|
|
{ |
|
98
|
|
|
if (!isset($result->original_value)) { |
|
99
|
|
|
$result->original_value = null; |
|
100
|
|
|
} |
|
101
|
|
|
if (!isset($result->value)) { |
|
102
|
|
|
$result->value = []; |
|
103
|
|
|
} |
|
104
|
|
|
if (is_object($result->value)) { |
|
105
|
|
|
$result->value = get_object_vars($result->value); |
|
106
|
|
|
} |
|
107
|
|
|
if (!is_array($result->value)) { |
|
108
|
|
|
$result->value = [$result->value]; |
|
109
|
|
|
} |
|
110
|
|
|
return $result; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get Id |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getId() : string |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->id; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get key |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getKey() : string |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->key; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Get action |
|
133
|
|
|
* @return string |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getAction() : string |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->action; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get time |
|
142
|
|
|
* @return \DateTime |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getTime() : \DateTime |
|
145
|
|
|
{ |
|
146
|
|
|
return \DateTime::createFromFormat('Y-m-d H:i:s e', $this->time); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Get iso_639_1 |
|
151
|
|
|
* |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getIso_639_1() : string |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->iso_639_1; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get iso_3166_1 |
|
161
|
|
|
* |
|
162
|
|
|
* @return string |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getIso_3166_1() : string |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->iso_3166_1; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get value |
|
171
|
|
|
* |
|
172
|
|
|
* @return array |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getValue() : array |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->value; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Get original value |
|
181
|
|
|
* |
|
182
|
|
|
* @return array|null |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getOriginalValue() : ?array |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->original_value; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Get value by key |
|
191
|
|
|
* @param string $key |
|
192
|
|
|
* @return mixed |
|
193
|
|
|
*/ |
|
194
|
|
|
public function getValueByKey($key) |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->value[$key] ?? null; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|