config json: fix mappings and default values

This commit is contained in:
Andreas Hubel 2022-12-25 02:52:58 +01:00
parent 6fc8b204b2
commit ad005b8c50
5 changed files with 63 additions and 41 deletions

View file

@ -150,7 +150,7 @@
"definitions": {
"Room": {
"type": "object",
"description": "Liste der Räume (= Audio & Video Produktionen, also auch DJ-Sets o.ä.)",
"description": "Liste der Räume/Streams/Channels (= Audio & Video Produktionen, also auch DJ-Sets o.ä.)",
"additionalProperties": false,
"properties": {
"name": {
@ -166,7 +166,7 @@
"$ref": "#/definitions/RoomStreamingConfig"
}
},
"required": ["streamId", "name", "slug", "streamingConfig"]
"required": ["streamId", "name", "slug"]
},
"Features": {
"type": "object",
@ -208,7 +208,8 @@
"type": "boolean"
},
"matrix": {
"type": "boolean"
"$ref": "#/definitions/IrcConfig",
"type": ["object", "boolean"]
},
"irc": {
"$ref": "#/definitions/IrcConfig",
@ -238,7 +239,7 @@
"title": "Konfigurationen",
"description": "",
"default": {},
"required": ["features", "overviewPage"],
"required": ["features"],
"properties": {
"schedule": {
"type": "object",
@ -356,8 +357,8 @@
},
"wide": {
"type": "boolean",
"title": "16:9",
"description": "",
"title": "Breiter Teaser",
"description": "Doppelte Breite für die Teaserbox auf der Übersichtsseite",
"default": true
},
"preview": {
@ -474,21 +475,21 @@
}
}
},
"ChatConfig": {
"ChatConfig":{
"type": "object",
"additionalProperties": false,
"properties": {
"irc": {
"matrix": {
"$ref": "#/definitions/IrcConfig"
},
"twitter": {
"irc": {
"$ref": "#/definitions/IrcConfig"
},
"mastodon":{
"$ref": "#/definitions/SocialMediaConfig"
},
"matrix": {
"twitter": {
"$ref": "#/definitions/SocialMediaConfig"
}
}
},
@ -507,8 +508,8 @@
},
"required": ["display", "url"]
},
"TwitterConfig": {
"title": "Twitter",
"SocialMediaConfig": {
"title": "SocialMedia",
"type": "object",
"additionalProperties": false,
"properties": {

View file

@ -15,12 +15,13 @@ class ConferenceJson extends Conference
$this->html = @$c->streamingConfig->html ?: [];
$this->rooms = [];
$rooms = property_exists($c->rooms, 'nodes') ? @$c->rooms->nodes : $c->rooms;
$rooms = is_array(@$c->rooms) ? $c->rooms : @$c->rooms->nodes;
foreach($rooms as $r) {
if (!$r) {
continue;
}
$this->rooms[$r->slug] = array_merge(
['stream' => $r->streamId],
get_object_vars($r),
@get_object_vars($r->streamingConfig) ?: [],
@get_object_vars($r->streamingConfig->chat) ?: []
@ -37,25 +38,23 @@ class ConferenceJson extends Conference
}
}
else {
$groups['Live'] = array_keys((array) $rooms);
$groups['Live'] = array_keys((array) $this->rooms);
}
parent::__construct([
'conference' => array_merge([
parent::__construct(array_merge(@get_object_vars($c->streamingConfig) ?: [], [
'conference' => [
'title' => $c->title,
'author' => $c->organizer,
'description' => $c->description,
'keywords' => @implode(', ', $c->keywords),
],
@get_object_vars($c->streamingConfig) ?: []),
// 'schedule' => (array) $c->streamingConfig->schedule
'rooms' => $this->rooms,
'overview' => [
'groups' => $groups
]
], $mandator ?: $c->acronym);
]), $mandator ?: $c->acronym);
}
public function has($keychain)
@ -143,21 +142,21 @@ class ConferenceJson extends Conference
}
public function hasBannerHtml() {
return array_key_exists('banner', $this->html) && !empty($this->html->banner);
return !empty($this->html->banner);
}
public function getBannerHtml() {
return @$this->html->banner;
}
public function hasFooterHtml() {
return array_key_exists('footer', $this->html) && !empty($this->html->footer);
return !empty($this->html->footer);
}
public function getFooterHtml() {
return @$this->html->footer;
}
public function hasNotStartedHtml() {
return array_key_exists('not_started', $this->html);
return !empty($this->html->not_started);
}
public function getNotStartedHtml() {
return @$this->html->not_started;

View file

@ -13,19 +13,20 @@ class ModelJson
return ModelJson::_has($this->config, $keychain);
}
public static function _has($array, $keychain)
public static function _has($model, $keychain)
{
if(!is_array($keychain))
$keychain = explode('.', $keychain);
$key = strtolower($keychain[0]);
if(!isset($array[$key]))
if(is_array($model) ? !isset($model[$key]) : !isset($model->$key))
return false;
if(count($keychain) == 1)
return true;
return ModelJson::_has($array[$key], array_slice($keychain, 1));
$value = is_array($model) ? $model[$key] : $model->$key;
return ModelJson::_has($value, array_slice($keychain, 1));
}
public function get($keychain, $default = null)
@ -33,18 +34,19 @@ class ModelJson
return ModelJson::_get($this->config, $keychain, $default);
}
public static function _get($array, $keychain, $default)
public static function _get($model, $keychain, $default)
{
if(!is_array($keychain))
$keychain = explode('.', $keychain);
$key = strtolower($keychain[0]);
if(!isset($array[$key]))
if (is_array($model) ? !isset($model[$key]) : !isset($model->$key))
return $default;
$value = is_array($model) ? $model[$key] : $model->$key;
if(count($keychain) == 1)
return $array[$key];
return $value;
return ModelJson::_get($array[$key], array_slice($keychain, 1), $default);
return ModelJson::_get($value, array_slice($keychain, 1), $default);
}
}

View file

@ -73,7 +73,7 @@ class Room
}
public function getScheduleName() {
return $this->get('SCHEDULE_NAME', $this->getDisplay());
return $this->get('SCHEDULE_NAME') ?: $this->get('name') ?: $this->getDisplay();
}
public function getDisplay() {
@ -99,7 +99,7 @@ class Room
}
public function hasPreview() {
return $this->get('PREVIEW');
return $this->get('PREVIEW', true);
}
public function requestsWide() {
@ -107,7 +107,7 @@ class Room
}
public function hasSchedule() {
return $this->get('SCHEDULE') && $this->getConference()->has('SCHEDULE');
return $this->get('SCHEDULE', true) && $this->getConference()->has('SCHEDULE');
}
public function hasSubtitles() {
@ -218,7 +218,7 @@ class Room
}
public function hasDash() {
return $this->get('DASH');
return $this->get('DASH', true);
}
public function getHLSPlaylistUrl() {
@ -234,7 +234,7 @@ class Room
}
public function getTranslations() {
return $this->get('TRANSLATION');
return $this->get('TRANSLATION') ?: [];
}
private function getTranslationEndpoints() {

View file

@ -26,7 +26,7 @@ function formatConference($conference) {
),
'schedule' => lowerCaseKeys($conference->get('SCHEDULE')),
'overviewPage' => array(
'sections' => formatSections($conference->get('OVERVIEW.GROUPS')),
'sections' => formatSections($conference->get('OVERVIEW.GROUPS', [])),
),
'html' => array(
'banner' => $conference->getBannerHtml(),
@ -45,9 +45,23 @@ function formatRooms($conference) {
foreach($conference->getRooms() as $room) {
$config = $conference->get('ROOMS.'.$room->getSlug());
// cleanup nested config from config.json input
unset($config['streamingConfig']);
unset($config['stream']);
unset($config['streamId']);
unset($config['guid']);
unset($config['name']);
unset($config['slug']);
foreach ($config['chat'] as $k => $v) {
unset($config[$k]);
}
$struct[] = array(
'name' => $room->getDisplay(),
'guid' => $room->getId(),
'slug' => $room->getSlug(),
'name' => $room->get('name') ?: $room->getScheduleName(),
'stream' => $room->getStream(),
'streamingConfig' => $config ? lowerCaseKeys($config) : null,
);
@ -81,6 +95,12 @@ function lowerCaseKeys($config)
if (empty($config)) {
return null;
}
// if config is an object, the keys are already in the proper format
if (is_object($config)) {
return (array) $config;
}
return array_map(function($item) {
return is_array($item) ? lowerCaseKeys($item) : $item;
}, array_change_key_case($config));