13-12-2006, 08:17 AM
voici les fichiers en cause:
class planete_ressource_db.class.php
class planete_ressource_db.class.php
Code PHP :
<?php
class planete_ressource_db
{
protected $element = "";
protected $value = "";
function __construct($db='')
{
if ($db == '')
{
global $db_exploit;
$db = $db_exploit;
}
$this->db = $db;
$this->id_planete = "NULL";
$this->id_ressource = "NULL";
$this->valeur = "NULL";
$this->croissanceactuelle = "NULL";
$this->timestamp = "NULL";
}
function __get($element)
{
switch($element)
{
case 'id_planete':
return $this->id_planete;
case 'id_ressource':
return $this->id_ressource;
case 'valeur':
return $this->valeur;
case 'croissanceactuelle':
return $this->croissanceactuelle;
case 'timestamp':
return $this->timestamp;
}
}
function check () //valide que tout est bon pour insérer en base
{
if ($this->id_planete != "NULL")
{
if ($this->id_ressource != "NULL")
{
if ($this->valeur != "NULL")
{
if ($this->croissanceactuelle != "NULL")
{
if ($this->timestamp != "NULL")
{
$response = "1";
}
}
}
}
}
return $response;
}
/**
* initialise les données en base
*/
protected function initialize ()
{
$contenu="SELECT croissance FROM `tbl_ressource` WHERE `id_ressource`=".$this->id_ressource." ";
$res = $this->db->query($contenu);
$table = $this->db->getObject($res);
$this->valeur=$table->croissance;
$this->croissanceactuelle=$table->croissance;
$this->timestamp=time();
$contenu="INSERT INTO `tbl_planete_ressource` VALUES ('".$this->id_planete."','".$this->id_ressource."','".$this->valeur."','".$this->croissanceactuelle."','".$this->timestamp."')";
$res = $this->db->query($contenu);
}
/**
* charge un élement depuis la base en se reposant sur son "id"
*/
function load ($id_planete,$id_ressource)
{
$res = $this->db->query("SELECT * FROM tbl_planete_ressource WHERE id_planete = '".$this->id_planete."' AND id_ressource = '".$this->id_ressource."'");
if ($this->db->sql_num_res[$res] != "0")
{
$table = $this->db->getObject($res);
$this->id_planete = $table->id_planete;
$this->id_ressource = $table->id_ressource;
$this->valeur = $table->valeur;
$this->croissanceactuelle = $table->croissanceactuelle;
$this->timestamp = $table->timestamp;
}
else
{
return "false";
}
}
?>
et
planete_ressource.class.php
Code PHP :
<?php
/* chemin relatif vers les classes à tester*/
$path_to_classes = '../model/';
/**
* inclusion de la classe mère
*/
require_once($path_to_classes . 'planete_ressource.db.class.php');
/**
* classe de gestion des ressources.
*/
class planete_ressource extends planete_ressource_db
{
protected $id_planete = "NULL";
protected $id_ressource = "NULL";
protected $valeur = "NULL";
protected $croissanceactuelle = "NULL";
protected $timestamp = "NULL";
/**
* constructeur de la ressource
*/
function __construct($db='',$id_planete,$id_ressource)
{
if ($db == '')
{
global $db_exploit;
$db = $db_exploit;
}
$this->db=$db;
parent::__construct($db);
$test=parent::load($id_planete,$id_ressource);
if ($test == "false")
{
parent::initialize();
}
}
}
?>