added phpdocs everywhere

renamed acronyms to uppercase
some cleanup &refactoring
This commit is contained in:
Steffen Vogel 2010-07-21 12:44:01 +02:00
parent 7c4288f92a
commit b1a17a044f
36 changed files with 1187 additions and 746 deletions

View file

@ -1,4 +1,27 @@
<?php
/**
* doctrine cli configuration and bootstrapping
*
* @author Steffen Vogel <info@steffenvogel.de>
* @package doctrine
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
// TODO replace by state class
const BACKEND_DIR = '/home/steffen/workspace/volkszaehler.org/backend';

View file

@ -1,22 +1,25 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* backend bootstrapping entrypoint
*
* @author Steffen Vogel <info@steffenvogel.de>
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler;

View file

@ -1,28 +1,35 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Controller;
use \Volkszaehler\Model;
/**
* channel controller
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
class Channel extends Controller {
// TODO authentification/indentification
@ -49,7 +56,11 @@ class Channel extends Controller {
}
}
// TODO validate input and throw exceptions
/**
* add channel
*
* @todo validate input and throw exceptions
*/
public function add() {
$channel = new Model\Channel\Meter($this->view->request->getParameter('indicator'));
@ -65,7 +76,11 @@ class Channel extends Controller {
$this->view->add($channel);
}
// TODO authentification/indentification
/**
* delete channel
*
* @todo authentification/indentification
*/
public function delete() {
$ucid = $this->view->request->getParameter('ucid');
$channel = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findOneBy(array('uuid' => $ucid));
@ -74,8 +89,12 @@ class Channel extends Controller {
$this->em->flush();
}
// TODO implement Controller\Channel::edit();
// TODO authentification/indentification
/**
* edit channel properties
*
* @todo authentification/indentification
* @todo to be implemented
*/
public function edit() {
}

View file

@ -1,31 +1,37 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Controller;
/**
* controller superclass for all controllers
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
abstract class Controller {
protected $view;
protected $em;
/*
/**
* constructor
*/
public function __construct(\Volkszaehler\View\View $view, \Doctrine\ORM\EntityManager $em) {

View file

@ -1,32 +1,40 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package data
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Controller;
// TODO call via redirect from Controller\Channel
use Volkszaehler\Util;
/**
* data controller
*
* @author Steffen Vogel <info@steffenvogel.de>
* @todo call via redirect from Controller\Channel
*/
class Data extends Controller {
// TODO authentification/indentification
/**
* @todo authentification/indentification
*/
public function get() {
// TODO use uuids for groups or channels
$ids = explode(',', trim($this->view->request->getParameter('ids')));
@ -44,6 +52,9 @@ class Data extends Controller {
}
}
/**
*
*/
public function add() {
$ucid = $this->view->request->getParameter('ucid');
$channel = $this->em->getRepository('Volkszaehler\Model\Channel\Channel')->findOneBy(array('uuid' => $ucid));
@ -62,10 +73,11 @@ class Data extends Controller {
$this->em->flush();
}
/*
/**
* prune data from database
*
* @todo authentification/indentification
*/
// TODO authentification/indentification
public function delete() {
$dql = 'DELETE FROM \Volkszaehler\Model\Data WHERE channel_id = ' . $this->id;

View file

@ -1,27 +1,38 @@
chann<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
<?php
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package group
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Controller;
/**
* group controller
*
* @author Steffen Vogel (info@steffenvogel.de)
*
*/
class Group extends Controller {
/**
*
*/
public function get() {
// TODO get groups from entitymanager according to API specs
@ -30,7 +41,9 @@ class Group extends Controller {
}
}
/**
*
*/
public function add() {
$group = new Group();
@ -43,7 +56,9 @@ class Group extends Controller {
$this->view->add($group);
}
// TODO authentification/indentification
/**
* @todo authentification/indentification
*/
public function delete() {
$group = Group::getByUuid($this->view->request->getParameter('ugid'));
@ -51,9 +66,14 @@ class Group extends Controller {
$this->em->flush();
}
/**
* edit group properties
*
* @todo implement Controller\Group::edit()
*/
public function edit() {
// TODO implement Controller\Group::edit();
}
}
}
?>

View file

@ -1,78 +1,105 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler;
use Volkszaehler\View\HTTP;
use Volkszaehler\View;
use Volkszaehler\Controller;
use Volkszaehler\Util;
/*
* frontcontroller / dispatcher
/**
* backend dispatcher
*
* this class acts as a frontcontroller to route incomming requests
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Dispatcher {
// MVC
protected $em; // Model (Doctrine EntityManager)
protected $view; // View
protected $controller; // Controller
protected $debug = NULL; // optional debugging instance
/*
/**
* @var EntityManager Doctrine Model
*/
protected $em;
/**
* @var View
*/
protected $view;
/**
* @var Controller
*/
protected $controller;
/**
* @var Debug optional debugging instance
*/
protected $debug = NULL;
/**
* constructor
*/
public function __construct() {
// create HTTP request & response (needed to initialize view & controller)
$request = new View\Http\Request();
$response = new View\Http\Response();
$request = new HTTP\Request();
$response = new HTTP\Response();
$format = ($request->getParameter('format')) ? $request->getParameter('format') : 'json'; // default action
$controller = $request->getParameter('controller');
// initialize entity manager
$this->em = Dispatcher::createEntityManager();
// staring debugging
if (($request->getParameter('debug') && $request->getParameter('debug') > 0) || Util\Configuration::read('debug')) {
$this->debug = new Util\Debug($request->getParameter('debug'));
$this->em->getConnection()->getConfiguration()->setSQLLogger($this->debug);
}
// initialize view
if (in_array($format, array('png', 'jpeg', 'gif'))) {
$this->view = new View\JpGraph($request, $response, $format);
}
else {
if ($controller == 'data' && ($format == 'json' || $format == 'xml')) {
switch ($format) {
case 'png':
case 'jpeg':
case 'gif':
$this->view = new View\JpGraph($request, $response, $format);
break;
case 'json':
case 'xml':
$controller = 'channel';
}
$viewClassName = 'Volkszaehler\View\\' . ucfirst($format) . '\\' . ucfirst($controller);
if (!(\Volkszaehler\Util\ClassLoader::classExists($viewClassName)) || !is_subclass_of($viewClassName, '\Volkszaehler\View\View')) {
throw new \InvalidArgumentException('\'' . $viewClassName . '\' is not a valid View');
}
$this->view = new $viewClassName($request, $response);
case 'csv':
$viewClassName = 'Volkszaehler\View\\' . strtoupper($format) . '\\' . ucfirst($controller);
if (!(\Volkszaehler\Util\ClassLoader::classExists($viewClassName)) || !is_subclass_of($viewClassName, '\Volkszaehler\View\View')) {
throw new \InvalidArgumentException('\'' . $viewClassName . '\' is not a valid View');
}
$this->view = new $viewClassName($request, $response);
break;
default:
throw new \Exception('unknown format: ' . $format);
break;
}
// initialize controller
$controllerClassName = 'Volkszaehler\Controller\\' . ucfirst(strtolower($request->getParameter('controller')));
if (!(\Volkszaehler\Util\ClassLoader::classExists($controllerClassName)) || !is_subclass_of($controllerClassName, '\Volkszaehler\Controller\Controller')) {
@ -80,43 +107,43 @@ class Dispatcher {
}
$this->controller = new $controllerClassName($this->view, $this->em);
}
/**
* execute application
*/
public function run() {
$action = ($this->view->request->getParameter('action')) ? 'get' : $this->view->request->getParameter('action'); // default action
$this->controller->run($action); // run controllers actions (usually CRUD: http://de.wikipedia.org/wiki/CRUD)
if (Util\Debug::isActivated()) {
$this->view->addDebug($this->debug);
}
$this->view->render(); // render view & send http response
}
/**
* factory for doctrines entitymanager
*
*
* @todo create extra singleton class?
*/
public static function createEntityManager() {
$config = new \Doctrine\ORM\Configuration;
if (extension_loaded('apc')) {
$cache = new \Doctrine\Common\Cache\ApcCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
}
$driverImpl = $config->newDefaultAnnotationDriver(BACKEND_DIR . '/lib/Model');
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(BACKEND_DIR . '/lib/Model/Proxies');
$config->setProxyNamespace('Volkszaehler\Model\Proxies');
$config->setAutoGenerateProxyClasses(DEV_ENV == TRUE);
return \Doctrine\ORM\EntityManager::create(Util\Configuration::read('db'), $config);
}
}

View file

@ -1,26 +1,31 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Interpreter;
/**
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
interface InterpreterInterface {
public function getValues($from = NULL, $to = NULL, $groupBy = NULL);
public function getMin($from = NULL, $to = NULL);
@ -28,18 +33,33 @@ interface InterpreterInterface {
public function getAverage($from = NULL, $to = NULL);
}
/**
* interpreter superclass for all interpreters
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
abstract class Interpreter implements InterpreterInterface {
protected $channel;
protected $em;
/*
* constructor
/**
*
* @param $channel
* @param $em
*/
public function __construct(\Volkszaehler\Model\Channel $channel, \Doctrine\ORM\EntityManager $em) {
$this->channel = $channel;
$this->em = $em;
}
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
* @param mixed $groupBy
* @todo split in two functions
*/
protected function getData($from = NULL, $to = NULL, $groupBy = NULL) {
$ts = 'FROM_UNIXTIME(timestamp/1000)'; // just for saving space
switch ($groupBy) {

View file

@ -1,28 +1,41 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Interpreter;
/**
* meter interpreter
*
* @author Steffen Vogel (info@steffenvogel.de)
*
*/
class Meter extends Interpreter {
/**
* calculates the consumption for interval speciefied by $from and $to
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getConsumption($from = NULL, $to = NULL) { // TODO untested
$sql = 'SELECT SUM(value) AS count
FROM data
@ -36,6 +49,11 @@ class Meter extends Interpreter {
return $result['count'] / $this->resolution / 1000; // returns Wh
}
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getMin($from = NULL, $to = NULL) {
$data = $this->getData($from, $to);
@ -48,6 +66,11 @@ class Meter extends Interpreter {
return $min;
}
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getMax($from = NULL, $to = NULL) {
$data = $this->getData($from, $to);
@ -60,20 +83,31 @@ class Meter extends Interpreter {
return $min;
}
// TODO calculate timeinterval if no params were given
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
* @todo calculate timeinterval if no params were given
*/
public function getAverage($from = NULL, $to = NULL) {
return $this->getConsumption($from, $to) / ($to - $from) / 1000; // return W
}
/*
/**
* just a passthru of raw data
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getPulses($from = NULL, $to = NULL, $groupBy = NULL) {
return parent::getData($from, $to, $groupBy);
}
/*
/**
* raw pulses to power conversion
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getValues($from = NULL, $to = NULL, $groupBy = NULL) {
$pulses = parent::getData($from, $to, $groupBy);

View file

@ -1,28 +1,39 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Interpreter;
/**
* sensor interpreter
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Sensor extends Interpreter {
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*/
public function getValues($from = NULL, $to = NULL, $groupBy = NULL) {
$data = parent::getData($from, $to, $groupBy);
@ -33,14 +44,35 @@ class Sensor extends Interpreter {
return $data;
}
public function getMin($from = NULL, $to = NULL) { // TODO untested
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*
* @todo untested
*/
public function getMin($from = NULL, $to = NULL) {
return $this->dbh->query('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($from, $to) . ' ORDER BY value ASC', 1)->current();
}
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*
* @todo untested
*/
public function getMax($from = NULL, $to = NULL) { // TODO untested
return $this->dbh->query('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($from, $to) . ' ORDER BY value DESC', 1)->current();
}
/**
*
* @param integer $from timestamp in ms since 1970
* @param integer $to timestamp in ms since 1970
*
* @todo untested
*/
public function getAverage($from = NULL, $to = NULL) { // TODO untested
return $this->dbh->query('SELECT AVG(value) AS value FROM data WHERE channel_id = ' . (int) $this->id . self::buildFilterTime($from, $to))->current();
}

View file

@ -1,26 +1,35 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Logger;
/**
* logger for the Flukso.net api
*
* @link http://www.flukso.net
* @link http://github.com/icarus75/flukso
* @author Steffen Vogel <info@steffenvogel.de>
* @todo to be implemented
*/
class Flukso implements Logger {
}

View file

@ -1,32 +1,38 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Logger;
/*
use Volkszaehler\View\HTTP;
/**
* interface for parsing diffrent logging APIs (google, flukso etc..)
*
* @author Steffen Vogel <info@steffenvogel.de>
* @todo to be implemented
*/
interface Logger {
public function __construct(\Volkszaehler\View\Http\Request $request);
public function __construct(HTTP\Request $request);
/**
* @return \Volkszaehler\Model\Data $data the parsed data
*/

View file

@ -1,22 +1,23 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Model;
@ -24,8 +25,10 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Channel class
* Channel entity
*
* @author Steffen Vogel <info@steffenvogel.de>
*
* @Entity
* @Table(name="channels")
*/
@ -50,7 +53,7 @@ class Channel extends Entity {
/** @Column(type="decimal", precision="5", scale="2") */
protected $cost;
/*
/**
* indicator => interpreter, unit mapping
*/
protected static $indicators = array(
@ -62,7 +65,7 @@ class Channel extends Entity {
'humidity' => array('sensor', '%')
);
/*
/**
* constructor
*/
public function __construct($indicator) {
@ -76,7 +79,7 @@ class Channel extends Entity {
$this->data = new ArrayCollection();
}
/*
/**
* add a new data to the database
* @todo move to Logger\Logger?
*/
@ -84,7 +87,7 @@ class Channel extends Entity {
$this->data->add($data);
}
/*
/**
* obtain channels data interpreter to calculate statistical information
*/
public function getInterpreter(\Doctrine\ORM\EntityManager $em) {
@ -95,7 +98,7 @@ class Channel extends Entity {
return new $interpreterClassName($this, $em);
}
/*
/**
* getter & setter
*/
public function getName() { return $this->name; }

View file

@ -1,22 +1,23 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package data
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Model;
@ -24,6 +25,10 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Data entity
*
* @author Steffen Vogel <info@steffenvogel.de>
*
* @Entity
* @Table(name="data")
*/
@ -55,7 +60,7 @@ class Data {
$this->timestamp = $timestamp;
}
/*
/**
* setter & getter
*/
public function getValue() { return $this->value; }

View file

@ -1,22 +1,22 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Model;
@ -24,7 +24,9 @@ namespace Volkszaehler\Model;
use Volkszaehler\Util;
/**
* Database Entity
* entity superclass for all models with database persistance
*
* @author Steffen Vogel <info@steffenvogel.de>
*
* @MappedSuperclass
*/
@ -43,7 +45,7 @@ abstract class Entity {
$this->uuid = Util\Uuid::mint();
}
/*
/**
* getter & setter
*/
public function getId() { return $this->id; } // read only

View file

@ -1,22 +1,23 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package group
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Model;
@ -24,7 +25,9 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Grouping class
* Group entity
*
* @author Steffen Vogel <info@steffenvogel.de>
*
* @Entity
* @Table(name="groups")
@ -54,7 +57,7 @@ class Group extends Entity {
*/
protected $children = NULL;
/*
/**
* construct
*/
public function __construct() {
@ -64,7 +67,7 @@ class Group extends Entity {
$this->children = new ArrayCollection();
}
/*
/**
* getter & setter
*/
public function getName() { return $this->name; }

View file

@ -1,28 +1,36 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package util
* @author Steffen Vogel <info@steffenvogel.de>
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
/*
* slightly modified from doctrine
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Util;
/**
* class loader for volkszaehler and vendor libraries
*
* namespace is mapped to the filesystem structure
*
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php Lesser GNU Public License
*/
class ClassLoader {
protected $fileExtension = '.php';
protected $namespace;
@ -105,7 +113,7 @@ class ClassLoader {
if ($this->namespace !== NULL && strpos($className, $this->namespace . $this->namespaceSeparator) !== 0) {
return FALSE;
}
$subNamespace = substr($className, strlen($this->namespace));
$parts = explode($this->namespaceSeparator, $subNamespace);
$path = implode(DIRECTORY_SEPARATOR, $parts);
@ -129,7 +137,7 @@ class ClassLoader {
$subNamespace = substr($className, strlen($this->namespace));
$parts = explode($this->namespaceSeparator, $subNamespace);
$path = implode(DIRECTORY_SEPARATOR, $parts);
return file_exists(($this->includePath !== NULL ? $this->includePath . DIRECTORY_SEPARATOR : '') . $path . $this->fileExtension);
}

View file

@ -1,50 +1,65 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package util
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Util;
/**
* static configuration class for loading and storing the configuration to the disk
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Configuration {
static protected $values = array();
/**
* @param string $var A string delimited by dots
* @param mixed $value A scalar value or array which should be set as the value for $var
*/
static public function write($var, $value) {
if (!is_scalar($value) && !is_array($value)) {
throw new \Exception('sry we can\'t store this datatype in the configuration');
}
$values =& self::$values;
$tree = explode('.', $var);
foreach ($tree as $part) {
$values =& $values[$part]; // TODO use array_merge_recursive()
}
$values = $value;
}
/**
*
* @param string $var A string delimited by dots
* @return mixed the configuration value
*/
static public function read($var = NULL) {
$tree = explode('.', $var);
if (is_null($var)) {
return self::$values;
}
$values = self::$values;
foreach ($tree as $part) {
$values = $values[$part];
@ -53,45 +68,62 @@ class Configuration {
return $values;
}
/**
*
* @param string $var A string delimited by dots
*/
static public function delete($var) {
$tree = explode('.', $var);
$values =& self::$values;
foreach ($tree as $part) {
$values =& $values[$part];
}
unset($values);
}
/*
* configuration file handling
/**
* loading configuration from fule
*
* @param string $filename A string pointing to a file on the filesystem
*/
static public function load($filename) {
$filename .= '.php';
if (!file_exists($filename)) {
throw new \Exception('configuration file not found: ' . $filename);
}
include $filename;
if (!isset($config)) {
throw new \Exception('no variable $config found in ' . $filename);
}
self::$values = $config;
}
/**
*
* @param string $filename A string pointing to a file on the filesystem
* @return boolean TRUE on success
*/
static public function store($filename) {
$filename .= '.php';
$delcaration = '';
foreach (self::$values as $key => $value) {
$export = var_export($value, TRUE);
$export = preg_replace('/=>\s+array/', '=> array', $export);
$export = str_replace(" ", "\t", $export);
$declaration .= '$config[\'' . $key . '\'] = ' . $export . ';' . PHP_EOL . PHP_EOL;
$declaration .= '$config[\'' . $key . '\'] = ' . $export . ';' . PHP_EOL . PHP_EOL;
}
$content = <<<EOT
<?php
/*
/**
* That's the volkszaehler.org configuration file.
* Please take care of the following rules:
* - you are allowed to edit it by your own

View file

@ -1,77 +1,95 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package util
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Util;
use Doctrine\DBAL\Logging;
/**
* static debugging class
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Debug implements Logging\SQLLogger {
protected static $instance = NULL;
protected $queries = array();
protected $messages = array();
protected $started; // holds timestamp of initialization, used later to return time of execution
/**
* @var float holds timestamp of initialization, used later to return time of execution
*/
protected $started;
/**
* @var integer the debug level
*/
protected $level;
/*
/**
* constructor
*
* @param integer $level the debug level
*/
public function __construct($level) {
// taking timestamp to stop execution time
$this->created = microtime(TRUE);
$this->level = $level;
if (isset(self::$instance)) {
throw new \Exception('debugging has already been started. please use the static functions!');
}
self::$instance = $this;
// assert options
assert_options(ASSERT_ACTIVE, TRUE);
assert_options(ASSERT_BAIL, FALSE);
assert_options(ASSERT_WARNING, FALSE);
assert_options(ASSERT_CALLBACK, array($this, 'assertHandler'));
}
/*
/**
* interface for doctrine's dbal sql logger
*/
function logSQL($sql, array $parameter = NULL) {
$query['sql'] = $sql;
if (isset($parameter) && !empty($parameter)) {
$query['parameters'] = $parameter;
}
$this->queries[] = $query;
*
* @param string $sql the sql query
* @param array $parameters optional parameters for prepared queries
*/
function logSQL($sql, array $parameters = NULL) {
$this->queries[] = array('sql' => $sql, 'parameters' => $parameters);
}
/*
* logs messages to the debug stack including file, lineno, args and a stacktrace
*
* @param string $message
* @param more parameters could be passed
*/
static public function log($message) {
if (isset(self::$instance)) {
$trace = debug_backtrace();
self::$instance->messages[] = array(
'message' => $message,
'file' => $trace[0]['file'],
@ -82,20 +100,28 @@ class Debug implements Logging\SQLLogger {
);
}
}
/*
/**
* simple assertion passthrough for future improvements
*
*
* @param string $code code to be evaluated
* @todo check how should be en/disabled (options etc..)
*/
public static function assert($code) {
assert($code);
return assert($code);
}
/**
* handles failed assertions
*
* @param string $file
* @param integer $line
* @param string $code code to be evaluated
*/
public function assertHandler($file, $line, $code) {
$trace = debug_backtrace();
$info = $trace[2];
$this->messages[] = array(
'message' => 'assertion failed: ' . $code,
'file' => $info['file'],
@ -104,11 +130,25 @@ class Debug implements Logging\SQLLogger {
'trace' => array_slice($trace, 2)
);
}
/**
* is debugging enabled?
*/
public static function isActivated() { return isset(self::$instance); }
/**
* @return float execution time
*/
public function getExecutionTime() { return round((microtime(TRUE) - $this->created), 5); }
/**
* @return 2 dimensional array with sql queries and parameters
*/
public function getQueries() { return $this->queries; }
/**
* @return 2 dimensional array with messages
*/
public function getMessages() { return $this->messages; }
}

View file

@ -1,6 +1,34 @@
<?php
/*
* Copyright (c) 2009 J. King
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\Util;
class Exception extends \Exception {}
/**
* DrUUID RFC4122 library for PHP5
*
* @author J. King
* @link http://jkingweb.ca/code/php/lib.uuid/
* @license Licensed under MIT license
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@ -23,19 +51,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DrUUID RFC4122 library for PHP5 by J. King (http://jkingweb.ca/)
* Licensed under MIT license
* See http://jkingweb.ca/code/php/lib.uuid/ for documentation
* Last revised 2010-02-15
*/
namespace Volkszaehler\Util;
class Exception extends \Exception {}
class Uuid {
class UUID {
const MD5 = 3;
const SHA1 = 5;
const clearVer = 15; // 00001111 Clears all bits of version byte with AND
@ -55,7 +71,7 @@ class Uuid {
const nsX500 = '6ba7b814-9dad-11d1-80b4-00c04fd430c8';
protected static $randomFunc = 'randomTwister';
protected static $randomSource = NULL;
//instance properties
protected $bytes;
protected $hex;
@ -66,8 +82,14 @@ class Uuid {
protected $node;
protected $time;
/**
* Create a new UUID based on provided data
*
* @param integer $ver
* @param string $node
* @param string $ns
*/
public static function mint($ver = 1, $node = NULL, $ns = NULL) {
/* Create a new UUID based on provided data. */
switch((int) $ver) {
case 1:
return new self(self::mintTime($node));
@ -85,19 +107,25 @@ class Uuid {
}
}
/**
* Import an existing UUID
*
* @param unkown_type $uuid
*/
public static function import($uuid) {
/* Import an existing UUID. */
return new self(self::makeBin($uuid, 16));
}
/**
* Compares the binary representations of two UUIDs.
* The comparison will return TRUE if they are bit-exact,
* or if neither is valid
*
* @param unknown_type $a
* @param unknown_type $b
*/
public static function compare($a, $b) {
/* Compares the binary representations of two UUIDs.
The comparison will return TRUE if they are bit-exact,
or if neither is valid. */
if (self::makeBin($a, 16)==self::makeBin($b, 16))
return TRUE;
else
return FALSE;
return (self::makeBin($a, 16) == self::makeBin($b, 16));
}
public function __toString() {
@ -152,9 +180,9 @@ class Uuid {
if (strlen($uuid) != 16) {
throw new Exception("Input must be a 128-bit integer.");
}
$this->bytes = $uuid;
// Optimize the most common use
$this->string =
bin2hex(substr($uuid,0,4))."-".

View file

@ -1,40 +1,49 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Csv;
namespace Volkszaehler\View\CSV;
use Volkszaehler\View\HTTP;
use Volkszaehler\View;
use Volkszaehler\Util;
abstract class Csv extends \Volkszaehler\View\View {
/*
* CSV view
*
* also used for data
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
abstract class CSV extends View\View {
protected $csv = array();
protected $header = array();
protected $footer = array();
protected $delimiter = ';';
protected $enclosure = '"';
/*
/**
* constructor
*/
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
public function __construct(HTTP\Request $request, HTTP\Response $response) {
parent::__construct($request, $response);
$this->header[] = 'source: volkszaehler.org';
@ -43,29 +52,29 @@ abstract class Csv extends \Volkszaehler\View\View {
$this->response->setHeader('Content-type', 'text/csv');
$this->response->setHeader('Content-Disposition', 'attachment; filename="data.csv"');
}
public function render() {
foreach ($this->header as $line) {
echo $line . PHP_EOL;
}
echo PHP_EOL;
foreach ($this->csv as $array) {
$array = array_map(array($this, 'escape'), $array);
echo implode($this->delimiter, $array) . PHP_EOL;
}
echo PHP_EOL;
foreach ($this->footer as $line) {
echo $line . PHP_EOL;
}
parent::render();
}
protected function escape($value) {
if (is_string($value)) {
return $this->enclosure . $value . $this->enclosure;
@ -77,21 +86,21 @@ abstract class Csv extends \Volkszaehler\View\View {
return (string) $value;
}
}
public function addDebug(Util\Debug $debug) {
$this->footer[] = 'time: ' . $debug->getExecutionTime();
$this->footer[] = 'database: ' . Util\Configuration::read('db.driver');
foreach ($debug->getMessages() as $message) {
$this->footer[] = 'message: ' . $message['message']; // TODO add more information
}
foreach ($debug->getQueries() as $query) {
$this->footer[] = 'query: ' . $query['sql'];
$this->footer[] = ' parameters: ' . implode(', ', $query['parameters']);
}
}
public function addException(\Exception $exception) {
echo $exception;
}

View file

@ -0,0 +1,33 @@
<?php
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package data
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\CSV;
/**
* CSV data view
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Data extends CSV {
public function add($obj, $data) {
$this->csv = array_merge($this->csv, $data);
}
}

View file

@ -1,28 +0,0 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\View\Csv;
class Data extends Csv {
public function add($obj, $data) {
$this->csv = array_merge($this->csv, $data);
}
}

View file

@ -1,60 +1,68 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package http
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Http;
namespace Volkszaehler\View\HTTP;
/**
* HTTP request
*
* also used for data
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Request {
protected $headers;
protected $parameters;
/**
* HTTP request methods
*
*
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
*/
public $method;
/*
/**
* constructor
*/
public function __construct() {
$this->headers = apache_response_headers(); // NOTICE only works for Apache Webservers
$this->method = $_SERVER['REQUEST_METHOD'];
$this->parameters= array(
'get' => $_GET,
'post' => $_POST,
'cookies' => $_COOKIE,
'files' => $_FILES
);
unset($_GET, $_POST, $_COOKIE, $_FILES);
}
/*
/**
* setter & getter
*/
public function getHeader($header) { return $this->headers[$header]; }
public function getParameter($name, $method = 'get') {
return (isset($this->parameters[$method][$name])) ? $this->parameters[$method][$name] : NULL;
}

View file

@ -1,33 +1,39 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* HTTP request
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* also used for data
*
* This program is distributed in the hope that it will be useful,
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package http
* @author Steffen Vogel <info@steffenvogel.de>
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Http;
namespace Volkszaehler\View\HTTP;
/*
/**
* simple class to control the output buffering
*/
class Response {
protected $headers = array();
protected $code = 200; // default code (OK)
protected static $codes = array(
100 => 'Continue',
101 => 'Switching Protocols',
@ -70,32 +76,32 @@ class Response {
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);
/*
/**
* constructor
*/
public function __construct() {
$this->headers = apache_response_headers();
ob_start(array($this, 'obCallback'));
}
public function obCallback($output) {
return $output; // simple passthrough
}
public function send() {
// change returncode
header('HTTP/1.1 ' . $this->code . ' ' . self::getCodeDescription($this->code));
// send headers
foreach ($this->headers as $name => $value) {
header($name . ': ' . $value);
}
ob_end_flush();
}
/*
/**
* setter & getter
*/
public function setHeader($header, $value) { $this->headers[$header] = $value; }

View file

@ -1,48 +1,56 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Json;
namespace Volkszaehler\View\JSON;
/**
* JSON channel view
*
* also used for data
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Channel extends JSON {
class Channel extends Json {
public function add(\Volkszaehler\Model\Channel $obj, array $data = NULL) {
$channel['uuid'] = (string) $obj->getUuid();
$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();
}
if (isset($data)) {
$channel['data'] = array();
foreach ($data as $reading) {
$channel['data'][] = array($reading['timestamp'], $reading['value'], $reading['count']);
}
}
$this->json['channels'][] = $channel;
}
}

View file

@ -0,0 +1,47 @@
<?php
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package group
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\JSON;
/**
* JSON group view
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Group extends JSON {
public function add(\Volkszaehler\Model\Group $obj, $recursive = FALSE) {
$group['uuid'] = (string) $obj->getUuid();
$group['name'] = $obj->getName();
$group['description'] = $obj->getDescription();
if ($recursive) { // TODO add nested groups in json view
$children = $obj->getChildren();
foreach ($children as $child) {
$this->addGroup($child, $recursive);
}
}
$this->json['groups'][] = $group;
}
}

View file

@ -1,35 +1,43 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* JSON view
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* also used for data
*
* This program is distributed in the hope that it will be useful,
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @author Steffen Vogel <info@steffenvogel.de>
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Json;
namespace Volkszaehler\View\JSON;
use Volkszaehler\View\HTTP;
use Volkszaehler\View;
use Volkszaehler\Util;
abstract class Json extends \Volkszaehler\View\View {
abstract class JSON extends View\View {
protected $json = array();
/*
/**
* constructor
*/
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
public function __construct(HTTP\Request $request, HTTP\Response $response) {
parent::__construct($request, $response);
$this->json['source'] = 'volkszaehler.org';
@ -40,13 +48,13 @@ abstract class Json extends \Volkszaehler\View\View {
public function render() {
$json = json_encode($this->json);
if (Util\Debug::isActivated()) {
$json = self::format($json);
}
echo $json;
parent::render();
}
@ -103,7 +111,7 @@ abstract class Json extends \Volkszaehler\View\View {
public function addDebug(Util\Debug $debug) {
$this->json['debug'] = array(
'time' => $debug->getExecutionTime(),
'messages' => $debug->getMessages(),
'messages' => $debug->getMessages(),
'database' => array(
'driver' => Util\Configuration::read('db.driver'),
'queries' => $debug->getQueries()

View file

@ -1,22 +1,22 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View;
@ -25,19 +25,23 @@ require_once \Volkszaehler\BACKEND_DIR . '/lib/vendor/JpGraph/jpgraph.php';
require_once \Volkszaehler\BACKEND_DIR . '/lib/vendor/JpGraph/jpgraph_scatter.php';
require_once \Volkszaehler\BACKEND_DIR . '/lib/vendor/JpGraph/jpgraph_date.php';
/*
* JpGraph plotting
*
/**
* plotting and graphing of data on the server side
*
* this view uses the JpGraph PHP5 plotting library
*
* @author Steffen Vogel <info@steffenvogel.de>
* @link http://jpgraph.net/
* @todo add caching
*/
class JpGraph extends View {
/*
/**
* indicator => ynaxis[n] mapping
*/
protected $axes = array();
protected $channels = array();
protected $width = 800;
protected $height = 400;
@ -45,35 +49,44 @@ class JpGraph extends View {
protected $graph;
/*
* constructor
/**
*
* @param HTTP\Request $request
* @param HTTP\Response $response
* @param string $format one of png, jpeg, gif
*/
public function __construct(Http\Request $request, Http\Response $response, $format) {
public function __construct(HTTP\Request $request, HTTP\Response $response, $format) {
parent::__construct($request, $response);
$this->graph = new \Graph($this->width,$this->height);
$this->graph->img->SetImgFormat($format);
// Specify what scale we want to use,
$this->graph->SetScale('datlin');
$this->graph->legend->SetPos(0.1,0.02, 'left', 'top');
$this->graph->legend->SetShadow(FALSE);
$this->graph->SetMarginColor('white');
$this->graph->SetYDeltaDist(65);
$this->graph->yaxis->SetTitlemargin(36);
$this->graph->SetTickDensity(TICKD_DENSE, TICKD_SPARSE);
$this->graph->xaxis->SetFont(FF_ARIAL);
$this->graph->xaxis->SetLabelAngle(45);
$this->graph->xaxis->SetLabelFormatCallback(function($label) { return date('j.n.y G:i', $label); });
//$this->graph->img->SetAntiAliasing();
//$this->graph->img->SetAntiAliasing();
}
/**
* adds new plot to the graph
*
* @param $obj
* @param $data
*/
public function add(\Volkszaehler\Model\Channel $obj, array $data) {
$count = count($this->channels);
$xData = $yData = array();
@ -81,18 +94,18 @@ class JpGraph extends View {
$xData[] = $reading['timestamp']/1000;
$yData[] = $reading['value'];
}
// Create the scatter plot
$plot = new \ScatterPlot($yData, $xData);
$plot->setLegend($obj->getName() . ': ' . $obj->getDescription() . ' [' . $obj->getUnit() . ']');
$plot->SetLinkPoints(TRUE, self::$colors[$count]);
$plot->mark->SetColor(self::$colors[$count]);
$plot->mark->SetFillColor(self::$colors[$count]);
$plot->mark->SetType(MARK_DIAMOND);
$plot->mark->SetWidth(1);
$axis = $this->getAxisIndex($obj);
if ($axis >= 0) {
$this->graph->AddY($axis, $plot);
@ -100,40 +113,50 @@ class JpGraph extends View {
else {
$this->graph->Add($plot);
}
$this->channels[] = $obj;
}
protected function getAxisIndex(\Volkszaehler\Model\Channel $obj) {
if (!in_array($obj->getIndicator(), array_keys($this->axes))) {
$count =count($this->axes);
/**
* check weather a axis for the indicator of $channel exists
*
* @param \Volkszaehler\Model\Channel $channel
*/
protected function getAxisIndex(\Volkszaehler\Model\Channel $channel) {
if (!in_array($channel->getIndicator(), array_keys($this->axes))) {
$count =count($this->axes);
if ($count == 0) {
$this->axes[$obj->getIndicator()] = -1;
$this->axes[$channel->getIndicator()] = -1;
$yaxis = $this->graph->yaxis;
}
else {
$this->axes[$obj->getIndicator()] = $count - 1;
$this->graph->SetYScale($this->axes[$obj->getIndicator()],'lin');
$yaxis = $this->graph->ynaxis[$this->axes[$obj->getIndicator()]];
}
$yaxis->title->Set($obj->getUnit());
$yaxis->SetFont(FF_ARIAL);
$yaxis->title->SetFont(FF_ARIAL);
$yaxis->SetTitleMargin('50');
}
return $this->axes[$obj->getIndicator()];
}
/**
* render graph and send output directly to browser
*
* headers has been set automatically
*/
public function render() {
$this->graph->SetMargin(75, (count($this->axes) - 1) * 65 + 10, 20, 90);
// Display the graph
$this->graph->Stroke();

View file

@ -1,41 +0,0 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\View\Json;
class Group extends Json {
public function add(\Volkszaehler\Model\Group $obj, $recursive = FALSE) {
$group['uuid'] = (string) $obj->getUuid();
$group['name'] = $obj->getName();
$group['description'] = $obj->getDescription();
if ($recursive) { // TODO add nested groups in json view
$children = $obj->getChildren();
foreach ($children as $child) {
$this->addGroup($child, $recursive);
}
}
$this->json['groups'][] = $group;
}
}

View file

@ -1,69 +1,76 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View;
use Volkszaehler\View\HTTP;
use Volkszaehler\Util;
/**
* superclass for all view classes
*
* @author Steffen Vogel <info@steffenvogel.de>
*
*/
abstract class View {
public $request;
protected $response;
public function __construct(Http\Request $request, Http\Response $response) {
public function __construct(HTTP\Request $request, HTTP\Response $response) {
$this->request = $request;
$this->response = $response;
// error & exception handling by view
set_exception_handler(array($this, 'exceptionHandler'));
set_error_handler(array($this, 'errorHandler'));
}
/*
/**
* error & exception handling
*/
final public function errorHandler($errno, $errstr, $errfile, $errline) {
$this->exceptionHandler(new \ErrorException($errstr, 0, $errno, $errfile, $errline));
}
final public function exceptionHandler(\Exception $exception) {
$this->addException($exception);
//$this->status = STATUS_EXCEPTION; // TODO add status reporting to API
$code = ($exception->getCode() == 0 && Http\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode();
$code = ($exception->getCode() == 0 && HTTP\Response::getCodeDescription($exception->getCode())) ? 400 : $exception->getCode();
$this->response->setCode($code);
$this->render();
die();
}
public function render() {
$this->response->send();
}
public function addException(\Exception $e) {
echo $e;
}
public function addDebug(Util\Debug $debug) {
}
}

View file

@ -1,67 +1,77 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package channel
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* This file is part of volkzaehler.org
*
* This program is distributed in the hope that it will be useful,
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Xml;
namespace Volkszaehler\View\XML;
class Channel extends Xml {
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
use Volkszaehler\View\HTTP;
/**
* XML channel view
*
* also used for data
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Channel extends XML {
public function __construct(HTTP\Request $request, HTTP\Response $response) {
parent::__construct($request, $response);
$this->xml = $this->xmlDoc->createElement('channels');
}
public function add(\Volkszaehler\Model\Channel $obj, array $data = NULL) {
$xmlChannel = $this->xmlDoc->createElement('channel');
$xmlChannel->setAttribute('uuid', $obj->getUuid());
$xmlChannel->appendChild($this->xmlDoc->createElement('indicator', $obj->getIndicator()));
$xmlChannel->appendChild($this->xmlDoc->createElement('unit', $obj->getUnit()));
$xmlChannel->appendChild($this->xmlDoc->createElement('name', $obj->getName()));
$xmlChannel->appendChild($this->xmlDoc->createElement('description', $obj->getDescription()));
$xmlChannel->appendChild($this->xmlDoc->createElement('resolution', (int) $obj->getResolution()));
$xmlChannel->appendChild($this->xmlDoc->createElement('cost', (float) $obj->getCost()));
if (isset($data)) {
$xmlData = $this->xmlDoc->createElement('data');
foreach ($data as $reading) {
$xmlReading = $this->xmlDoc->createElement('reading');
$xmlReading->setAttribute('timestamp', $reading['timestamp']); // hardcoded data fields for performance optimization
$xmlReading->setAttribute('value', $reading['value']);
$xmlReading->setAttribute('count', $reading['count']);
$xmlData->appendChild($xmlReading);
}
$xmlChannel->appendChild($xmlData);
}
$this->xml->appendChild($xmlChannel);
}
public function render() {
$this->xmlRoot->appendChild($this->xml);
parent::render();
}
}

View file

@ -0,0 +1,57 @@
<?php
/**
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package group
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\XML;
use Volkszaehler\View\HTTP;
/**
* XML group view
*
* @author Steffen Vogel <info@steffenvogel.de>
*/
class Group extends XML {
protected $xml;
public function __construct(HTTP\Request $request, HTTP\Request $response) {
parent::__construct($request, $response);
$this->xml = $this->xmlDoc->createElement('groups');
}
public function add(\Volkszaehler\Model\Group $obj) {
$xmlGroup = $this->xmlDoc->createElement('group');
$xmlGroup->setAttribute('uuid', $obj->getUuid());
$xmlGroup->appendChild($this->xmlDoc->createElement('name', $obj->getName()));
$xmlGroup->appendChild($this->xmlDoc->createElement('description', $obj->getDescription()));
// TODO include sub groups?
$this->xml->appendChild($xmlGroup);
}
public function render() {
$this->xmlRoot->appendChild($this->xml);
parent::render();
}
}

View file

@ -1,32 +1,37 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
/**
* XML view
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @author Steffen Vogel <info@steffenvogel.de>
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This program is distributed in the hope that it will be useful,
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Volkszaehler\View\Xml;
namespace Volkszaehler\View\XML;
use Volkszaehler\View\HTTP;
use Volkszaehler\View;
use Volkszaehler\Util;
abstract class Xml extends \Volkszaehler\View\View {
abstract class XML extends View\View {
protected $xmlDoc;
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
public function __construct(HTTP\Request $request, HTTP\Response $response) {
parent::__construct($request, $response);
$this->xmlDoc = new \DOMDocument('1.0', 'UTF-8');
@ -42,7 +47,7 @@ abstract class Xml extends \Volkszaehler\View\View {
public function render() {
$this->xmlDoc->appendChild($this->xmlRoot);
echo $this->xmlDoc->saveXML();
parent::render();
}
@ -56,16 +61,16 @@ abstract class Xml extends \Volkszaehler\View\View {
$this->xmlRoot->appendChild($xmlException);
}
public function addDebug(Util\Debug $debug) {
$xmlDebug = $this->xmlDoc->createElement('debug');
$xmlDebug->appendChild($this->xmlDoc->createElement('time', $debug->getExecutionTime()));
$xmlDebug->appendChild($this->xmlDoc->createElement('database', Util\Configuration::read('db.driver')));
// TODO add queries to xml debug
// TODO add messages to xml output
$this->xmlRoot->appendChild($xmlDebug);
}
@ -86,7 +91,7 @@ abstract class Xml extends \Volkszaehler\View\View {
$xmlArgs->appendChild($this->xmlDoc->createElement('arg', (is_scalar($value)) ? $value : print_r($value, TRUE)));
}
break;
case 'type':
case 'function':
case 'line':

View file

@ -1,49 +0,0 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
namespace Volkszaehler\View\Xml;
class Group extends Xml {
protected $xml;
public function __construct(\Volkszaehler\View\Http\Request $request, \Volkszaehler\View\Http\Response $response) {
parent::__construct($request, $response);
$this->xml = $this->xmlDoc->createElement('groups');
}
public function add(\Volkszaehler\Model\Group $obj) {
$xmlGroup = $this->xmlDoc->createElement('group');
$xmlGroup->setAttribute('uuid', $obj->getUuid());
$xmlGroup->appendChild($this->xmlDoc->createElement('name', $obj->getName()));
$xmlGroup->appendChild($this->xmlDoc->createElement('description', $obj->getDescription()));
// TODO include sub groups?
$this->xml->appendChild($xmlGroup);
}
public function render() {
$this->xmlRoot->appendChild($this->xml);
parent::render();
}
}

View file

@ -1,23 +1,29 @@
<?php
/*
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License (either version 2 or
* version 3) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
/**
* configuration template
*
* you should use this file to obtain your custom configuration
* new parameters should be documented
*
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @author Steffen Vogel <info@steffenvogel.de>
* @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
$config['db']['driver'] = 'pdo_mysql';
$config['db']['host'] = 'localhost';