Working on Frontend

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@24 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-08-16 10:59:36 +00:00
parent 162879454a
commit 4249404692
4 changed files with 59 additions and 17 deletions

View File

@ -1,23 +1,23 @@
<h3 class="mod_headline">Temparatur - {content:fill:pre:location}</h3> <h3 class="mod_headline">Temparatur - {content:fill:sens_location}</h3>
<p class="mod_description">{content:fill:pre: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>
<td>Momentan:</td><td>{content:fill:pre:temp_now_val}</td><td>{content:fill:pre:temp_now_date}</td> <td>Momentan:</td><td>{content:fill:temp_now_val}</td><td>{content:fill:temp_now_date}</td>
</tr> </tr>
<tr> <tr>
<td>Durchschnitt (halbe std.):</td><td>{content:fill:pre:temp_av_value}</td><td>&nbsp;</td> <td>Durchschnitt (halbe std.):</td><td>{content:fill:temp_av_value}</td><td>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td>Tendenz (2 std.):</td><td>{content:fill:pre:temp_changing}</td><td>&nbsp;</td> <td>Tendenz (2 std.):</td><td>{content:fill:temp_changing}</td><td>&nbsp;</td>
</tr> </tr>
</table> </table>
<h4>Extrema</h4> <h4>Extrema</h4>
<table> <table>
<tr> <tr>
<td>Max:</td><td>{content:fill:pre:temp_max_val}</td><td>{content:fill:pre:temp_max_date}</td> <td>Max:</td><td>{content:fill:temp_max_val}</td><td>{content:fill:temp_max_date}</td>
</tr> </tr>
<tr> <tr>
<td>Min:</td><td>{content:fill:pre:temp_min_val}</td><td>{content:fill:pre:temp_min_date}</td> <td>Min:</td><td>{content:fill:temp_min_val}</td><td>{content:fill:temp_min_date}</td>
</tr> </tr>
</table> </table>

View File

@ -1,22 +1,50 @@
<? <?
include_once("php_inc/parser.inc.php"); include_once("php_inc/parser.inc.php");
include_once("php_inc/sensor.inc.php");
include_once("php_inc/temp.inc.php");
class Module{ class Module{
var $sensId; /* Sensor-Id */
var $connection; /* Connection - Instanz */
var $parserInstance = NULL; /* Parser - Instanz */ var $parserInstance = NULL; /* Parser - Instanz */
var $connectionInstance = NULL; /* Connection - Instanz */ var $connectionInstance = NULL; /* Connection - Instanz */
var $sensInstance = NULL; /* Sensor-Instanz */
var $tempInstance = NULL; /* Temp-Instanz */
function Module($modName, $sensId, $parser, $connection){ function Module($modName, $sensId, $parser, $connection){
$parser->parseContent($this->_getModuleFilename($modName)); $this->$sensId = $sensId;
$this->$connection = $connection;
$parser->parseContent($this->_getModuleFilename("frame"), $this, "top");
$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(){
if($sensInstance == NULL)
$this->$sensInstance = new Sensor($this->$sensId, $this->$connection);
return $this->$sensInstance;
}
function _get_temp(){
if($tempInstance == NULL)
$this->$tempInstance = new Temp($this->$sensId, $this->$connection);
return $this->$tempInstance;
} }
function fill($contentId){ function fill($contentId){
$content_split = explode("_", $contentId); $content_split = explode("_", $contentId);
return $this->"get".$content_split[0]($content_split[1]) $callObject = call_user_method("_get_".$content_split[0], $this);
$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]);
} }
} }

View File

@ -12,6 +12,9 @@ class ModuleSet{
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();
} }
/* Dateinamen eines Setz aus dessen Namen zusammenbauen */ /* Dateinamen eines Setz aus dessen Namen zusammenbauen */
@ -21,15 +24,20 @@ 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)
$parserInstance = new Parser(); $this->$parserInstance = new Parser();
return $parserInstance; return $this->$parserInstance;
}
function _getConnInstance(){
// TODO: Muss noch Implementiert werden!!
return $connInstance;
} }
/* Ein Modul hinzufügen */ /* Ein Modul hinzufügen */
function _addModule($modName){ function addModule($modName){
$params = explode("_",$modName); /* Modulname und Sensorid trennen */ $params = explode("_",$modName); /* Modulname und Sensorid trennen */
include("content/modules/mod_".$params[0].".html"); new Module($params[0], $params[1], $this->_getParserInstance(), $this->_getConnInstance());
} }
} }
?> ?>

View File

@ -14,7 +14,9 @@ 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);
@ -23,6 +25,8 @@ class Parser{
/* Zeigt den Geparsten Inhalt an */ /* Zeigt den Geparsten Inhalt an */
function printContent(){ function printContent(){
echo "\n ---- Printing ----\n";
echo "";
$array = &$this->getContentArray(); $array = &$this->getContentArray();
for ($i = 0; $i < count($array); $i++){ for ($i = 0; $i < count($array); $i++){
echo $array[$i]; echo $array[$i];
@ -31,20 +35,22 @@ class Parser{
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]); $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:fill:".$results[1][$j]."\}/i", $fileContents[$results[1][$j]], $fileArray[$i]);
} }
} }
} }
//$this->appendContent($fileArray); $this->appendContent($fileArray);
} }