Amélioration de l'organisation du code : la classe principale "Module" est maintenant prête et les modules l'ont bien étendue.

This commit is contained in:
Chouchen
2010-10-05 15:30:04 +00:00
parent ac017b84e9
commit 759a5556cc
25 changed files with 236 additions and 706 deletions

View File

@@ -1,5 +1,6 @@
<?php
class clockAdvanced extends Module {
protected $moduleTitle = 'Horloge Avancée';
protected static $paramsList = array(
'visibility',
'x',
@@ -10,124 +11,26 @@ class clockAdvanced extends Module {
'color'
);
public $params = array();
public function __construct($params){
$this->moduleName = get_class();
$this->pathToModule = 'modules/'.$this->moduleName.'/';
$this->setParams($params);
parent::__construct(__CLASS__, $params);
}
public function build(){
echo '<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
<link rel="stylesheet" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css" type="text/css" />';
echo '<div class="jclockAdvanced" id="clockAdvanced" style="left:'.$params['x'].'; top:'.$params['y'].';"></div>';
echo '<div class="jclockAdvanced" id="clockAdvanced" style="left:'.$this->getParam('x').'; top:'.$this->getParam('y').';"></div>';
$options = '';
foreach (self::$paramsList as $paramName){
if(isset($this->params[$paramName]))
$options .= $paramName.' : "'.$this->params[$paramName].'",';
if($this->getParam($paramName) != null)
$options .= $paramName.' : "'.$this->getParam($paramName).'",';
}
echo '<script>$(document).ready(function(){
$(\'#fontFamily\').val("'.$params['fontFamily'].'");
$(\'#fontSize\').val("'.$params['fontSize'].'");
$(\'#format\').val("'.$params['format'].'");
$(\'#color\').val("'.$params['color'].'");
$(\'#fontFamily\').val("'.$this->getParam('fontFamily').'");
$(\'#fontSize\').val("'.$this->getParam('fontSize').'");
$(\'#format\').val("'.$this->getParam('format').'");
$(\'#color\').val("'.$this->getParam('color').'");
$(\'.jclockAdvanced\').jclock({'.substr($options,0,-1).'});
});
</script>';
}
private function setParams($params){
$this->params = $params;
}
public static function start($params){
$clockAdvanced = new clockAdvanced($params);
}
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='clockAdvanced']");
$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='clockAdvanced']");
$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='clockAdvanced']");
$path[0]->visibility = $visibility;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setFontFamily($fontFamily){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='clockAdvanced']");
$path[0]->fontFamily = $fontFamily;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setFontSize($fontSize){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='clockAdvanced']");
$path[0]->fontSize = $fontSize;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setColor($color){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='clockAdvanced']");
$path[0]->color = $color;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setFormat($format){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='clockAdvanced']");
$path[0]->format = $format;
$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);
}
}
}
}