diff options
Diffstat (limited to 'src/model/Model.php')
-rw-r--r-- | src/model/Model.php | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/model/Model.php b/src/model/Model.php index 9ada9a4..b3d157d 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -21,15 +21,15 @@ abstract class Model extends DB | |||
21 | } | 21 | } |
22 | 22 | ||
23 | // setters | 23 | // setters |
24 | public function setID(int $value = 0) | 24 | public function setId(int $value = 0) |
25 | { | 25 | { |
26 | if($value === 0) | 26 | if($value === 0) |
27 | { | 27 | { |
28 | $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence | 28 | $this->id = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence |
29 | } | 29 | } |
30 | else | 30 | else |
31 | { | 31 | { |
32 | $this->ID = $value; | 32 | $this->id = $value; |
33 | } | 33 | } |
34 | return $this; | 34 | return $this; |
35 | } | 35 | } |
@@ -202,7 +202,7 @@ abstract class Model extends DB | |||
202 | 202 | ||
203 | public function findById() // obtenir une entrée grace à son ID | 203 | public function findById() // obtenir une entrée grace à son ID |
204 | { | 204 | { |
205 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); | 205 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->id)->fetch()); |
206 | } | 206 | } |
207 | public function getDetailsByIdPresta() | 207 | public function getDetailsByIdPresta() |
208 | { | 208 | { |
@@ -214,7 +214,7 @@ abstract class Model extends DB | |||
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array | 217 | return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->id_presta)->fetch(); // type array |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
@@ -223,13 +223,13 @@ abstract class Model extends DB | |||
223 | $fields = []; | 223 | $fields = []; |
224 | $values = []; | 224 | $values = []; |
225 | 225 | ||
226 | // change "'ID' => 2" en "'ID' = ?" et "2" | 226 | // change "'id' => 2" en "'id' = ?" et "2" |
227 | foreach($criteria as $field => $value) | 227 | foreach($criteria as $field => $value) |
228 | { | 228 | { |
229 | $fields[] = "$field = ?"; // même chose que: $field . " = ?" | 229 | $fields[] = "$field = ?"; // même chose que: $field . " = ?" |
230 | $values[] = $value; | 230 | $values[] = $value; |
231 | } | 231 | } |
232 | $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND ID = ?' | 232 | $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND id = ?' |
233 | 233 | ||
234 | // SELECT * FROM annonces WHERE actif = 1; | 234 | // SELECT * FROM annonces WHERE actif = 1; |
235 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field_list, $values)->fetchAll()); | 235 | return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field_list, $values)->fetchAll()); |
@@ -252,7 +252,7 @@ abstract class Model extends DB | |||
252 | $values[] = $value; | 252 | $values[] = $value; |
253 | } | 253 | } |
254 | } | 254 | } |
255 | $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau | 255 | $values[] = $this->id; // cette syntaxe ajoute une valeur au tableau |
256 | $field_list = implode(', ', $fields); | 256 | $field_list = implode(', ', $fields); |
257 | 257 | ||
258 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? | 258 | // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? |
@@ -261,7 +261,7 @@ abstract class Model extends DB | |||
261 | 261 | ||
262 | public function updateOneValue(string $field, $value) | 262 | public function updateOneValue(string $field, $value) |
263 | { | 263 | { |
264 | return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->ID])); | 264 | return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->id])); |
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||