summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/api.inc.php
diff options
context:
space:
mode:
authorJannik Schönartz2017-03-09 11:52:45 +0100
committerJannik Schönartz2017-03-09 11:52:45 +0100
commit0973537ed133104daa7a7bdc11abe4244dae1552 (patch)
treed79654f2e4f5e1510585a7636be9cadfc409d9f0 /modules-available/locationinfo/api.inc.php
parentLocationinfo: Admin-panel auto size cell for the Credentials button. In the G... (diff)
downloadslx-admin-0973537ed133104daa7a7bdc11abe4244dae1552.tar.gz
slx-admin-0973537ed133104daa7a7bdc11abe4244dae1552.tar.xz
slx-admin-0973537ed133104daa7a7bdc11abe4244dae1552.zip
API: Reworked getRoomInfo with isset and added overlay if coords = true
Diffstat (limited to 'modules-available/locationinfo/api.inc.php')
-rw-r--r--modules-available/locationinfo/api.inc.php29
1 files changed, 12 insertions, 17 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index 96685cab..575b04f4 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -299,11 +299,11 @@ function getRoomInfo($idList, $coords) {
// Build SQL Query for multiple ids.
$query = "SELECT m.locationid, machineuuid, position, logintime, lastseen, lastboot FROM `machine` as m LEFT JOIN location_info AS l ON l.locationid = m.locationid WHERE l.hidden = 0 AND m.locationid IN (";
- //$query = "SELECT locationid, machineuuid, position, logintime, lastseen, lastboot FROM `machine` WHERE locationid IN (";
$query .= implode(",", $idList);
$query .= ")";
$query .= " ORDER BY m.locationid ASC";
+
// Execute query.
$dbquery = Database::simpleQuery($query);
$dbresult = array();
@@ -311,36 +311,31 @@ function getRoomInfo($idList, $coords) {
$currentlocationid = 0;
$pclist = array();
+
+ // Fetch db data.
while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) {
- // Add the data in the array if locationid changed
- if ($dbdata['locationid'] != $currentlocationid && $currentlocationid != 0) {
- $data['id'] = $currentlocationid;
- $data['computer'] = $pclist;
- $dbresult[] = $data;
- $pclist = array();
+ // Set the id if the locationid changed.
+ if (!isset($dbresult[$dbdata['locationid']])) {
+ $dbresult[$dbdata['locationid']] = array('id' => $dbdata['locationid'], 'computer' => array());
}
+ // Compact the pc data in one array.
$pc['id'] = $dbdata['machineuuid'];
-
- // Add coordinates if bool = true.
if ($coordinates == '1' || $coordinates == 'true') {
$position = json_decode($dbdata['position'], true);
$pc['x'] = $position['gridCol'];
$pc['y'] = $position['gridRow'];
+ $pc['overlay'] = $position['overlays'];
}
-
$pc['pcState'] = LocationInfo::getPcState($dbdata);
- $pclist[] = $pc;
- // Save the last entry to add this at the end.
- $lastentry['id'] = $dbdata['locationid'];
- $lastentry['computer'] = $pclist;
- $currentlocationid = $dbdata['locationid'];
+ // Add the array to the computer list.
+ $dbresult[$dbdata['locationid']]['computer'][] = $pc;
}
- $dbresult[] = $lastentry;
- return json_encode($dbresult, true);
+ // The array keys are only used for the isset -> Return only the values.
+ return json_encode(array_values($dbresult), true);
}
// ########## </Roominfo> ###########