1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LiveStream\Resources; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
use LiveStream\Interfaces\Resource; |
7
|
|
|
|
8
|
|
|
class Event implements Resource |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Resource Payload. |
12
|
|
|
* |
13
|
|
|
* @var object |
14
|
|
|
*/ |
15
|
|
|
private $data; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Constructor. |
19
|
|
|
* |
20
|
|
|
* @param string $fullName |
21
|
|
|
* @param boolean $init |
22
|
|
|
*/ |
23
|
|
|
public function __construct(string $fullName, bool $init = true) |
24
|
|
|
{ |
25
|
|
|
if ($init) { |
26
|
|
|
$this->data = new stdClass(); |
27
|
|
|
$this->data->fullName = $fullName; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Factory Method. |
33
|
|
|
* |
34
|
|
|
* @param object $object |
35
|
|
|
* @return \LiveStream\Resources\Event|null |
36
|
|
|
*/ |
37
|
|
|
public static function fromObject(?object $object): ?Event |
38
|
|
|
{ |
39
|
|
|
if ($object == null) return null; |
40
|
|
|
|
41
|
|
|
$instance = new static(false); |
|
|
|
|
42
|
|
|
$instance->data = $object; |
43
|
|
|
return $instance; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Magic Setter Method |
48
|
|
|
* |
49
|
|
|
* @param string $key |
50
|
|
|
* @param mixed $value |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function __set(string $key, $value): void |
54
|
|
|
{ |
55
|
|
|
$this->data->$key = $value; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Magic Getter Method |
60
|
|
|
* |
61
|
|
|
* @param string $key |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function __get(string $key) |
65
|
|
|
{ |
66
|
|
|
return $this->data->$key ?? null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Magic Method Isset. |
71
|
|
|
* |
72
|
|
|
* @param string $key |
73
|
|
|
* @return boolean |
74
|
|
|
*/ |
75
|
|
|
public function __isset(string $key) |
76
|
|
|
{ |
77
|
|
|
return isset($this->data->$key); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set Full Name. |
82
|
|
|
* |
83
|
|
|
* @param string $fullName |
84
|
|
|
* @return \LiveStream\Resources\Event |
85
|
|
|
*/ |
86
|
|
|
public function setFullName(string $fullName): Event |
87
|
|
|
{ |
88
|
|
|
$this->data->fullName = $fullName; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get Full Name. |
94
|
|
|
* |
95
|
|
|
* @return string|null |
96
|
|
|
*/ |
97
|
|
|
public function getFullName(): ?string |
98
|
|
|
{ |
99
|
|
|
return $this->data->fullName ?? null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Set Event Start Time. |
104
|
|
|
* |
105
|
|
|
* @param string $strtime |
106
|
|
|
* @return \LiveStream\Resources\Event |
107
|
|
|
*/ |
108
|
|
|
public function setStartTime(string $strtime): Event |
109
|
|
|
{ |
110
|
|
|
$this->data->startTime = date('c', strtotime($strtime)); |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get Start Time |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getStartTime(): ?string |
120
|
|
|
{ |
121
|
|
|
return $this->data->startTime ?? null; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Set End Time |
126
|
|
|
* |
127
|
|
|
* @param string $strtime |
128
|
|
|
* @return \LiveStream\Resources\Event |
129
|
|
|
*/ |
130
|
|
|
public function setEndTime(string $strtime): Event |
131
|
|
|
{ |
132
|
|
|
$this->data->endTime = date('c', strtotime($strtime)); |
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get End Time. |
138
|
|
|
* |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getEndTime(): ?string |
142
|
|
|
{ |
143
|
|
|
return $this->data->endTime ?? null; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set Is Draft. |
148
|
|
|
* |
149
|
|
|
* @param boolean $isDraft |
150
|
|
|
* |
151
|
|
|
* @return \LiveStream\Resources\Event |
152
|
|
|
*/ |
153
|
|
|
public function setIsDraft(bool $isDraft = true): Event |
154
|
|
|
{ |
155
|
|
|
$this->data->draft = $isDraft; |
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get Is Draft. |
161
|
|
|
* |
162
|
|
|
* @return boolean |
163
|
|
|
*/ |
164
|
|
|
public function isDraft(): bool |
165
|
|
|
{ |
166
|
|
|
return $this->data->draft ?? true; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Set Event Short Name. |
171
|
|
|
* |
172
|
|
|
* @param string $shortName |
173
|
|
|
* @return Event |
174
|
|
|
*/ |
175
|
|
|
public function setShortName(string $shortName): Event |
176
|
|
|
{ |
177
|
|
|
$this->data->shortName = $shortName; |
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get Event Short Name. |
183
|
|
|
* |
184
|
|
|
* @return string|null |
185
|
|
|
*/ |
186
|
|
|
public function getShortName(): ?string |
187
|
|
|
{ |
188
|
|
|
return $this->data->shortName ?? null; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set Event Description |
193
|
|
|
* |
194
|
|
|
* @param string $description |
195
|
|
|
* @return Event |
196
|
|
|
*/ |
197
|
|
|
public function setDescription(string $description): Event |
198
|
|
|
{ |
199
|
|
|
$this->data->description = $description; |
200
|
|
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Get Description. |
205
|
|
|
* |
206
|
|
|
* @return string|null |
207
|
|
|
*/ |
208
|
|
|
public function getDescription(): ?string |
209
|
|
|
{ |
210
|
|
|
return $this->data->description ?? null; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Add Event Tag |
215
|
|
|
* |
216
|
|
|
* @param string $tag |
217
|
|
|
* @return \LiveStream\Resources\Event |
218
|
|
|
*/ |
219
|
|
|
public function addTag(string $tag): Event |
220
|
|
|
{ |
221
|
|
|
if (!isset($this->data->tags)) $this->data->tags = ''; |
222
|
|
|
|
223
|
|
|
$this->data->tags .= rtrim($tag, ',') . ','; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Get Tags. |
230
|
|
|
* |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getTags(): string |
234
|
|
|
{ |
235
|
|
|
return $this->data->tags ?? ''; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Resource Interface Method: Get Resource as FormURLEncoded String. |
240
|
|
|
* |
241
|
|
|
* @return string |
242
|
|
|
*/ |
243
|
|
|
public function getRawBody(): string |
244
|
|
|
{ |
245
|
|
|
$body = ['fullName' => $this->data->fullName]; |
246
|
|
|
|
247
|
|
|
if ($this->data->shortName ?? null) |
248
|
|
|
$body['shortName'] = $this->data->shortName; |
249
|
|
|
|
250
|
|
|
if ($this->data->startTime ?? null) |
251
|
|
|
$body['startTime'] = $this->data->startTime; |
252
|
|
|
|
253
|
|
|
if ($this->data->endTime ?? null) |
254
|
|
|
$body['endTime'] = $this->data->endTime; |
255
|
|
|
|
256
|
|
|
if ($this->data->draft ?? null) |
257
|
|
|
$body['draft'] = $this->data->draft; |
258
|
|
|
|
259
|
|
|
if ($this->data->description ?? null) |
260
|
|
|
$body['description'] = $this->data->description; |
261
|
|
|
|
262
|
|
|
if ($this->data->tags ?? null) |
263
|
|
|
$body['tags'] = rtrim($this->data->tags, ','); |
264
|
|
|
|
265
|
|
|
/* TODO: Getters & Setters */ |
266
|
|
|
if ($this->data->isPublic ?? null) $body['isPublic'] = $this->data->isPublic; |
267
|
|
|
if ($this->data->isSearchable ?? null) $body['isSearchable'] = $this->data->isSearchable; |
268
|
|
|
if ($this->data->viewerCountVisible ?? null) $body['viewerCountVisible'] = $this->data->viewerCountVisible; |
269
|
|
|
if ($this->data->postCommentsEnabled ?? null) $body['postCommentsEnabled'] = $this->data->postCommentsEnabled; |
270
|
|
|
if ($this->data->liveChatEnabled ?? null) $body['liveChatEnabled'] = $this->data->liveChatEnabled; |
271
|
|
|
if ($this->data->isEmbeddable ?? null) $body['isEmbeddable'] = $this->data->isEmbeddable; |
272
|
|
|
if ($this->data->isPasswordProtected ?? null) $body['isPasswordProtected'] = $this->data->isPasswordProtected; |
273
|
|
|
if ($this->data->password ?? null) $body['password'] = $this->data->password; |
274
|
|
|
if ($this->data->isWhiteLabeled ?? null) $body['isWhiteLabeled'] = $this->data->isWhiteLabeled; |
275
|
|
|
if ($this->data->embedRestriction ?? null && in_array($this->data->embedRestriction, ['off', 'whitelist', 'blacklist'])) $body['embedRestriction'] = $this->data->embedRestriction; |
276
|
|
|
if ($this->data->embedRestrictionWhitelist ?? null) $body['embedRestrictionWhitelist'] = $this->data->embedRestrictionWhitelist; |
277
|
|
|
if ($this->data->embedRestrictionBlacklist ?? null) $body['embedRestrictionBlacklist'] = $this->data->embedRestrictionBlacklist; |
278
|
|
|
|
279
|
|
|
return json_encode($body); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Undocumented function |
284
|
|
|
* |
285
|
|
|
* @return string |
286
|
|
|
*/ |
287
|
|
|
public function getContentType(): string |
288
|
|
|
{ |
289
|
|
|
return 'application/json'; |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|