fixed a lot bugs in views
This commit is contained in:
parent
b14f0a6966
commit
f59aa6c0e4
4 changed files with 15 additions and 15 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue