Accueil/modules/weather/Weather.php

104 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2010-09-20 11:40:27 +02:00
class weather extends Module {
2010-09-27 12:48:53 +02:00
protected $moduleName;
protected $moduleTitle;
protected $pathToModule;
2010-09-20 11:40:27 +02:00
protected static $paramsList = array(
2010-09-15 23:36:14 +02:00
'visibility',
'city',
'x',
'y'
);
2010-09-20 11:40:27 +02:00
public $params = array();
2010-09-15 23:36:14 +02:00
public function __construct($params){
2010-09-27 12:48:53 +02:00
$this->moduleName = get_class();
$this->pathToModule = 'modules/'.$this->moduleName.'/';
2010-09-20 11:40:27 +02:00
$this->setParams($params);
2010-09-17 15:38:57 +02:00
$ville = $params['city'];
2010-09-27 12:48:53 +02:00
include $this->pathToModule.'includes/GoogleMeteo.php';
echo '<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">';
echo '<div id="weather" style="left:'.$params['x'].'; top:'.$params['y'].';">
2010-09-17 15:38:57 +02:00
'.$city.'<br/>
<div class="weatherpic"></div>
<strong>'.$present_weather.'</strong><br/>
'.$future_weather1.'<br/>
'.$future_weather2.'
</div>';
}
2010-09-15 23:36:14 +02:00
2010-09-20 11:40:27 +02:00
private function setParams($params){
$this->params = $params;
}
2010-09-15 23:36:14 +02:00
public static function start($params){
$weather = new weather($params);
}
2010-09-15 23:36:14 +02:00
/**
*
* Modifie la ville
* @param String $city la ville.
* @return String "ok" ou message d'erreur (effectue aussi l'enregistrement en XML)
*/
public function setCity($city){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->city = $city;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setX($x){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->x = $x;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setY($y){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->y = $y;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setVisibility($visibility){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->visibility = $visibility;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public static function updateConfig($updated){
foreach ($updated as $what=>$withWhat){
if(in_array($what, self::$paramsList)){
call_user_func(array(get_class(), "set".ucfirst($what)), $withWhat);
}
}
}
}