forked from munkireport/power
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower_controller.php
executable file
·74 lines (69 loc) · 1.94 KB
/
power_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* power status module class
*
* @package munkireport
* @author
**/
class Power_controller extends Module_controller
{
/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
}
/**
* Default method
*
* @author AvB
**/
public function index()
{
echo "You've loaded the power module!";
}
/**
* Retrieve data in json format
*
**/
public function get_data($serial_number = '')
{
$obj = new View();
$power = new Power_model($serial_number);
$temp_format = conf('temperature_unit');
$power->rs['temp_format'] = $temp_format; // Add the temp format for use in the client tab's JavaScript
$obj->view('json', array('msg' => $power->rs));
}
/**
* Get Power Statistics
*
*
**/
public function get_stats()
{
$obj = new View();
$pm = new Power_model;
$out[] = $pm->get_stats();
$obj->view('json', array('msg' => $out));
}
/**
* Get conditions
*
* @return void
* @author AvB
**/
public function conditions()
{
$obj = new View();
$queryobj = new Power_model();
$sql = "SELECT COUNT(CASE WHEN `condition` = 'Normal' OR `condition` = 'Good' THEN 1 END) AS good,
COUNT(CASE WHEN `condition` = 'Check Battery' OR `condition` = 'Service Battery' THEN 1 END) AS service,
COUNT(CASE WHEN `condition` = 'Fair' THEN 1 END) AS fair,
COUNT(CASE WHEN `condition` = 'Poor' THEN 1 END) AS poor,
COUNT(CASE WHEN `condition` = 'No Battery' OR `condition` = 'NoBattery' THEN 1 END) AS missing
FROM power
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
} // END class Power_controller