From f59aa6c0e4a11bebeb8cb99674e3d1ef9088abb3 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 28 Jul 2010 00:42:28 +0200 Subject: [PATCH] fixed a lot bugs in views --- backend/lib/View/CSV.php | 11 +++++------ backend/lib/View/JSON.php | 11 +++++------ backend/lib/View/JpGraph.php | 5 +++-- backend/lib/View/View.php | 3 ++- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/lib/View/CSV.php b/backend/lib/View/CSV.php index 865633a..7c8d867 100644 --- a/backend/lib/View/CSV.php +++ b/backend/lib/View/CSV.php @@ -37,6 +37,8 @@ class CSV extends View { protected $delimiter = ';'; protected $enclosure = '"'; + protected $csv = array(); + /** * constructor */ @@ -68,12 +70,9 @@ class CSV extends View { public function renderResponse() { // channel data - foreach ($this->channels as $channel) { - foreach ($channel[1] as $reading) { - $array = array_map(array($this, 'escape'), ); - - echo implode($this->delimiter, $array) . PHP_EOL; - } + foreach ($this->csv as $row) { + $array = array_map(array($this, 'escape'), $row); + echo implode($this->delimiter, $row) . PHP_EOL; } echo PHP_EOL; diff --git a/backend/lib/View/JSON.php b/backend/lib/View/JSON.php index 4cf90d3..26713db 100644 --- a/backend/lib/View/JSON.php +++ b/backend/lib/View/JSON.php @@ -50,12 +50,15 @@ class JSON extends View { $this->json['version'] = \Volkszaehler\VERSION; $this->response->setHeader('Content-type', 'application/json'); + + $this->padding = $this->request->getParameter('padding'); } public function setPadding($padding) { $this->padding = $padding; } public function addChannel(Model\Channel $channel, array $data = NULL) { $jsonChannel['uuid'] = (string) $channel->getUuid(); + $jsonChannel['type'] = $channel->getType(); $jsonChannel['indicator'] = $channel->getIndicator(); $jsonChannel['unit'] = $channel->getUnit(); $jsonChannel['name'] = $channel->getName(); @@ -64,11 +67,7 @@ class JSON extends View { $jsonChannel['cost'] = (float) $channel->getCost(); if (isset($data)) { - $jsonChannel['data'] = array(); - - foreach ($data as $reading) { - $jsonChannel['data'][] = array($reading['timestamp'], $reading['value'], $reading['count']); - } + $jsonChannel['data'] = $data; } $this->json['channels'][] = $jsonChannel; @@ -131,7 +130,7 @@ class JSON extends View { } if ($this->padding) { - $json = $this->padding . '(' . $json . ')'; + $json = 'if (self.' . $this->padding . ') { ' . $this->padding . '(' . $json . '); }'; } echo $json; diff --git a/backend/lib/View/JpGraph.php b/backend/lib/View/JpGraph.php index 5127ab7..0e5e28e 100644 --- a/backend/lib/View/JpGraph.php +++ b/backend/lib/View/JpGraph.php @@ -96,9 +96,10 @@ class JpGraph extends View { public function addChannel(Model\Channel $channel, array $data = NULL){ $count = count($this->channels); $xData = $yData = array(); + foreach ($data as $reading) { - $xData[] = $reading['timestamp']/1000; - $yData[] = $reading['value']; + $xData[] = $reading[0] / 1000; + $yData[] = $reading[1]; } // Create the scatter plot diff --git a/backend/lib/View/View.php b/backend/lib/View/View.php index 246d235..efe6e4e 100644 --- a/backend/lib/View/View.php +++ b/backend/lib/View/View.php @@ -72,7 +72,8 @@ abstract class View implements ViewInterface { $code = ($exception->getCode() == 0 && HTTP\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode(); $this->response->setCode($code); - $this->renderResponse(); + echo $exception; + //$this->sendResponse(); die(); }