diff options
Diffstat (limited to 'src/model/Model.php')
| -rw-r--r-- | src/model/Model.php | 25 |
1 files changed, 19 insertions, 6 deletions
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 | |||
| 19 | return $this->table; | 19 | return $this->table; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | public function getAll(): array | 22 | public function getAll(): array // à améliorer pour ne pas renvoyer $db et $table |
| 23 | { | 23 | { |
| 24 | return get_object_vars($this); // retourne les propriétés de l'objet | 24 | return get_object_vars($this); // retourne les propriétés de l'objet |
| 25 | } | 25 | } |
| @@ -29,7 +29,7 @@ abstract class Model extends DB | |||
| 29 | { | 29 | { |
| 30 | if($value === 0) | 30 | if($value === 0) |
| 31 | { | 31 | { |
| 32 | $this->ID = $this->db->lastInsertId(); // méthode de PDO (attention ne gère pas la concurence) | 32 | $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence |
| 33 | } | 33 | } |
| 34 | else | 34 | else |
| 35 | { | 35 | { |
| @@ -183,9 +183,22 @@ abstract class Model extends DB | |||
| 183 | return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! | 183 | return($this->execQuery('SELECT * FROM ' . $this->table)->fetchAll()); // fonctionne aussi sans le point virgule dans le SQL!! |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | public function findById(int $id) // obtenir une entrée avec son ID | 186 | public function findById() // obtenir une entrée avec son ID |
| 187 | { | 187 | { |
| 188 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $id)->fetch()); | 188 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); |
| 189 | } | ||
| 190 | public function getDetailsByIdPresta() | ||
| 191 | { | ||
| 192 | if($this->table == 'prestations') | ||
| 193 | { | ||
| 194 | // à l'occaz, rendre abstraite la classe Prestations | ||
| 195 | echo 'erreur: ne pas appeler Model::getDetailsByIdPresta() si la table ciblée est "prestations".'; | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | else | ||
| 199 | { | ||
| 200 | return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array | ||
| 201 | } | ||
| 189 | } | 202 | } |
| 190 | 203 | ||
| 191 | protected function find(array $criteria): array // obtenir une entrée avec un tableau associatif 'champ' => 'valeur' | 204 | 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 | |||
| 207 | 220 | ||
| 208 | 221 | ||
| 209 | // update UPDATE | 222 | // update UPDATE |
| 210 | public function update(int $id) // utiliser plutôt $this->ID ? | 223 | public function update() |
| 211 | { | 224 | { |
| 212 | $fields = []; | 225 | $fields = []; |
| 213 | $values = []; | 226 | $values = []; |
| @@ -219,7 +232,7 @@ abstract class Model extends DB | |||
| 219 | $values[] = $value; | 232 | $values[] = $value; |
| 220 | } | 233 | } |
| 221 | } | 234 | } |
| 222 | $values[] = $id; // cette syntaxe ajoute une valeur au tableau | 235 | $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau |
| 223 | $field_list = implode(', ', $fields); | 236 | $field_list = implode(', ', $fields); |
| 224 | 237 | ||
| 225 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? | 238 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? |
