From 9b121b58a98ac1f19ec67a1707b7e9a0fa6607b9 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 23 Nov 2016 11:27:36 -0800 Subject: Api openingtime is now returning the parent times if the current has no own times. Api action=config now returns the value from the database. New colum has to be added. --- modules-available/locationinfo/api.inc.php | 44 ++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 8 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 2b3a4ca2..464ca2df 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -15,6 +15,22 @@ function HandleParameters() { } elseif ($getAction == "openingtime") { $getRoomID = Request::get('id', 0, 'int'); getOpeningTimes($getRoomID); + } elseif ($getAction == "config") { + $getRoomID = Request::get('id', 0, 'int'); + getConfig($getRoomID); + } +} + +function getConfig($locationID) { + $dbquery = Database::simpleQuery("SELECT config FROM `location_info` WHERE locationid = :locationID", array('locationID' => $locationID)); + $config = array(); + while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $config = json_decode($dbresult['config'], true); + } + if (empty($config)) { + echo json_encode(array()); + } else { + echo json_encode($config); } } @@ -31,6 +47,18 @@ function checkIfHidden($locationID) { } } +function getOpeningTimesFromParent($locationID) { + $dbquery = Database::simpleQuery("SELECT parentlocationid FROM `location` WHERE locationid = :locationID", array('locationID' => $locationID)); + while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $parentlocationid = $dbdata['parentlocationid']; + } + if ($parentlocationid == 0) { + echo json_encode(array()); + }else { + echo getOpeningTimes($parentlocationid); + } +} + function getOpeningTimes($locationID) { $error = checkIfHidden($locationID); if ($error == true) { @@ -44,6 +72,11 @@ function getOpeningTimes($locationID) { $dbresult = json_decode($dbdata['openingtime'], true); } + if (count($dbresult) == 0) { + getOpeningTimesFromParent($locationID); + return; + } + $weekarray = array ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); foreach ($weekarray as $d) { @@ -57,15 +90,10 @@ function getOpeningTimes($locationID) { $arr['HourOpen'] = $openTime[0]; $arr['MinutesOpen'] = $openTime[1]; - //$arr['HourOpen'] = $day['openingtime'][0] . $day['openingtime'][1]; - //$arr['MinutesOpen'] = $day['openingtime'][3] . $day['openingtime'][4]; $closeTime = explode(':', $day['closingtime']); $arr['HourClose'] = $closeTime[0]; $arr['MinutesClose'] = $closeTime[1]; - //$arr['HourClose'] = $day['closingtime'][0] . $day['closingtime'][1]; - //$arr['MinutesClose'] = $day['closingtime'][3] . $day['closingtime'][4]; - $array[] = $arr; } } @@ -87,7 +115,7 @@ function getRoomInfoJson($locationID, $coords) { $error = true; } - if ($error === false) { + if ($error == false) { echo $pcs; } else { echo "ERROR"; @@ -97,7 +125,7 @@ function getRoomInfoJson($locationID, $coords) { function getPcInfos($locationID, $coords) { $dbquery; - if ($coords === '1') { + if ($coords == '1') { $dbquery = Database::simpleQuery("SELECT machineuuid, position, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID)); } else { $dbquery = Database::simpleQuery("SELECT machineuuid, logintime FROM `machine` WHERE locationid = :locationID" , array('locationID' => $locationID)); @@ -111,7 +139,7 @@ function getPcInfos($locationID, $coords) { $computer['id'] = $pc['machineuuid']; - if ($coords === '1') { + if ($coords == '1') { $position = json_decode($pc['position'], true); $computer['x'] = $position['gridRow']; $computer['y'] = $position['gridCol']; -- cgit v1.2.3-55-g7522