Accueil/class/Todo.php

112 lines
2.9 KiB
PHP
Raw Normal View History

<?php
2010-09-20 11:40:27 +02:00
class todo extends Module {
protected static $paramsList = array(
'visibility',
'x',
'y'
);
public $params = array();
private $persistance = 'db/todoist.xml';
private $token;
private $project_name;
private $project_id;
public function __construct($params){
$this->setParams($params);
echo '<link rel="stylesheet" type="text/css" href="css/todo.css">';
if($xmla = simplexml_load_file($this->persistance)){
$this->setToken($xmla->token);
$this->setProjectName($xmla->name);
$this->setProjectId($xmla->id);
echo '<div id="todo" style="top:'.$params['y'].'; left :'.$params['x'].';">';
if($this->token == null || $this->project_id == null)
echo 'Impossible de trouver votre configuration. <a href="install-todoist.php">Cliquez ici</a> pour la mettre en place.</div>';
else{
$token = $xmla->token;
$id = $xmla->id;
echo '</div><script type="text/javascript" src="js/getUncompletedTasks.php?token='.$token.'&id='.$id.'"></script>';
}
2010-09-17 15:38:57 +02:00
echo '<script>
$(document).ready(function(){
$(\'#todo\').resizable();
2010-09-17 15:38:57 +02:00
});</script>';
}else{
echo 'baaaaad persistance...';
}
}
private function setToken($token){
if($token == '' || $token == null)
$this->token = null;
else
$this->token = $token;
}
private function setProjectName($name){
if($name == '' || $name == null)
$this->project_name = null;
else
$this->project_name = $name;
}
private function setProjectId($id){
if($id == '' || $id == null)
$this->project_id = null;
else
$this->project_id = $id;
}
private function setParams($params){
$this->params = $params;
}
public static function start($params){
$todo = new todo($params);
}
2010-09-20 11:40:27 +02:00
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='todo']");
$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='todo']");
$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='todo']");
$path[0]->visibility = $visibility;
$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
}
}