Finished temperature module in Webfrontend

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@25 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-08-17 16:13:47 +00:00
parent 4249404692
commit f27798bc3f
6 changed files with 93 additions and 49 deletions

View File

@ -1 +1 @@
{content:addModule:temp_1}{content:addModule:temp_2} {content:addModule:temp_1}{content:addModule:temp_4}

View File

@ -2,22 +2,22 @@
<p class="mod_description">{content:fill:sens_description}</p> <p class="mod_description">{content:fill:sens_description}</p>
<h4 class="mod_subhead">Momentane Werte</h4> <h4 class="mod_subhead">Momentane Werte</h4>
<table class="mod_temp_now_data"> <table class="mod_temp_now_data">
<tr> <tr class="mod_temp_current_row">
<td>Momentan:</td><td>{content:fill:temp_now_val}</td><td>{content:fill:temp_now_date}</td> <td class="mod_line_desc">Momentan:</td><td class="mod_line_val">{content:fill:temp_now_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_now_date}</td>
</tr> </tr>
<tr> <tr class="mod_temp_average_row">
<td>Durchschnitt (halbe std.):</td><td>{content:fill:temp_av_value}</td><td>&nbsp;</td> <td class="mod_line_desc">Durchschnitt ({content:fill:temp_av_interval} min.):</td><td class="mod_line_val">{content:fill:temp_av_value}&deg;C</td><td>&nbsp;</td>
</tr> </tr>
<tr> <tr class="mod_temp_moving_row">
<td>Tendenz (2 std.):</td><td>{content:fill:temp_changing}</td><td>&nbsp;</td> <td class="mod_line_desc">Tendenz (2 std.):</td><td class="mod_line_val">{content:fill:temp_changing}</td><td>&nbsp;</td>
</tr> </tr>
</table> </table>
<h4>Extrema</h4> <h4 class="mod_subhead">Extrema</h4>
<table> <table>
<tr> <tr class="mod_temp_max_row">
<td>Max:</td><td>{content:fill:temp_max_val}</td><td>{content:fill:temp_max_date}</td> <td class="mod_line_desc">Max:</td><td class="mod_line_val">{content:fill:temp_max_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_max_date}</td>
</tr> </tr>
<tr> <tr class="mod_temp_min_row">
<td>Min:</td><td>{content:fill:temp_min_val}</td><td>{content:fill:temp_min_date}</td> <td class="mod_line_desc">Min:</td><td class="mod_line_val">{content:fill:temp_min_val}&deg;C</td><td class="mod_line_date">{content:fill:temp_min_date}</td>
</tr> </tr>
</table> </table>

View File

@ -0,0 +1,44 @@
<?
class Connection{
var $conn = NULL;
function Connection(){
$this->conn = NULL;
}
function _createConn(){
if($this->conn == NULL){
$this->conn = pg_connect("host=141.30.228.39 dbname=wetter user=losinshi")
or die('Verbindungsaufbau fehlgeschlagen: ' . pg_last_error());
}
}
function closeConn(){
if($this->conn != NULL){
pg_close($this->conn);
$this->conn = NULL;
}
}
function fetchQueryResultLine($query){
$this->_createConn();
$result = pg_query($this->conn, $query)
or die('Abfrage fehlgeschlagen: ' . pg_last_error());
$array = pg_fetch_assoc($result);
//print_r($array);
return $array;
}
function fetchQueryResultSet($query){
$returnArray = array();
$this->_createConn();
$result = pg_query($this->conn, $query)
or die('Abfrage fehlgeschlagen: ' . pg_last_error());
while($array = pg_fetch_assoc($result))
array_push($returnArray, $array);
return $returnArray;
}
}
?>

View File

@ -13,37 +13,40 @@ class Module{
var $tempInstance = NULL; /* Temp-Instanz */ var $tempInstance = NULL; /* Temp-Instanz */
function Module($modName, $sensId, $parser, $connection){ function Module($modName, $sensId, &$parser, &$connection){
$this->$sensId = $sensId; $this->sensId = $sensId;
$this->$connection = $connection; $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, "top");
$parser->parseContent($this->_getModuleFilename("frame"), $this, "bottom"); $parser->parseContent($this->_getModuleFilename($modName), & $this, NULL);
$parser->parseContent($this->_getModuleFilename("frame"), & $this, "bottom");
} }
function _getModuleFilename($modName){ function _getModuleFilename($modName){
return "content/modules/mod_".$modName.".html"; return "content/modules/mod_".$modName.".html";
} }
function _get_sens(){ function &_get_sens(){
if($sensInstance == NULL) if($this->sensInstance == NULL)
$this->$sensInstance = new Sensor($this->$sensId, $this->$connection); $this->sensInstance = new Sensor($this->sensId, $this->connection);
return $this->$sensInstance; return $this->sensInstance;
} }
function _get_temp(){ function &_get_temp(){
if($tempInstance == NULL) if($this->tempInstance == NULL)
$this->$tempInstance = new Temp($this->$sensId, $this->$connection); $this->tempInstance = new Temp($this->sensId, $this->connection);
return $this->$tempInstance; return $this->tempInstance;
} }
function fill($contentId){ function fill($contentId){
$content_split = explode("_", $contentId); $content_split = explode("_", $contentId);
$callObject = call_user_method("_get_".$content_split[0], $this); $callObject = & call_user_method("_get_".$content_split[0], $this);
$funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0])); $funcName = "get".substr($contentId, strlen($content_split[0]), strlen($contentId)-strlen($content_split[0]));
echo "\n\naufruf: ".$funcName."()\n\n";
return $callObject->$funcName($content_split[1]); return $callObject->$funcName($content_split[1]);
} }

View File

@ -1,6 +1,7 @@
<? <?
include_once("php_inc/module.inc.php"); include_once("php_inc/module.inc.php");
include_once("php_inc/parser.inc.php"); include_once("php_inc/parser.inc.php");
include_once("php_inc/connection.inc.php");
/* Klasse, die die ModuleSets Verwaltet */ /* Klasse, die die ModuleSets Verwaltet */
@ -10,10 +11,9 @@ class ModuleSet{
/* Konstruktor */ /* Konstruktor */
function ModuleSet($setName){ function ModuleSet($setName){
$parser = $this->_getParserInstance(); /* Parserinstanz holen */ $parser = & $this->_getParserInstance(); /* Parserinstanz holen */
$parser->parseContent($this->_getSetFilename($setName), $this, NULL); /* Set Parsen */ $parser->parseContent($this->_getSetFilename($setName), &$this, NULL); /* Set Parsen */
echo "\n\n";
$parser->printContent(); $parser->printContent();
} }
@ -23,15 +23,17 @@ class ModuleSet{
} }
/* Parser Instanzieren (wenn noch nicht ist) und zurückgeben */ /* Parser Instanzieren (wenn noch nicht ist) und zurückgeben */
function _getParserInstance(){ function &_getParserInstance(){
if($this->$parserInstance==NULL) if($this->parserInstance==NULL)
$this->$parserInstance = new Parser(); $this->parserInstance = new Parser();
return $this->$parserInstance; return $this->parserInstance;
} }
function _getConnInstance(){ function &_getConnInstance(){
// TODO: Muss noch Implementiert werden!! if($connInstance == NULL){
return $connInstance; $this->connInstance = new Connection();
}
return $this->connInstance;
} }
/* Ein Modul hinzufügen */ /* Ein Modul hinzufügen */

View File

@ -1,6 +1,7 @@
<? <?
class Parser{ class Parser{
var $contentArray; var $contentArray;
var $ts = 0;
function Parser(){ function Parser(){
$this->contentArray = array(); $this->contentArray = array();
@ -14,9 +15,7 @@ class Parser{
function appendContent($newContent){ function appendContent($newContent){
if(is_array($newContent)){ if(is_array($newContent)){
for($i = 0; $i < count($newContent); $i++){ for($i = 0; $i < count($newContent); $i++){
echo "adding: ".$newContent[$i]."\n";
array_push($this->contentArray, $newContent[$i]); array_push($this->contentArray, $newContent[$i]);
echo "added: ".$this->contentArray[count($this->contentArray)-1]."\n";
} }
} else { } else {
array_push($this->contentArray, $newContent); array_push($this->contentArray, $newContent);
@ -25,28 +24,24 @@ class Parser{
/* Zeigt den Geparsten Inhalt an */ /* Zeigt den Geparsten Inhalt an */
function printContent(){ function printContent(){
echo "\n ---- Printing ----\n"; $array = $this->getContentArray();
echo "";
$array = &$this->getContentArray();
for ($i = 0; $i < count($array); $i++){ for ($i = 0; $i < count($array); $i++){
echo $array[$i]; echo $array[$i];
} }
} }
function parseContent($fileName, $callingObject, $filePart=null){ function parseContent($fileName, & $callingObject, $filePart=null){
echo "\n\nparse: ".$fileName."\n\n";
$fileArray = file($fileName); /* File als Array einlesen */ $fileArray = file($fileName); /* File als Array einlesen */
if($filePart != null){ if($filePart != null){
$fileArray = $this->_fetchFilePart(&$fileArray, $filePart); /* Wenn File aus mehreren Template-Teilen besteht, dann wird hir der relevante Zeil geholt */ $fileArray = $this->_fetchFilePart(&$fileArray, $filePart); /* Wenn File aus mehreren Template-Teilen besteht, dann wird hir der relevante Zeil geholt */
} }
for($i = 0; $i < count($fileArray); $i++){ /* Das Array durchlaufen ... */ for($i = 0; $i < count($fileArray); $i++){ /* Das Array durchlaufen ... */
echo "Zeile: ".$i." = ".$fileArray[$i]."\n";
if(0 != preg_match_all("/\{content:([a-z]+):([a-z0-9_]+)\}/i", $fileArray[$i], $results)){ if(0 != preg_match_all("/\{content:([a-z]+):([a-z0-9_]+)\}/i", $fileArray[$i], $results)){
//print_r($results); //print_r($results);
for($j = 0; $j < count($results[1]); $j++){ for($j = 0; $j < count($results[1]); $j++){
$callingObject->$results[1][$j]($results[2][$j]); $insert = $callingObject->$results[1][$j]($results[2][$j]);
//$fileArray[$i] = preg_replace("/\{content:fill:".$results[1][$j]."\}/i", $fileContents[$results[1][$j]], $fileArray[$i]); $fileArray[$i] = preg_replace("/\{content:".$results[1][$j].":".$results[2][$j]."\}/i", $insert, $fileArray[$i]);
} }
} }
} }