1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LiveStream\Resources; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
use LiveStream\Resources\Resource; |
7
|
|
|
use LiveStream\Interfaces\Resource as ResourceInterface; |
8
|
|
|
|
9
|
|
|
class Event extends Resource implements ResourceInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Class Constructor. |
13
|
|
|
* |
14
|
|
|
* @param string $fullName |
15
|
|
|
* @param boolean $init |
16
|
|
|
*/ |
17
|
|
|
public function __construct(string $fullName, bool $init = true) |
18
|
|
|
{ |
19
|
|
|
parent::__construct($init); |
20
|
|
|
if ($init) |
21
|
|
|
$this->data->fullName = $fullName; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Set Event Start Time. |
26
|
|
|
* |
27
|
|
|
* @param string $strtime |
28
|
|
|
* @return \LiveStream\Resources\Event |
29
|
|
|
*/ |
30
|
|
|
public function setStartTime(string $strtime): Event |
31
|
|
|
{ |
32
|
|
|
$this->data->startTime = date('c', strtotime($strtime)); |
33
|
|
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Set End Time |
38
|
|
|
* |
39
|
|
|
* @param string $strtime |
40
|
|
|
* @return \LiveStream\Resources\Event |
41
|
|
|
*/ |
42
|
|
|
public function setEndTime(string $strtime): Event |
43
|
|
|
{ |
44
|
|
|
$this->data->endTime = date('c', strtotime($strtime)); |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Set Is Draft. |
50
|
|
|
* |
51
|
|
|
* @param boolean $isDraft |
52
|
|
|
* |
53
|
|
|
* @return \LiveStream\Resources\Event |
54
|
|
|
*/ |
55
|
|
|
public function setIsDraft(bool $isDraft = true): Event |
56
|
|
|
{ |
57
|
|
|
$this->data->draft = $isDraft; |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get Is Draft. |
63
|
|
|
* |
64
|
|
|
* @return boolean |
65
|
|
|
*/ |
66
|
|
|
public function isDraft(): bool |
67
|
|
|
{ |
68
|
|
|
return $this->data->draft ?? true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Add Event Tag |
73
|
|
|
* |
74
|
|
|
* @param string $tag |
75
|
|
|
* @return \LiveStream\Resources\Event |
76
|
|
|
*/ |
77
|
|
|
public function addTag(string $tag): Event |
78
|
|
|
{ |
79
|
|
|
if (!isset($this->data->tags)) $this->data->tags = ''; |
80
|
|
|
|
81
|
|
|
$this->data->tags .= rtrim($tag, ',') . ','; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get Tags. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getTags() |
92
|
|
|
{ |
93
|
|
|
return $this->data->tags ?? ''; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Undocumented function |
98
|
|
|
* |
99
|
|
|
* @param string $name |
100
|
|
|
* @param array $arguments |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
public function __call(string $name, array $arguments) |
104
|
|
|
{ |
105
|
|
|
switch ($name) { |
106
|
|
|
case 'getDraft': |
107
|
|
|
return $this->isDraft(); |
|
|
|
|
108
|
|
|
case 'setDraft': |
109
|
|
|
return $this->setIsDraft($arguments[0]); |
|
|
|
|
110
|
|
|
default: |
111
|
|
|
return parent::__call($name, $arguments); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Resource Interface Method: Get Resource as JSON String. |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getResourceBody(): string |
121
|
|
|
{ |
122
|
|
|
$body = ['fullName' => $this->data->fullName]; |
123
|
|
|
|
124
|
|
|
$this->set_fields($body, [ |
125
|
|
|
'shortName' => $this->data->shortName ?? null, |
126
|
|
|
'startTime' => $this->data->startTime ?? null, |
127
|
|
|
'endTime' => $this->data->endTime ?? null, |
128
|
|
|
'draft' => $this->data->draft ?? null, |
129
|
|
|
'description' => $this->data->description ?? null, |
130
|
|
|
'tags' => ($this->data->tags ?? null) ? rtrim($this->data->tags, ',') : null, |
131
|
|
|
'isPublic' => $this->data->isPublic ?? null, |
132
|
|
|
'isSearchable' => $this->data->isSearchable ?? null, |
133
|
|
|
'viewerCountVisible' => $this->data->viewerCountVisible ?? null, |
134
|
|
|
'postCommentsEnabled' => $this->data->postCommentsEnabled ?? null, |
135
|
|
|
'liveChatEnabled' => $this->data->liveChatEnabled ?? null, |
136
|
|
|
'isEmbeddable' => $this->data->isEmbeddable ?? null, |
137
|
|
|
'isPasswordProtected' => $this->data->isPasswordProtected ?? null, |
138
|
|
|
'password' => $this->data->password ?? null, |
139
|
|
|
'isWhiteLabeled' => $this->data->isWhiteLabeled ?? null, |
140
|
|
|
'embedRestriction' => $this->data->embedRestriction ?? null, |
141
|
|
|
'embedRestrictionWhitelist' => $this->data->embedRestrictionWhitelist ?? null, |
142
|
|
|
'embedRestrictionBlacklist' => $this->data->embedRestrictionBlacklist ?? null, |
143
|
|
|
]); |
144
|
|
|
|
145
|
|
|
return json_encode($body); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Undocumented function |
150
|
|
|
* |
151
|
|
|
* @param array $array |
152
|
|
|
* @param array $map |
153
|
|
|
* @return void |
154
|
|
|
*/ |
155
|
|
|
private function set_fields(array &$array, array $map): void |
156
|
|
|
{ |
157
|
|
|
foreach ($map as $key => $value) { |
158
|
|
|
if ($value) |
159
|
|
|
$array[$key] = $value; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Undocumented function |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getContentType(): string |
169
|
|
|
{ |
170
|
|
|
return 'application/json'; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|