added casts and validation to get parameters
This commit is contained in:
parent
d78996c673
commit
eafaf99341
4 changed files with 7 additions and 4 deletions
|
@ -32,7 +32,7 @@ class DataController extends Controller {
|
|||
|
||||
$from = (isset($this->view->request->get['from'])) ? (int) $this->view->request->get['from'] : NULL;
|
||||
$to = (isset($this->view->request->get['to'])) ? (int) $this->view->request->get['to'] : NULL;
|
||||
$groupBy = (isset($this->view->request->get['groupBy'])) ? $this->view->request->get['groupBy'] : 400; // get all readings by default
|
||||
$groupBy = (isset($this->view->request->get['groupBy'])) ? $this->view->request->get['groupBy'] : NULL; // get all readings by default
|
||||
|
||||
foreach ($channels as $channel) {
|
||||
$this->view->addChannel($channel, $channel->getPulses($from, $to, $groupBy));
|
||||
|
|
|
@ -88,6 +88,9 @@ abstract class Channel extends DatabaseObject implements ChannelInterface {
|
|||
break;
|
||||
|
||||
default:
|
||||
if (is_numeric($groupBy)) {
|
||||
$groupBy = (int) $groupBy;
|
||||
}
|
||||
$sqlGroupBy = false;
|
||||
}
|
||||
|
||||
|
@ -116,7 +119,7 @@ abstract class Channel extends DatabaseObject implements ChannelInterface {
|
|||
$reading = $result->rewind();
|
||||
for ($i = 1; $i <= $packageCount; $i++) {
|
||||
$package = array('timestamp' => $reading['timestamp'], // last timestamp in package
|
||||
'value' => $reading['value'], // sum of values
|
||||
'value' => (float) $reading['value'], // sum of values
|
||||
'count' => ($sqlGroupBy === false) ? 1 : $reading['count']); // total count of values or pulses in the package
|
||||
|
||||
while ($package['count'] < $packageSize) {
|
||||
|
|
|
@ -60,7 +60,7 @@ class JsonView extends View {
|
|||
$channel['unit'] = $obj->unit;
|
||||
$channel['description'] = $obj->description;
|
||||
$channel['resolution'] = (int) $obj->resolution;
|
||||
$channel['costs'] = $obj->cost;
|
||||
$channel['costs'] = (float) $obj->cost;
|
||||
|
||||
// TODO check for optional data in second param
|
||||
if (!is_null($data) && is_array($data)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ include '../../backend/init.php';
|
|||
|
||||
$meter = current(Channel::getByFilter(array('id' => 1)));
|
||||
|
||||
$data = $meter->getData(0, time()*1000);
|
||||
$data = $meter->getPulses(1270062000000, 1270666800000, 400);
|
||||
|
||||
echo '<table border="1">';
|
||||
foreach ($data as $i => $reading) {
|
||||
|
|
Loading…
Add table
Reference in a new issue