From d311bddd350fde9c35d8a04351accee9d6e0af1d Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sat, 28 Jan 2017 23:18:18 -0800 Subject: API: Adde a method for multi handle ids and a method for returning the room tree. --- modules-available/locationinfo/api.inc.php | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (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 ddbd1304..296354c4 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -21,9 +21,54 @@ function HandleParameters() { } elseif ($getAction == "calendar") { $getRoomID = Request::get('id', 0, 'int'); getCalendar($getRoomID); + } elseif ($getAction == "roomtree") { + $roomIDS = Request::get('ids', 0, 'string'); + getRoomTree($roomIDS); } } +function getMultipleInformations($roomids) { + $idList = explode(',', $roomids); + $filteredIdList = array_filter($idList, 'is_numeric'); + return $filteredIdList; +} + +function getRoomTree($ids) { + $idList = getMultipleInformations($ids); + $roomTree = array(); + foreach ($idList as $id) { + $dbquery = Database::simpleQuery("SELECT locationname FROM `location` WHERE locationid=:locationID", array('locationID' => $id)); + $dbresult=$dbquery->fetch(PDO::FETCH_ASSOC); + + $a['id'] = $id; + $a['name'] = $dbresult['locationname']; + $a['childs'] = getChildsRecursive($id); + $roomTree[] = $a; + } + + echo json_encode($roomTree); +} + +function getChildsRecursive($id) { + $dbquery = Database::simpleQuery("SELECT locationid, locationname FROM `location` WHERE parentlocationid=:locationID", array('locationID' => $id)); + $array = array(); + $dbarray = array(); + + while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) { + $dbarray[] = $dbresult; + } + + foreach ($dbarray as $db) { + $i = $db['locationid']; + $a['id'] = $i; + $a['name'] = $db['locationname']; + $a['childs'] = getChildsRecursive($i); + $array[] = $a; + } + + return $array; +} + function randomCalendarGenerator() { $randNum = rand(3, 7); -- cgit v1.2.3-55-g7522