From 7d9466a0d218a678b15e7174fc44ce275400dcb1 Mon Sep 17 00:00:00 2001 From: losinshi Date: Fri, 18 Aug 2006 19:43:54 +0000 Subject: [PATCH] Frontend module vor Rain added git-svn-id: file:///home/jan/tmp/wetterstation/trunk@27 dd492736-c11a-0410-ad51-8c26713eaf7f --- .../content/module_sets/set_test.html | 2 +- .../frontend/content/modules/mod_temp.html | 2 +- webstuff/frontend/php_inc/connection.inc.php | 10 ++++- webstuff/frontend/php_inc/module.inc.php | 43 ++++++++++++------- webstuff/frontend/php_inc/module_set.inc.php | 4 ++ 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/webstuff/frontend/content/module_sets/set_test.html b/webstuff/frontend/content/module_sets/set_test.html index 3ce2893..a7431d2 100644 --- a/webstuff/frontend/content/module_sets/set_test.html +++ b/webstuff/frontend/content/module_sets/set_test.html @@ -1 +1 @@ -{content:addModule:temp_1}{content:addModule:temp_4} +{content:addModule:rain_3}{content:addModule:temp_1}{content:addModule:temp_4} diff --git a/webstuff/frontend/content/modules/mod_temp.html b/webstuff/frontend/content/modules/mod_temp.html index 0361b6c..fda6c76 100644 --- a/webstuff/frontend/content/modules/mod_temp.html +++ b/webstuff/frontend/content/modules/mod_temp.html @@ -1,4 +1,4 @@ -

Temparatur - {content:fill:sens_location}

+

Temperatur - {content:fill:sens_location}

{content:fill:sens_description}

Momentane Werte

diff --git a/webstuff/frontend/php_inc/connection.inc.php b/webstuff/frontend/php_inc/connection.inc.php index 6fab5c7..ea2374f 100644 --- a/webstuff/frontend/php_inc/connection.inc.php +++ b/webstuff/frontend/php_inc/connection.inc.php @@ -1,12 +1,15 @@ conn = NULL; } - + + /* Verbindung herstellen (wenn noch net besteht)*/ function _createConn(){ if($this->conn == NULL){ $this->conn = pg_connect("host=141.30.228.39 dbname=wetter user=losinshi") @@ -14,6 +17,7 @@ class Connection{ } } + /* Verbindung schließen */ function closeConn(){ if($this->conn != NULL){ pg_close($this->conn); @@ -21,6 +25,7 @@ class Connection{ } } + /* Eine Zeile holen */ function fetchQueryResultLine($query){ $this->_createConn(); $result = pg_query($this->conn, $query) @@ -30,6 +35,7 @@ class Connection{ return $array; } + /* mehrere Zeilen holen */ function fetchQueryResultSet($query){ $returnArray = array(); $this->_createConn(); diff --git a/webstuff/frontend/php_inc/module.inc.php b/webstuff/frontend/php_inc/module.inc.php index 610d2e1..3512121 100644 --- a/webstuff/frontend/php_inc/module.inc.php +++ b/webstuff/frontend/php_inc/module.inc.php @@ -1,8 +1,10 @@ sensId = $sensId; $this->connection = &$connection; $this->parserInstance = &$parser; - - $parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); - $parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); - $parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom"); + $parser->parseContent($this->_getModuleFilename("frame"), & $this, "top"); /* Oberen Modulrahmen parsen */ + $parser->parseContent($this->_getModuleFilename($modName), & $this, NULL); /* Modul Parsen */ + $parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom"); /* unteren Modulrahmen Parsen */ } + /* Dateinamen des Modul-Files zusammenbauen */ function _getModuleFilename($modName){ return "content/modules/mod_".$modName.".html"; } + /* Instanz der Sensorklasse holen */ function &_get_sens(){ if($this->sensInstance == NULL) $this->sensInstance = new Sensor($this->sensId, $this->connection); return $this->sensInstance; } + /* Instanz der Temp-Klasse holen */ function &_get_temp(){ if($this->tempInstance == NULL) $this->tempInstance = new Temp($this->sensId, $this->connection); return $this->tempInstance; } - function fill($contentId){ - $content_split = explode("_", $contentId); - $callObject = & call_user_method("_get_".$content_split[0], $this); - $funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); - - + /* Instanz der Rain-Klasse holen */ + function &_get_rain(){ + if($this->rainInstance == NULL) + $this->rainInstance = new Rain($this->sensId, $this->connection); + return $this->rainInstance; + } - return $callObject->$funcName($content_split[1]); + /* Callback-Funktion, wird ausgeführt wenn {content:fill:xyz} gefunden wird */ + function fill($contentId){ + $content_split = explode("_", $contentId); /* Modultyp bekommen */ + $callObject = & call_user_method("_get_".$content_split[0], $this); /* Instanz der zum Modul gehörenden Klasse */ + $funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); /* Namen der In der Instanz aufzurufenden Methode zusammenbauen */ + + return $callObject->$funcName($content_split[1]); /* Methode ausführen (Wert holen) und zurückgeben */ } } diff --git a/webstuff/frontend/php_inc/module_set.inc.php b/webstuff/frontend/php_inc/module_set.inc.php index a5ff8b8..b56aa95 100644 --- a/webstuff/frontend/php_inc/module_set.inc.php +++ b/webstuff/frontend/php_inc/module_set.inc.php @@ -15,6 +15,10 @@ class ModuleSet{ $parser->parseContent($this->_getSetFilename($setName), &$this, NULL); /* Set Parsen */ $parser->printContent(); + + if ($this->connInstance != NULL){ + $this->connInstance->closeConn(); + } } /* Dateinamen eines Setz aus dessen Namen zusammenbauen */