improved view components
added first draft of csv output view
This commit is contained in:
parent
0fd8726a50
commit
5d394c1ccc
7 changed files with 39 additions and 9 deletions
|
@ -19,11 +19,34 @@
|
|||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
namespace Volkszaehler\View\Json;
|
||||
namespace Volkszaehler\View\Csv;
|
||||
|
||||
class Data extends \Volkszaehler\View\Json {
|
||||
public function add($data) {
|
||||
$this->json['data'][] = $data;
|
||||
class Csv extends \Volkszaehler\View\View {
|
||||
|
||||
/*
|
||||
* constructor
|
||||
*/
|
||||
public function __construct(Http\Request $request, Http\Response $response) {
|
||||
parent::__construct($request, $response);
|
||||
|
||||
$this->csv['source'] = 'volkszaehler.org';
|
||||
$this->csv['version'] = \Volkszaehler\VERSION;
|
||||
|
||||
$this->response->setHeader('Content-type', 'text/csv');
|
||||
}
|
||||
|
||||
public function render() {
|
||||
parent::render();
|
||||
|
||||
// TODO implement
|
||||
}
|
||||
|
||||
public function addDebug() {
|
||||
// TODO implement debug output for csv view
|
||||
}
|
||||
|
||||
public function addException(\Exception $exception) {
|
||||
// TODO implement exception output for csv view
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,10 @@ class JpGraph extends View {
|
|||
//$this->graph->img->SetAntiAliasing();
|
||||
}
|
||||
|
||||
public function add($data) {
|
||||
/*
|
||||
* @todo add title unit etc..
|
||||
*/
|
||||
public function add(\Volkszaehler\Model\Channel $obj, $data = NULL) {
|
||||
$xData = $yData = array();
|
||||
foreach ($data as $reading) {
|
||||
$xData[] = $reading['timestamp']/1000;
|
||||
|
|
|
@ -21,17 +21,17 @@
|
|||
|
||||
namespace Volkszaehler\View\Json;
|
||||
|
||||
class Channel extends \Volkszaehler\View\Json {
|
||||
class Channel extends Json {
|
||||
|
||||
public function add(\Volkszaehler\Model\Channel\Channel $obj, $data = NULL) {
|
||||
public function add(\Volkszaehler\Model\Channel $obj, $data = NULL) {
|
||||
$channel['id'] = (int) $obj->getId();
|
||||
$channel['uuid'] = (string) $obj->getUuid();
|
||||
$channel['type'] = strtolower(substr(strrchr(get_class($obj), '\\'), 1));
|
||||
$channel['indicator'] = $obj->getIndicator();
|
||||
$channel['unit'] = $obj->getUnit();
|
||||
$channel['name'] = $obj->getName();
|
||||
$channel['description'] = $obj->getDescription();
|
||||
|
||||
// TODO adapt to new indicator style
|
||||
if (is_subclass_of($obj, '\Volkszaehler\Model\Channel\Meter')) {
|
||||
$channel['resolution'] = (int) $obj->getResolution();
|
||||
$channel['cost'] = (float) $obj->getCost();
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
namespace Volkszaehler\View\Json;
|
||||
|
||||
class Group extends \Volkszaehler\View\Json {
|
||||
class Group extends Json {
|
||||
|
||||
public function add(\Volkszaehler\Model\Group $obj, $recursive = false) {
|
||||
$group['id'] = (int) $obj->getId();
|
||||
|
|
|
@ -46,6 +46,7 @@ abstract class View implements ViewInterface {
|
|||
|
||||
/*
|
||||
* creates new view instance depending on the requested format
|
||||
* @todo improve mapping
|
||||
*/
|
||||
public static function factory(Http\Request $request, Http\Response $response) {
|
||||
$format = strtolower($request->getParameter('format'));
|
||||
|
@ -55,6 +56,9 @@ abstract class View implements ViewInterface {
|
|||
$view = new JpGraph($request, $response, $format);
|
||||
}
|
||||
else {
|
||||
if ($controller == 'data' && $format == 'json') {
|
||||
$controller = 'channel';
|
||||
}
|
||||
$viewClassName = 'Volkszaehler\View\\' . ucfirst($format) . '\\' . ucfirst($controller);
|
||||
|
||||
if (!(\Volkszaehler\Util\ClassLoader::classExists($viewClassName)) || !is_subclass_of($viewClassName, '\Volkszaehler\View\View')) {
|
||||
|
|
Loading…
Add table
Reference in a new issue