. */ /* */ /*************************************************************************************/ require_once __DIR__ . "/../fonctions/autoload.php"; class Variable extends Baseobj { var $id; var $nom; var $valeur; var $protege; var $cache; const TABLE="variable"; var $table=self::TABLE; var $bddvars=array("id", "nom", "valeur", "protege", "cache"); function __construct($nom = ""){ parent::__construct(); if($nom != "") $this->charger($nom); } function charger($nom){ return $this->getVars("select * from $this->table where nom=\"$nom\""); } function charger_id($id){ return $this->getVars("select * from $this->table where id=\"$id\""); } /* * Pour obtenir la valeur d'une variable en un seul appel: Variable::lire("nomvariable") */ static $_cache = array(); public static function lire($nom, $defaut = "") { if (! isset(self::$_cache[$nom])) { $var = new Variable($nom); self::$_cache[$nom] = empty($var->id) ? $defaut : $var->valeur; } return self::$_cache[$nom]; } public function add() { unset(self::$_cache[$this->nom]); return parent::add(); } public function maj() { unset(self::$_cache[$this->nom]); return parent::maj(); } public function delete() { unset(self::$_cache[$this->nom]); parent::delete(); } /* * Pour mettre a jour la valeur d'une variable en un seul appel: Variable::ecrire("nomvariable", valeur) */ public static function ecrire($nom, $valeur, $creer_si_inexistante = false, $protege = 1, $cache = 1) { $var = new Variable($nom); if ($creer_si_inexistante && ! $var->charger($nom)) { $var->nom = $nom; $var->valeur = $valeur; $var->protege = $protege; $var->cache = $cache; $var->add(); } else { $var->valeur = $valeur; $var->maj(); } } } ?>