From ed9f71e519e5fbb7621c91c633d272cb7a999922 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 26 Sep 2010 14:00:15 +0200 Subject: [PATCH] fixed definitions and added translations --- README | 4 +- backend/lib/Definition/Definition.php | 13 +- backend/lib/Definition/EntityDefinition.json | 161 ++++++++++-------- backend/lib/Definition/EntityDefinition.php | 12 +- .../lib/Definition/PropertyDefinition.json | 130 +++++++------- backend/lib/Definition/PropertyDefinition.php | 3 + backend/lib/Model/Property.php | 11 +- 7 files changed, 184 insertions(+), 150 deletions(-) diff --git a/README b/README index a4cdf47..71a15e7 100644 --- a/README +++ b/README @@ -4,11 +4,11 @@ volkszaehler.org/ |_ frontend/ Web Frontend |_ backend/ PHP Backend |_ controller/ Controller Code für verschiedene Plattformen/Programmiersprachen - | \_ php/ Einfach Referenzimplementation des Controller-Codes in PHP + | |_ php/ Einfach Referenzimplementation des Controller-Codes in PHP + | \_ ethersex Portierung auf ethersex | \_ share/ Gemeinsam genutze Codebestandteile |_ docs/ Dokumentation - |_ definitions/ Gemeinsame Definitionen über Entities und deren Eigenschaften für Controller, Backend & Frontend |_ sql/ SQL-Schema Dumps für verschieden Datenbanksysteme | \_ demo/ Demo Daten zum Import in die Datenbank | diff --git a/backend/lib/Definition/Definition.php b/backend/lib/Definition/Definition.php index ffc8156..ec055da 100644 --- a/backend/lib/Definition/Definition.php +++ b/backend/lib/Definition/Definition.php @@ -30,14 +30,15 @@ use Volkszaehler\Util; * @package default */ abstract class Definition { - /** @var string discriminator for database column */ + /** + * @var string discriminator for database column + */ protected $name; - /** @var string title for UI */ - //protected $title; - - /** @var string description for UI */ - //protected $description; + /** + * @var string title for UI + */ + protected $translation; /** * Hide default constructor diff --git a/backend/lib/Definition/EntityDefinition.json b/backend/lib/Definition/EntityDefinition.json index a0cbf2c..e3fb9ec 100644 --- a/backend/lib/Definition/EntityDefinition.json +++ b/backend/lib/Definition/EntityDefinition.json @@ -1,7 +1,7 @@ /** * Definition of entities - * Format is specified in EntityDefinition class + * Format is specified in EntityDefinition model * * @author Steffen Vogel * @copyright Copyright (c) 2010, The volkszaehler.org project @@ -27,98 +27,111 @@ [ { - "name" : "group", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "tolerance"], - "interpreter" : "AggregatorInterpreter", - "icon" : "", // TODO look for an icon - "de_name" : "Gruppe" + "name" : "group", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "tolerance"], + "icon" : "", // TODO look for an icon + "interpreter" : "Volkszaehler\\Interpreter\\AggregatorInterpreter", + "model" : "Volkszaehler\\Model\\Aggregator", + "translation" : { "de" : "Gruppe" } }, { - "name" : "user", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "tolerance"], - "interpreter" : "AggregatorInterpreter", - "icon" : "", // TODO look for an icon - "de_name" : "Nutzer" + "name" : "user", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "tolerance"], + "icon" : "", // TODO look for an icon + "interpreter" : "Volkszaehler\\Interpreter\\AggregatorInterpreter", + "model" : "Volkszaehler\\Model\\Aggregator", + "translation" : { "de" : "Nutzer" } }, { - "name" : "power", - "required" : ["title", "resolution"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "MeterInterpreter", - "unit" : "kW/h", - "icon" : "", // TODO look for an icon - "de_name" : "Strom" + "name" : "power", + "required" : ["title", "resolution"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "kW/h", + "interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Strom" } }, { - "name" : "gas", - "required" : ["title", "resolution"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "MeterInterpreter", - "unit" : "m³/h", - "icon" : "", // TODO look for an icon - "de_name" : "Gas" + "name" : "gas", + "required" : ["title", "resolution"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "m³/h", + "interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Gas" } }, { - "name" : "water", - "required" : ["title", "resolution"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "MeterInterpreter", - "unit" : "m³/h", - "icon" : "", // TODO look for an icon - "de_name" : "Wasser" + "name" : "water", + "required" : ["title", "resolution"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "m³/h", + "interpreter" : "Volkszaehler\\Interpreter\\MeterInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Wasser" } }, { - "name" : "temperature", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "unit" : "°C", - "icon" : "", // TODO look for an icon - "de_name" : "Temperatur" + "name" : "temperature", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "°C", + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Temperatur" } }, { - "name" : "pressure", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "unit" : "hPa", - "icon" : "", // TODO look for an icon - "de_name" : "Luftdruck" + "name" : "pressure", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "hPa", + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Luftdruck" } }, { - "name" : "humidity", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "unit" : "%", - "icon" : "", // TODO look for an icon - "de_name" : "Luftfeuchtigkeit" + "name" : "humidity", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "%", + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Luftfeuchtigkeit" } }, { - "name" : "windspeed", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "unit" : "km/h", - "icon" : "", // TODO look for an icon - "de_name" : "Windgeschwindigkeit" + "name" : "windspeed", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "km/h", + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Windgeschwindigkeit" } }, { - "name" : "radition", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "icon" : "", // TODO look for an icon - "de_name" : "Strahlung" + "name" : "radition", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "", // TODO add unit + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Strahlung" } }, { - "name" : "luminosity", - "required" : ["title"], - "optional" : ["description", "details:", "owner:", "address:", "tolerance"], - "interpreter" : "SensorInterpreter", - "icon" : "", // TODO look for an icon - "de_name" : "Lichtstärke" + "name" : "luminosity", + "required" : ["title"], + "optional" : ["description", "details:", "owner:", "address:", "tolerance"], + "icon" : "", // TODO look for an icon + "unit" : "", // TODO add unit + "interpreter" : "Volkszaehler\\Interpreter\\SensorInterpreter", + "model" : "Volkszaehler\\Model\\Channel", + "translation" : { "de" : "Lichtstärke" } } ] diff --git a/backend/lib/Definition/EntityDefinition.php b/backend/lib/Definition/EntityDefinition.php index 423b619..3f54eb9 100644 --- a/backend/lib/Definition/EntityDefinition.php +++ b/backend/lib/Definition/EntityDefinition.php @@ -58,6 +58,13 @@ class EntityDefinition extends Definition { */ protected $interpreter; + /** + * Classname of model (see backend/lib/Model/) + * + * @var string + */ + protected $model; + /** * Optional for Aggregator class entities * @@ -71,7 +78,10 @@ class EntityDefinition extends Definition { */ protected $icon; - static protected $definitions = NULL; + /** + * @var array holds definitions + */ + protected static $definitions = NULL; /* * Setter & Getter diff --git a/backend/lib/Definition/PropertyDefinition.json b/backend/lib/Definition/PropertyDefinition.json index bd5fc4e..e38240c 100644 --- a/backend/lib/Definition/PropertyDefinition.json +++ b/backend/lib/Definition/PropertyDefinition.json @@ -27,72 +27,72 @@ [ { - "name" : "title", - "type" : "string", - "pattern" : "/[a-z0-9 ]/", - "min": 3, - "max" : 255, - "de_name" : "Titel" + "name" : "title", + "type" : "string", + "pattern" : "/[a-z0-9 ]/", + "min" : 3, + "max" : 255, + "translation" : { "de" : "Titel" } }, { - "name" : "description", - "type" : "text", - "pattern" : "/[a-z0-9 ]/", // TODO add whitespaces as \t \n \r - "max" : 255, // TODO allowed column size in database? - "de_name" : "Beschreibung" + "name" : "description", + "type" : "text", + "pattern" : "/[a-z0-9 ]/", // TODO add whitespaces as \t \n \r + "max" : 255, // TODO allowed column size in database? + "translation" : { "de" : "Beschreibung" } }, { - "name" : "cost", - "type" : "float", - "min" : 0, - "de_name" : "Kosten" + "name" : "cost", + "type" : "float", + "min" : 0, + "translation" : { "de" : "Kosten" } }, { - "name" : "resolution", - "type" : "integer", - "min" : 1, - "de_name" : "Auflösung" + "name" : "resolution", + "type" : "integer", + "min" : 1, + "translation" : { "de" : "Auflösung" } }, { - "name" : "tolerance", - "type" : "float", - "min" : 0, - "max" : 1, - "de_name" : "Toleranz" + "name" : "tolerance", + "type" : "float", + "min" : 0, + "max" : 1, + "translation" : { "de" : "Toleranz" } }, { - "name" : "address:lat", - "type" : "float", - "min" : -90, - "max" : 90, - "de_name" : "Latitude" + "name" : "address:lat", + "type" : "float", + "min" : -90, + "max" : 90, + "translation" : { "de" : "Latitude" } }, { - "name" : "address:lon", - "type" : "float", - "min" : -90, - "max" : 90, - "de_name" : "Longitude" + "name" : "address:lon", + "type" : "float", + "min" : -90, + "max" : 90, + "translation" : { "de" : "Longitude" } }, { - "name" : "address:city", - "type" : "string", - "pattern" : "", // TODO add pattern - "de_name" : "Stadt" + "name" : "address:city", + "type" : "string", + "pattern" : "", // TODO add pattern + "translation" : { "de" : "Stadt" } }, { - "name" : "address:houseno", - "type" : "string", - "de_name" : "Hausnummer" + "name" : "address:houseno", + "type" : "string", + "translation" : { "de" : "Hausnummer" } }, { - "name" : "address:postal", - "type" : "string", - "de_name" : "Postleitzahl" + "name" : "address:postal", + "type" : "string", + "translation" : { "de" : "Postleitzahl" } }, { - "name" : "address:state", - "type" : "multiple", + "name" : "address:state", + "type" : "multiple", "options" : [ "Albania", "Algeria", @@ -284,34 +284,34 @@ "Yemen", "Zambia" ], - "de_name" : "Land" + "translation" : { "de" : "Land" } }, { - "name" : "address:country", - "type" : "string", - "de_name" : "Staat" + "name" : "address:country", + "type" : "string", + "translation" : { "de" : "Staat" } }, { - "name" : "photo:url", - "type" : "string", - "pattern" : "", // TODO add pattern - "de_name" : "Foto (URL)" + "name" : "photo:url", + "type" : "string", + "pattern" : "", // TODO add pattern + "translation" : { "de" : "Foto (URL)" } }, { - "name" : "cuuid", - "type" : "string", - "max" : 37, - "de_name" : "Cotroller UUID" + "name" : "cuuid", + "type" : "string", + "max" : 37, + "translation" : { "de" : "Cotroller UUID" } }, { - "name" : "port", - "type" : "string", - "max" : 6, - "de_name" : "Controller Pin" + "name" : "port", + "type" : "string", + "max" : 6, + "translation" : { "de" : "Controller Pin" } }, { - "name" : "active", - "type" : "boolean", - "de_name" : "Aktiv?" + "name" : "active", + "type" : "boolean", + "translation" : { "de" : "Aktiv?" } } ] diff --git a/backend/lib/Definition/PropertyDefinition.php b/backend/lib/Definition/PropertyDefinition.php index a9ffd60..5129dd2 100644 --- a/backend/lib/Definition/PropertyDefinition.php +++ b/backend/lib/Definition/PropertyDefinition.php @@ -73,6 +73,9 @@ class PropertyDefinition extends Definition { */ protected $options = array(); + /** + * @var array holds definitions + */ protected static $definitions = NULL; /** diff --git a/backend/lib/Model/Property.php b/backend/lib/Model/Property.php index b8ef320..898d352 100644 --- a/backend/lib/Model/Property.php +++ b/backend/lib/Model/Property.php @@ -81,8 +81,15 @@ class Property { * @PostLoad */ public function cast() { - if ($this->getDefinition()->getType() != 'multiple') { - settype($this->value, $this->getDefinition()->getType()); + $type = $this->getDefinition()->getType(); + if ($type == 'multiple') { + // TODO + } + elseif ($type == 'text') { + settype($this->value, 'string'); + } + else { + settype($this->value, $type); } }