diff --git a/backend/bin/doctrine.php b/backend/bin/doctrine.php
index 6e417ba..ef48e55 100644
--- a/backend/bin/doctrine.php
+++ b/backend/bin/doctrine.php
@@ -1,4 +1,27 @@
+ * @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 .
+ */
// TODO replace by state class
const BACKEND_DIR = '/home/steffen/workspace/volkszaehler.org/backend';
diff --git a/backend/index.php b/backend/index.php
index ed1f4cd..b537210 100644
--- a/backend/index.php
+++ b/backend/index.php
@@ -1,22 +1,25 @@
+/**
+ * backend bootstrapping entrypoint
+ *
+ * @author Steffen Vogel
+ * @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 .
*/
namespace Volkszaehler;
diff --git a/backend/lib/Controller/Channel.php b/backend/lib/Controller/Channel.php
index 42f4f0c..59ad0a8 100644
--- a/backend/lib/Controller/Channel.php
+++ b/backend/lib/Controller/Channel.php
@@ -1,28 +1,35 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Controller;
use \Volkszaehler\Model;
+/**
+ * channel controller
+ *
+ * @author Steffen Vogel
+ *
+ */
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() {
}
diff --git a/backend/lib/Controller/Controller.php b/backend/lib/Controller/Controller.php
index 450e336..8fda019 100644
--- a/backend/lib/Controller/Controller.php
+++ b/backend/lib/Controller/Controller.php
@@ -1,31 +1,37 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Controller;
+/**
+ * controller superclass for all controllers
+ *
+ * @author Steffen Vogel
+ *
+ */
abstract class Controller {
protected $view;
protected $em;
- /*
+ /**
* constructor
*/
public function __construct(\Volkszaehler\View\View $view, \Doctrine\ORM\EntityManager $em) {
diff --git a/backend/lib/Controller/Data.php b/backend/lib/Controller/Data.php
index 65542ea..a97a4ee 100644
--- a/backend/lib/Controller/Data.php
+++ b/backend/lib/Controller/Data.php
@@ -1,32 +1,40 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Controller;
-// TODO call via redirect from Controller\Channel
use Volkszaehler\Util;
+/**
+ * data controller
+ *
+ * @author Steffen Vogel
+ * @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;
diff --git a/backend/lib/Controller/Group.php b/backend/lib/Controller/Group.php
index d443b8c..9c0c13f 100644
--- a/backend/lib/Controller/Group.php
+++ b/backend/lib/Controller/Group.php
@@ -1,27 +1,38 @@
-chann
+.
*/
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();
- }
+
+}
}
?>
\ No newline at end of file
diff --git a/backend/lib/Dispatcher.php b/backend/lib/Dispatcher.php
index a2dbe8f..776318f 100644
--- a/backend/lib/Dispatcher.php
+++ b/backend/lib/Dispatcher.php
@@ -1,78 +1,105 @@
+/**
+ * @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 .
*/
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
*/
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);
}
}
diff --git a/backend/lib/Interpreter/Interpreter.php b/backend/lib/Interpreter/Interpreter.php
index f1848b2..47d82ad 100644
--- a/backend/lib/Interpreter/Interpreter.php
+++ b/backend/lib/Interpreter/Interpreter.php
@@ -1,26 +1,31 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Interpreter;
+/**
+ *
+ * @author Steffen Vogel
+ *
+ */
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
+ *
+ */
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) {
diff --git a/backend/lib/Interpreter/Meter.php b/backend/lib/Interpreter/Meter.php
index d05cea6..6e06a3f 100644
--- a/backend/lib/Interpreter/Meter.php
+++ b/backend/lib/Interpreter/Meter.php
@@ -1,28 +1,41 @@
+/**
+ * @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 .
*/
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);
diff --git a/backend/lib/Interpreter/Sensor.php b/backend/lib/Interpreter/Sensor.php
index bafa05c..5fd5bf3 100644
--- a/backend/lib/Interpreter/Sensor.php
+++ b/backend/lib/Interpreter/Sensor.php
@@ -1,28 +1,39 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Interpreter;
+/**
+ * sensor interpreter
+ *
+ * @author Steffen Vogel
+ */
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();
}
diff --git a/backend/lib/Logger/Flukso.php b/backend/lib/Logger/Flukso.php
index 71f3c80..6afdd98 100644
--- a/backend/lib/Logger/Flukso.php
+++ b/backend/lib/Logger/Flukso.php
@@ -1,26 +1,35 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Logger;
+/**
+ * logger for the Flukso.net api
+ *
+ * @link http://www.flukso.net
+ * @link http://github.com/icarus75/flukso
+ * @author Steffen Vogel
+ * @todo to be implemented
+ */
class Flukso implements Logger {
}
diff --git a/backend/lib/Logger/Logger.php b/backend/lib/Logger/Logger.php
index cae526a..8fdee3b 100644
--- a/backend/lib/Logger/Logger.php
+++ b/backend/lib/Logger/Logger.php
@@ -1,32 +1,38 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Logger;
-/*
+use Volkszaehler\View\HTTP;
+
+/**
* interface for parsing diffrent logging APIs (google, flukso etc..)
+ *
+ * @author Steffen Vogel
+ * @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
*/
diff --git a/backend/lib/Model/Channel.php b/backend/lib/Model/Channel.php
index 2ed414d..5aa93ca 100644
--- a/backend/lib/Model/Channel.php
+++ b/backend/lib/Model/Channel.php
@@ -1,22 +1,23 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Model;
@@ -24,8 +25,10 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
- * Channel class
+ * Channel entity
*
+ * @author Steffen Vogel
+ *
* @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; }
diff --git a/backend/lib/Model/Data.php b/backend/lib/Model/Data.php
index e5c0958..e2b87d3 100644
--- a/backend/lib/Model/Data.php
+++ b/backend/lib/Model/Data.php
@@ -1,22 +1,23 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Model;
@@ -24,6 +25,10 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
+ * Data entity
+ *
+ * @author Steffen Vogel
+ *
* @Entity
* @Table(name="data")
*/
@@ -55,7 +60,7 @@ class Data {
$this->timestamp = $timestamp;
}
- /*
+ /**
* setter & getter
*/
public function getValue() { return $this->value; }
diff --git a/backend/lib/Model/Entity.php b/backend/lib/Model/Entity.php
index 9057158..a223609 100644
--- a/backend/lib/Model/Entity.php
+++ b/backend/lib/Model/Entity.php
@@ -1,22 +1,22 @@
+/**
+ * @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 .
*/
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
*
* @MappedSuperclass
*/
@@ -43,7 +45,7 @@ abstract class Entity {
$this->uuid = Util\Uuid::mint();
}
- /*
+ /**
* getter & setter
*/
public function getId() { return $this->id; } // read only
diff --git a/backend/lib/Model/Group.php b/backend/lib/Model/Group.php
index 45c0f8a..d0b9796 100644
--- a/backend/lib/Model/Group.php
+++ b/backend/lib/Model/Group.php
@@ -1,22 +1,23 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Model;
@@ -24,7 +25,9 @@ namespace Volkszaehler\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
- * Grouping class
+ * Group entity
+ *
+ * @author Steffen Vogel
*
* @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; }
diff --git a/backend/lib/Util/ClassLoader.php b/backend/lib/Util/ClassLoader.php
index 4439b60..71eafb3 100644
--- a/backend/lib/Util/ClassLoader.php
+++ b/backend/lib/Util/ClassLoader.php
@@ -1,28 +1,36 @@
+ * @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
- * .
- */
-
-/*
- * 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 .
*/
namespace Volkszaehler\Util;
+/**
+ * class loader for volkszaehler and vendor libraries
+ *
+ * namespace is mapped to the filesystem structure
+ *
+ * @author Roman Borschel
+ * @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);
}
diff --git a/backend/lib/Util/Configuration.php b/backend/lib/Util/Configuration.php
index e43d15c..0aecce3 100644
--- a/backend/lib/Util/Configuration.php
+++ b/backend/lib/Util/Configuration.php
@@ -1,50 +1,65 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\Util;
+/**
+ * static configuration class for loading and storing the configuration to the disk
+ *
+ * @author Steffen Vogel
+ */
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 = <<
+/**
+ * @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 .
*/
namespace Volkszaehler\Util;
use Doctrine\DBAL\Logging;
+/**
+ * static debugging class
+ *
+ * @author Steffen Vogel
+ */
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; }
}
diff --git a/backend/lib/Util/Uuid.php b/backend/lib/Util/UUID.php
similarity index 86%
rename from backend/lib/Util/Uuid.php
rename to backend/lib/Util/UUID.php
index edc1238..3ceb4fd 100644
--- a/backend/lib/Util/Uuid.php
+++ b/backend/lib/Util/UUID.php
@@ -1,6 +1,34 @@
.
+ */
+
+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))."-".
diff --git a/backend/lib/View/Csv/Csv.php b/backend/lib/View/CSV/CSV.php
similarity index 66%
rename from backend/lib/View/Csv/Csv.php
rename to backend/lib/View/CSV/CSV.php
index 0fe1499..42e1975 100644
--- a/backend/lib/View/Csv/Csv.php
+++ b/backend/lib/View/CSV/CSV.php
@@ -1,40 +1,49 @@
+/**
+ * @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 .
*/
-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
+ */
+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;
}
diff --git a/backend/lib/View/CSV/Data.php b/backend/lib/View/CSV/Data.php
new file mode 100644
index 0000000..2571738
--- /dev/null
+++ b/backend/lib/View/CSV/Data.php
@@ -0,0 +1,33 @@
+.
+ */
+
+namespace Volkszaehler\View\CSV;
+
+/**
+ * CSV data view
+ * @author Steffen Vogel
+ */
+class Data extends CSV {
+ public function add($obj, $data) {
+ $this->csv = array_merge($this->csv, $data);
+ }
+}
\ No newline at end of file
diff --git a/backend/lib/View/Csv/Data.php b/backend/lib/View/Csv/Data.php
deleted file mode 100644
index 7a97265..0000000
--- a/backend/lib/View/Csv/Data.php
+++ /dev/null
@@ -1,28 +0,0 @@
-
- *
- * 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);
- }
-}
\ No newline at end of file
diff --git a/backend/lib/View/Http/Request.php b/backend/lib/View/HTTP/Request.php
similarity index 55%
rename from backend/lib/View/Http/Request.php
rename to backend/lib/View/HTTP/Request.php
index 8e7bfa1..695489e 100644
--- a/backend/lib/View/Http/Request.php
+++ b/backend/lib/View/HTTP/Request.php
@@ -1,60 +1,68 @@
+/**
+ * @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 .
*/
-namespace Volkszaehler\View\Http;
+namespace Volkszaehler\View\HTTP;
+/**
+ * HTTP request
+ *
+ * also used for data
+ *
+ * @author Steffen Vogel
+ */
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;
}
diff --git a/backend/lib/View/Http/Response.php b/backend/lib/View/HTTP/Response.php
similarity index 75%
rename from backend/lib/View/Http/Response.php
rename to backend/lib/View/HTTP/Response.php
index 9bbbf3b..398386b 100644
--- a/backend/lib/View/Http/Response.php
+++ b/backend/lib/View/HTTP/Response.php
@@ -1,33 +1,39 @@
+/**
+ * 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
+ * @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 .
*/
-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; }
diff --git a/backend/lib/View/Json/Channel.php b/backend/lib/View/JSON/Channel.php
similarity index 53%
rename from backend/lib/View/Json/Channel.php
rename to backend/lib/View/JSON/Channel.php
index 95bacfa..6708ec0 100644
--- a/backend/lib/View/Json/Channel.php
+++ b/backend/lib/View/JSON/Channel.php
@@ -1,48 +1,56 @@
+/**
+ * @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 .
*/
-namespace Volkszaehler\View\Json;
+namespace Volkszaehler\View\JSON;
+
+/**
+ * JSON channel view
+ *
+ * also used for data
+ *
+ * @author Steffen Vogel
+ */
+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;
}
}
diff --git a/backend/lib/View/JSON/Group.php b/backend/lib/View/JSON/Group.php
new file mode 100644
index 0000000..1756123
--- /dev/null
+++ b/backend/lib/View/JSON/Group.php
@@ -0,0 +1,47 @@
+.
+ */
+
+namespace Volkszaehler\View\JSON;
+
+/**
+ * JSON group view
+ *
+ * @author Steffen Vogel
+ */
+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;
+ }
+}
diff --git a/backend/lib/View/Json/Json.php b/backend/lib/View/JSON/JSON.php
similarity index 70%
rename from backend/lib/View/Json/Json.php
rename to backend/lib/View/JSON/JSON.php
index ff0ff1c..40a8991 100644
--- a/backend/lib/View/Json/Json.php
+++ b/backend/lib/View/JSON/JSON.php
@@ -1,35 +1,43 @@
+/**
+ * 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
+ * @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 .
*/
-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()
diff --git a/backend/lib/View/JpGraph.php b/backend/lib/View/JpGraph.php
index eb435e1..a3303da 100644
--- a/backend/lib/View/JpGraph.php
+++ b/backend/lib/View/JpGraph.php
@@ -1,22 +1,22 @@
+/**
+ * @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 .
*/
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
+ * @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();
diff --git a/backend/lib/View/Json/Group.php b/backend/lib/View/Json/Group.php
deleted file mode 100644
index 4ebf4de..0000000
--- a/backend/lib/View/Json/Group.php
+++ /dev/null
@@ -1,41 +0,0 @@
-
- *
- * 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;
- }
-}
diff --git a/backend/lib/View/View.php b/backend/lib/View/View.php
index b92ccdc..95886ba 100644
--- a/backend/lib/View/View.php
+++ b/backend/lib/View/View.php
@@ -1,69 +1,76 @@
+/**
+ * @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 .
*/
namespace Volkszaehler\View;
+use Volkszaehler\View\HTTP;
use Volkszaehler\Util;
+/**
+ * superclass for all view classes
+ *
+ * @author Steffen Vogel
+ *
+ */
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) {
-
+
}
}
\ No newline at end of file
diff --git a/backend/lib/View/Xml/Channel.php b/backend/lib/View/XML/Channel.php
similarity index 64%
rename from backend/lib/View/Xml/Channel.php
rename to backend/lib/View/XML/Channel.php
index 3fb3b6d..60d15cb 100644
--- a/backend/lib/View/Xml/Channel.php
+++ b/backend/lib/View/XML/Channel.php
@@ -1,67 +1,77 @@
+/**
+ * @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 .
*/
-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
+ */
+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();
}
}
\ No newline at end of file
diff --git a/backend/lib/View/XML/Group.php b/backend/lib/View/XML/Group.php
new file mode 100644
index 0000000..123f32a
--- /dev/null
+++ b/backend/lib/View/XML/Group.php
@@ -0,0 +1,57 @@
+.
+ */
+
+namespace Volkszaehler\View\XML;
+
+use Volkszaehler\View\HTTP;
+
+/**
+ * XML group view
+ *
+ * @author Steffen Vogel
+ */
+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();
+ }
+}
\ No newline at end of file
diff --git a/backend/lib/View/Xml/Xml.php b/backend/lib/View/XML/XML.php
similarity index 74%
rename from backend/lib/View/Xml/Xml.php
rename to backend/lib/View/XML/XML.php
index d1de547..d062f94 100644
--- a/backend/lib/View/Xml/Xml.php
+++ b/backend/lib/View/XML/XML.php
@@ -1,32 +1,37 @@
+/**
+ * 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
+ * @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 .
*/
-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':
diff --git a/backend/lib/View/Xml/Group.php b/backend/lib/View/Xml/Group.php
deleted file mode 100644
index 374e982..0000000
--- a/backend/lib/View/Xml/Group.php
+++ /dev/null
@@ -1,49 +0,0 @@
-
- *
- * 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();
- }
-}
\ No newline at end of file
diff --git a/backend/volkszaehler.conf.default.php b/backend/volkszaehler.conf.default.php
index 2bec5bb..9ef8ec8 100644
--- a/backend/volkszaehler.conf.default.php
+++ b/backend/volkszaehler.conf.default.php
@@ -1,23 +1,29 @@
-*
-* 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
+ * @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 .
+ */
$config['db']['driver'] = 'pdo_mysql';
$config['db']['host'] = 'localhost';