1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
class ThemeTable
{
private $lastInsertId;
private $selectAll;
private $selectById;
private $insert;
private $update;
public function __construct ($bdd)
{
$this->lastInsertId = $bdd->prepare ("SELECT LAST_INSERT_ID() as id");
$this->lastInsertId ->setFetchMode(PDO::FETCH_ASSOC);
$this->selectAll = $bdd->prepare ("SELECT id_th, libelle_th, actif_th, ordre_th FROM table_theme ORDER BY ordre_th ASC");
$this->selectAll ->setFetchMode(PDO::FETCH_ASSOC);
$this->selectById = $bdd->prepare ("SELECT id_th, libelle_th, actif_th, ordre_th FROM table_theme WHERE id_th = ?");
$this->selectById ->setFetchMode(PDO::FETCH_ASSOC);
$this->insert = $bdd->prepare ("INSERT INTO table_theme (libelle_th, actif_th, ordre_th) VALUES (:libelle, :actif, :ordre)");
$this->insert ->setFetchMode(PDO::FETCH_ASSOC);
$this->update = $bdd->prepare ("UPDATE table_theme SET libelle_th = :libelle, actif_th = :actif, ordre_th = :ordre WHERE id_th = :id");
$this->update ->setFetchMode(PDO::FETCH_ASSOC);
}
public function lastInsertId ()
{
$this->lastInsertId->execute ();
$tab = $this->lastInsertId->fetch ();
return $tab["id"];
}
public function selectAll ()
{
$this->selectAll->execute ();
$tab = $this->selectAll->fetchAll();
$tableau = array ();
for ($i = 0; $i < count ($tab); $i++)
{
$object = new Theme($tab[$i]["libelle_th"], $tab[$i]["actif_th"], $tab[$i]["ordre_th"]);
$object->setId ($tab[$i]["id_th"]);
$tableau [$i] = $object;
}
return $tableau;
}
public function selectById ($aId)
{
$this->selectById->execute (array ($aId));
$tab = $this->selectById->fetchAll ();
$objet = new Theme($tab[0]["libelle_th"], $tab[0]["actif_th"], $tab[0]["ordre_th"]);
$objet->setId ($tab[0]["id_th"]);
return $objet;
}
public function insert ($aObject)
{
$this->insert->execute
( array( ":libelle" => $aObject->getLibelle (),
":actif" => $aObject->getActif (),
":ordre" => $aObject->getOrdre ()
));
$id = $this->lastInsertId();
$aObject->setId ($id);
return $aObject;
}
public function update ($aObject)
{
$this->update->execute
( array( ":id" => $aObject->getId (),
":libelle" => $aObject->getLibelle (),
":actif" => $aObject->getActif (),
":ordre" => $aObject->getOrdre ()
));
return $aObject;
} |
Partager