From 8ca62082650303c9a7e181919f3d6fd69098b54c Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 3 Apr 2017 16:26:09 +0200 Subject: Added a default config for rooms that have not saved a config yet. --- modules-available/locationinfo/api.inc.php | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'modules-available/locationinfo/api.inc.php') diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index 319dc3a5..f3b99e45 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -297,20 +297,43 @@ function getConfig($locationID) WHERE l.locationid=:locationID", array('locationID' => $locationID)); $config = array(); - $config = json_decode($dbresult['config'], true); - $config['room'] = $dbresult['locationname']; - $date = getdate(); - $config['time'] = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'] . " " . $date['hours'] . ":" . $date['minutes'] . ":" . $date['seconds']; + if ($dbresult['locationname'] == null) { + $config = array(); + } else { - if ($dbresult['servertype'] === "Frontend") { - $config['calendarqueryurl'] = $dbresult['serverurl'] . "/" . $dbresult['serverroomid'] . ".json"; - } + if ($dbresult['config'] == null) { + defaultConfig($config); + } else { + $config = json_decode($dbresult['config'], true); + } - if (empty($config)) { - echo json_encode(array()); - } else { - echo json_encode($config, JSON_UNESCAPED_SLASHES); + $config['room'] = $dbresult['locationname']; + $date = getdate(); + $config['time'] = $date['year'] . "-" . $date['mon'] . "-" . $date['mday'] . " " . $date['hours'] . ":" . $date['minutes'] . ":" . $date['seconds']; } + echo json_encode($config, true); +} + +/** + * Creates and returns a default config for room that didn't saved a config yet. + * + * @return Return a default config. + */ +function defaultConfig(&$config) { + $config['language'] = 'en'; + $config['mode'] = 1; + $config['vertical'] = false; + $config['eco'] = false; + $config['scaledaysauto'] = true; + $config['daystoshow'] = 7; + $config['rotation'] = 0; + $config['scale'] = 50; + $config['switchtime'] = 20; + $config['calupdate'] = 30; + $config['roomupdate'] = 5; + $config['configupdate'] = 180; + + return $config; } /** -- cgit v1.2.3-55-g7522