From 6f4cc3afffde36a13618458ffda72e6104624f36 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 30 Aug 2023 12:20:39 +0200 Subject: =?UTF-8?q?section=20client=20=C3=A0=20part,=20section=20modif=20e?= =?UTF-8?q?n=20cours,=20bug=20dans=20Dates,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Model.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/model/Model.php') diff --git a/src/model/Model.php b/src/model/Model.php index 3fb3bdf..4c4a80c 100644 --- a/src/model/Model.php +++ b/src/model/Model.php @@ -19,7 +19,7 @@ abstract class Model extends DB return $this->table; } - public function getAll(): array + public function getAll(): array // à améliorer pour ne pas renvoyer $db et $table { return get_object_vars($this); // retourne les propriétés de l'objet } @@ -29,7 +29,7 @@ abstract class Model extends DB { if($value === 0) { - $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) + $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence } else { @@ -183,9 +183,22 @@ abstract class Model extends DB return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! } - public function findById(int $id) // obtenir une entrée avec son ID + public function findById() // obtenir une entrée avec son ID { - return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $id)->fetch()); + return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); + } + public function getDetailsByIdPresta() + { + if($this->table == 'prestations') + { + // à l'occaz, rendre abstraite la classe Prestations + echo 'erreur: ne pas appeler Model::getDetailsByIdPresta() si la table ciblée est "prestations".'; + return 0; + } + else + { + return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array + } } protected function find(array $criteria): array // obtenir une entrée avec un tableau associatif 'champ' => 'valeur' @@ -207,7 +220,7 @@ abstract class Model extends DB // update UPDATE - public function update(int $id) // utiliser plutôt $this->ID ? + public function update() { $fields = []; $values = []; @@ -219,7 +232,7 @@ abstract class Model extends DB $values[] = $value; } } - $values[] = $id; // cette syntaxe ajoute une valeur au tableau + $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau $field_list = implode(', ', $fields); // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? -- cgit v1.2.3