diff options
author | polo <ordipolo@gmx.fr> | 2022-12-28 05:19:55 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2022-12-28 05:19:55 +0100 |
commit | 1894fc377e6b938ea34df9980567a1634ec6ef48 (patch) | |
tree | 812db64208797ecbdabbc9673a5247fbc18ebf8b /src/model/Clients.php | |
parent | 7d564efbccc4b361d2fa2db2902fb35882304aae (diff) | |
download | AppliGestionPHP-1894fc377e6b938ea34df9980567a1634ec6ef48.zip |
réorganisation + bientôt finie la section 1
Diffstat (limited to 'src/model/Clients.php')
-rw-r--r-- | src/model/Clients.php | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/model/Clients.php b/src/model/Clients.php index 92a4b31..aeb39c1 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
@@ -4,20 +4,37 @@ | |||
4 | class Clients extends Model | 4 | class Clients extends Model |
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | public $ID; | 7 | protected $ID; // auto-incrémentée |
8 | public $prenom_nom; | 8 | protected $prenom_nom = ''; |
9 | public $adresse; | 9 | protected $code_client = ''; |
10 | public $code_client; | 10 | protected $adresse = ''; |
11 | public $commentaires; | 11 | protected $telephone = ''; |
12 | protected $courriel = ''; | ||
13 | protected $commentaires = ''; | ||
12 | 14 | ||
13 | use ModelChildren; // renseigne parent::table | 15 | use ModelChildren; // renseigne parent::table |
14 | 16 | ||
17 | public function __construct() | ||
18 | { | ||
19 | $this->table = 'clients'; | ||
20 | } | ||
21 | |||
15 | //~ public function set(string $variable, $value) | 22 | //~ public function set(string $variable, $value) |
16 | //~ { | 23 | //~ { |
17 | //~ $this->$variable = $value; | 24 | //~ $this->$variable = $value; |
18 | //~ return($this); | 25 | //~ return($this); |
19 | //~ } | 26 | //~ } |
20 | 27 | ||
28 | // getters | ||
29 | public function getID(): int | ||
30 | { | ||
31 | return $this->ID; | ||
32 | } | ||
33 | public function getCodeClient(): string | ||
34 | { | ||
35 | return $this->code_client; | ||
36 | } | ||
37 | |||
21 | // setters | 38 | // setters |
22 | public function setID(int $value) // inutile? il s'autoincrémente | 39 | public function setID(int $value) // inutile? il s'autoincrémente |
23 | { | 40 | { |
@@ -29,14 +46,27 @@ class Clients extends Model | |||
29 | $this->prenom_nom = $value; | 46 | $this->prenom_nom = $value; |
30 | return($this); | 47 | return($this); |
31 | } | 48 | } |
49 | public function setCode_client(string $value) | ||
50 | { | ||
51 | $this->code_client = $value; | ||
52 | return($this); | ||
53 | } | ||
32 | public function setAdresse(string $value) | 54 | public function setAdresse(string $value) |
33 | { | 55 | { |
34 | $this->adresse = $value; | 56 | $this->adresse = $value; |
35 | return($this); | 57 | return($this); |
36 | } | 58 | } |
37 | public function setCode_client(string $value) | 59 | public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
38 | { | 60 | { |
39 | $this->code_client = $value; | 61 | if(is_numeric($value)) |
62 | { | ||
63 | $this->telephone = $value; | ||
64 | } | ||
65 | return($this); | ||
66 | } | ||
67 | public function setCourriel(string $value) | ||
68 | { | ||
69 | $this->courriel = $value; | ||
40 | return($this); | 70 | return($this); |
41 | } | 71 | } |
42 | public function setCommentaires(string $value) | 72 | public function setCommentaires(string $value) |
@@ -48,12 +78,18 @@ class Clients extends Model | |||
48 | 78 | ||
49 | public function newRow(array $input) | 79 | public function newRow(array $input) |
50 | { | 80 | { |
51 | $this->hydrate(['prenom_nom' => $input[0], 'adresse' => $input[1], 'code_client' => $input[2], 'commentaires' => $input[3]]); | 81 | $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); |
52 | $this->create(); | 82 | $this->create(); |
53 | $this->setIdFromLastInsertID(); // dans ModelChildren, n'utilise pas Model::execQuery() | 83 | // ID obtenu par auto-incrémentation |
84 | $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
54 | } | 85 | } |
86 | //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée | ||
87 | //~ { | ||
88 | //~ $this->db = parent::getInstance(); // $db est créée dans Model::execQuery() | ||
89 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
90 | //~ } | ||
55 | 91 | ||
56 | public function findByKeywords(array $keywords, string $field): array | 92 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite |
57 | { | 93 | { |
58 | $result = []; | 94 | $result = []; |
59 | for($i = 0; $i < count($keywords); $i++) | 95 | for($i = 0; $i < count($keywords); $i++) |