Accueil/class/ClockAdvanced.php

130 lines
3.6 KiB
PHP
Raw Normal View History

2010-09-20 10:44:44 +02:00
<?php
2010-09-20 11:40:27 +02:00
class clockAdvanced extends Module {
protected static $paramsList = array(
2010-09-20 10:44:44 +02:00
'visibility',
'x',
'y',
'fontFamily',
'fontSize',
'format',
'color'
);
public $params = array();
public function __construct($params){
$this->setParams($params);
echo '<script type="text/javascript" src="js/jquery.jclockAdvanced.js"></script>';
echo '<div class="jclockAdvanced" id="clockAdvanced" style="left:'.$params['x'].'; top:'.$params['y'].';"></div>';
$options = '';
foreach (self::$paramsList as $paramName){
if(isset($this->params[$paramName]))
$options .= $paramName.' : "'.$this->params[$paramName].'",';
2010-09-20 10:44:44 +02:00
}
echo '<script>$(document).ready(function(){
$(\'#fontFamily\').val("'.$params['fontFamily'].'");
$(\'#fontSize\').val("'.$params['fontSize'].'");
$(\'#format\').val("'.$params['format'].'");
$(\'#color\').val("'.$params['color'].'");
2010-09-20 10:44:44 +02:00
$(\'.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";
}
2010-09-20 11:40:27 +02:00
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);
}
}
2010-09-20 11:40:27 +02:00
}
2010-09-20 10:44:44 +02:00
}