From 1548ff96932dd61184b5b2d6ee8d15c73dc689c7 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 6 Mar 2017 22:07:22 +0100 Subject: API: getRoomTree recursive childs are now filtered out if the id is a duplicate. Frontendpanel: Some url fixes due to reworked api. --- modules-available/locationinfo/api.inc.php | 37 ++++++++++++++-------- modules-available/locationinfo/frontend/panel.html | 8 ++--- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index 0c4a1b67..ab940663 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -25,7 +25,7 @@ function HandleParameters() { $array = getMultipleInformations($roomIDs); echo getPcStates($array); } elseif ($getAction == "roomtree") { - $roomIDS = Request::get('ids', 0, 'string'); + $roomIDS = Request::get('id', 0, 'string'); getRoomTree($roomIDS); } elseif ($getAction == "calendar") { $roomIDs = Request::get('id', 0, 'string'); @@ -196,7 +196,7 @@ function getPcStates($idList) { $roominfoList = json_decode(getRoomInfo($idList), true); foreach ($roominfoList as $roomInfo) { - $result['id'] = $id; + $result['id'] = $roomInfo['id']; $idle = 0; $occupied = 0; $off = 0; @@ -225,20 +225,25 @@ function getPcStates($idList) { function getRoomTree($ids) { $idList = getMultipleInformations($ids); + $idList = array_unique($idList); $roomTree = array(); + $filteredIdList = array(); foreach ($idList as $id) { $dbresult = Database::queryFirst("SELECT locationname FROM `location` WHERE locationid=:locationID", array('locationID' => $id)); - $a['id'] = $id; - $a['name'] = $dbresult['locationname']; - $a['childs'] = getChildsRecursive($id); - $roomTree[] = $a; + if (!in_array($id, $filteredIdList)) { + $a['id'] = $id; + $a['name'] = $dbresult['locationname']; + $filteredIdList[] = $id; + $a['childs'] = getChildsRecursive($id, $filteredIdList); + $roomTree[] = $a; + } } - // TODO FIlter recursive childs (delete doubles) (Filteere froeach when recursive child exists) + echo json_encode($roomTree); } -function getChildsRecursive($id) { +function getChildsRecursive($id, &$filteredIdList) { $dbquery = Database::simpleQuery("SELECT locationid, locationname FROM `location` WHERE parentlocationid=:locationID", array('locationID' => $id)); $array = array(); $dbarray = array(); @@ -246,13 +251,17 @@ function getChildsRecursive($id) { 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; + + if (!in_array($i, $filteredIdList)) { + $a['id'] = $i; + $a['name'] = $db['locationname']; + $filteredIdList[] = $i; + $a['childs'] = getChildsRecursive($i, $filteredIdList); + $array[] = $a; + } + } return $array; @@ -329,7 +338,7 @@ function getRoomInfo($idList, $coords) { $pc['id'] = $dbdata['machineuuid']; // Add coordinates if bool = true. - if ($coords == '1') { + if ($coords == '1' || $coords == 'true') { $position = json_decode($dbdata['position'], true); $pc['x'] = $position['gridCol']; $pc['y'] = $position['gridRow']; diff --git a/modules-available/locationinfo/frontend/panel.html b/modules-available/locationinfo/frontend/panel.html index d899ffd2..61df4f12 100644 --- a/modules-available/locationinfo/frontend/panel.html +++ b/modules-available/locationinfo/frontend/panel.html @@ -101,7 +101,7 @@ function init() { var ids = getUrlParameter("id"); - $.getJSON("../../../api.php?do=locationinfo&action=roomtree&ids=" + ids, function (result) { + $.getJSON("../../../api.php?do=locationinfo&action=roomtree&id=" + ids, function (result) { generateLayout(result); setInterval(update,1000); @@ -161,13 +161,13 @@ function update() { if(lastPcUpdate ==null || (new MyDate().getTime()-lastPcUpdate.getTime()) > pcStateUpdateTime*1000){ - $.getJSON("../../../api.php?do=locationinfo&action=pcstates&ids=" + roomidsString, function (result) { + $.getJSON("../../../api.php?do=locationinfo&action=pcstates&id=" + roomidsString, function (result) { updatePcStates(result); lastPcUpdate = new MyDate(); }); } if(lastTimeTableUpdate ==null || (new MyDate().getTime()-lastTimeTableUpdate.getTime()) > TimeTableUpdateTime*1000){ - $.getJSON("../../../api.php?do=locationinfo&action=calendars&ids=" + roomidsString, function (result) { + $.getJSON("../../../api.php?do=locationinfo&action=calendars&id=" + roomidsString, function (result) { UpdateTimeTables(result); lastTimeTableUpdate = new MyDate(); }); @@ -217,7 +217,7 @@ } } - + function updatePcStates(json){ var l = json.length; -- cgit v1.2.3-55-g7522