-
Notifications
You must be signed in to change notification settings - Fork 109
/
ConferenceJson.php
196 lines (165 loc) · 5.17 KB
/
ConferenceJson.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
class ConferenceJson extends Conference
{
private $start;
private $end;
private $rooms;
private $streamingConfig;
private $html;
public function __construct($json, $mandator)
{
$c = $json->conference;
$this->start = isset($c->start) ? DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->start) : null;
$this->end = isset($c->end) ? DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->end) : null;
$this->html = isset($c->streamingConfig->html) ? $c->streamingConfig->html : [];
$this->streamingConfig = $c->streamingConfig;
$this->rooms = [];
$acronym = isset($c->acronym) ? $c->acronym : $mandator;
if (isset($c->rooms)) {
if (is_array($c->rooms)) {
$rooms = $c->rooms;
} else {
$rooms = isset($c->rooms->nodes) ? $c->rooms->nodes : [];
}
}
foreach($rooms as $r) {
if (!$r) {
continue;
}
$streamId = isset($r->streamId) ? $r->streamId : $r->slug;
$this->rooms[$r->slug] = array_merge(
['stream' => $streamId],
get_object_vars($r),
(isset($r->streamingConfig) ? get_object_vars($r->streamingConfig) : []),
(isset($r->streamingConfig->chat) ? get_object_vars($r->streamingConfig->chat) : [])
);
}
$groups = [];
if ( isset($c->streamingConfig->overviewPage->sections) ) {
foreach($c->streamingConfig->overviewPage->sections as $s) {
$groups[$s->title] = array_map(
function($r) { return $r->slug; },
@$s->items ?: @$s->rooms ?: []
);
}
}
else {
$groups['Live'] = array_keys((array) $this->rooms);
}
$media_slug = isset($c->media_slug) ? $c->media_slug : $acronym;
$relive = [];
if (isset($c->streamingConfig->features->relive) && $c->streamingConfig->features->relive) {
// TODO make configurable
$relive = [
"relive_json" => "https://cdn.c3voc.de/relive/".$acronym."/index.json"
];
}
$config = array_merge(
isset($c->streamingConfig) ? get_object_vars($c->streamingConfig) : [],
isset($c->streamingConfig->features) ? get_object_vars($c->streamingConfig->features) : [],
isset($c->streamingConfig->features->chat) ? get_object_vars($c->streamingConfig->features->chat) : [],
['embed' => isset($c->streamingConfig->features->embed) ? $c->streamingConfig->features->embed : true],
[
'conference' => array_merge(
$relive,
[
'title' => $c->title,
'author' => $c->organizer,
'description' => $c->description,
'keywords' => isset($c->keywords) ? (is_array($c->keywords) ? implode(', ', $c->keywords) : "") : "",
"releases" => "https://media.ccc.de/c/".$media_slug,
],
),
'schedule' => isset($c->streamingConfig->schedule) ? (array)$c->streamingConfig->schedule : [],
'rooms' => $this->rooms,
'overview' => [
'groups' => $groups
]
]
);
// disable relive button
if (isset($c->streamingConfig->features->relive) && $c->streamingConfig->features->relive === false) {
$config['conference']['relive_json'] = null;
}
// disable releases button
if (isset($c->streamingConfig->features->releases) && $c->streamingConfig->features->releases === false) {
$config['conference']['releases'] = null;
}
parent::__construct($config, $mandator);
}
public function has($keychain)
{
return ModelJson::_has($this->config, $keychain);
}
public function get($keychain, $default = null)
{
return ModelJson::_get($this->config, $keychain, $default);
}
public function startsAt() {
return $this->start;
}
public function endsAt() {
return $this->end;
}
public function hasBegun() {
// on the preview-domain all conferences are always open
if($this->isPreviewEnabled() || empty($this->start))
return true;
$now = new DateTime('now');
return $now >= $this->start;
}
public function hasEnded() {
// on the preview-domain no conference ever ends
if($this->isPreviewEnabled() || empty($this->end))
return false;
$now = new DateTime('now');
return $now >= $this->end;
}
public function isUnlisted() {
return empty($this->start) || empty($this->end);
}
public function getStreamingConfig() {
return $this->streamingConfig;
}
public function getRooms()
{
$rooms = array();
foreach($this->rooms as $slug => $room)
$rooms[] = $this->getRoom($slug);
return $rooms;
}
public function getRoomIfExists($room)
{
if($this->hasRoom($room))
return $this->getRoom($room);
return null;
}
public function hasRoom($slug)
{
return array_key_exists($slug, $this->rooms);
}
public function getRoom($slug) {
return new Room($this, $slug);
}
public function hasFeedback() {
return isset($this->streamingConfig->features->feedback) ? $this->streamingConfig->features->feedback : false;
}
public function hasBannerHtml() {
return !empty($this->html->banner);
}
public function getBannerHtml() {
return isset($this->html->banner) ? $this->html->banner : "";
}
public function hasFooterHtml() {
return !empty($this->html->footer);
}
public function getFooterHtml() {
return isset($this->html->footer) ? $this->html->footer : "";
}
public function hasNotStartedHtml() {
return !empty($this->html->not_started);
}
public function getNotStartedHtml() {
return isset($this->html->not_started) ? $this->html->not_started : "";
}
}