La solution facile est d'avoir une table competence_parent
competence_id
parent_id
Comme ca on peut setter plusieurs parents sur une competence donnee
competence_id
parent_id
Comme ca on peut setter plusieurs parents sur une competence donnee
Code PHP :
<?php
class Competence extends MySQL
{
private $id;
private $nb_point;
private $name;
private $level;
private $parent = array(); //Array de Competence
private $reached;
public function __construct($id = 0)
{
$this->table_name = 'competences';
if($id != 0)
{
$res = $this->selectOne(array('competence_id','=',$id));
$this->id = $res['competence_id'];
$this->nb_point = $res['nb_point'];
$this->name = $res['name'];
$this->level = $res['level'];
$this->reached = $res['reached'];
$this->setParents();
}
}
//Getters & setters.....
public function setParents()
{
$query = "SELECT parent_id FROM competence_parent WHERE competence_id = %d";
$res = $this->select(sprintf($query, $this->id));
foreach($res as $parent)
{
$this->parent[] = new Competence($parent['parent_id']);
}
}
public function isTakable()
{
foreach($this->parent as $requis)
{
$takable = false;
if($requis->getReached()) $takable = true;
}
return $takable;
}
}