Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit 9b5fc34

Browse files
committed
fix(graph): update online stats to use query criteria
Signed-off-by: Domingo Oropeza <[email protected]>
1 parent 03d0737 commit 9b5fc34

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

inc/graph.class.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,34 @@ public function showAgentOnlineStats() {
245245
INNER JOIN " . $FlyvemdmAgent . " AS f ON l.`items_id` = f.`id`
246246
WHERE l.`itemtype`='PluginFlyvemdmAgent' AND l.`id_search_option`='8'
247247
ORDER BY agent_id ASC, online_date ASC";
248-
$result = $DB->query($query);
249-
if ($result && $DB->numrows($result) > 0) {
250-
$currentId = $currentDate = null;
251-
while ($row = $DB->fetch_assoc($result)) {
252-
list($date, $time) = explode(' ', $row['online_date']);
253-
//$domain[] = $date;
254-
//$serie[] = strtotime($time);
255-
if ($currentId != $row['agent_id']) {
256-
$currentId = $row['agent_id'];
257-
$range[$currentId]['name'] = $row['agent_name'] . ' (ID:' . $currentId . ')';
258-
$range[$currentId]['data'] = [];
259-
}
260-
$jsTime = strtotime($row['online_date']) * 1000;
261-
$range[$currentId]['data'][] = "{x:$jsTime, y:$jsTime}";
248+
$request = [
249+
'FIELDS' => [$logTable => ['new_value'], $FlyvemdmAgent => ['id', 'name']],
250+
'FROM' => $logTable,
251+
'INNER JOIN' => [
252+
$FlyvemdmAgent => [
253+
'FKEY' => [
254+
$FlyvemdmAgent => 'id',
255+
$logTable => 'items_id',
256+
],
257+
],
258+
],
259+
'WHERE' => ['itemtype' => 'PluginFlyvemdmAgent', 'id_search_option' => 8],
260+
'ORDER' => ['id ASC', 'new_value ASC'],
261+
];
262+
$currentId = $currentDate = null;
263+
foreach ($DB->request($request) as $data) {
264+
list($date, $time) = explode(' ', $data['new_value']);
265+
//$domain[] = $date;
266+
//$serie[] = strtotime($time);
267+
if ($currentId != $data['id']) {
268+
$currentId = $data['id'];
269+
$range[$currentId]['name'] = $data['name'] . ' (ID:' . $currentId . ')';
270+
$range[$currentId]['data'] = [];
262271
}
263-
//$domain = array_unique($domain);
272+
$jsTime = strtotime($data['new_value']) * 1000;
273+
$range[$currentId]['data'][] = "{x:$jsTime, y:$jsTime}";
264274
}
275+
//$domain = array_unique($domain);
265276

266277
$out = $this->displayLineGraph(
267278
__('Online Agents', 'flyvemdm'),

0 commit comments

Comments
 (0)