diff options
Diffstat (limited to 'src/model/Clients.php')
-rw-r--r-- | src/model/Clients.php | 65 |
1 files changed, 27 insertions, 38 deletions
diff --git a/src/model/Clients.php b/src/model/Clients.php index aeb39c1..9661562 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
@@ -5,18 +5,18 @@ class Clients extends Model | |||
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | protected $ID; // auto-incrémentée | 7 | protected $ID; // auto-incrémentée |
8 | protected $prenom_nom = ''; | 8 | protected $prenom_nom; |
9 | protected $code_client = ''; | 9 | protected $code_client; |
10 | protected $adresse = ''; | 10 | protected $adresse; |
11 | protected $telephone = ''; | 11 | protected $telephone; |
12 | protected $courriel = ''; | 12 | protected $courriel; |
13 | protected $commentaires = ''; | 13 | protected $commentaires; |
14 | 14 | ||
15 | use ModelChildren; // renseigne parent::table | 15 | use ModelChildren; // pour hydrateFromForm() |
16 | 16 | ||
17 | public function __construct() | 17 | public function __construct() |
18 | { | 18 | { |
19 | $this->table = 'clients'; | 19 | $this->table = 'clients'; // à mettre dans ModelChildren |
20 | } | 20 | } |
21 | 21 | ||
22 | //~ public function set(string $variable, $value) | 22 | //~ public function set(string $variable, $value) |
@@ -36,59 +36,48 @@ class Clients extends Model | |||
36 | } | 36 | } |
37 | 37 | ||
38 | // setters | 38 | // setters |
39 | public function setID(int $value) // inutile? il s'autoincrémente | 39 | //~ public function setID() -> dans le trait ModelChildren |
40 | { | 40 | |
41 | $this->ID = $value; | 41 | public function setPrenomNom($value) |
42 | return($this); | ||
43 | } | ||
44 | public function setPrenom_nom(string $value) | ||
45 | { | 42 | { |
46 | $this->prenom_nom = $value; | 43 | $this->prenom_nom = (string) $value; |
47 | return($this); | 44 | return($this); |
48 | } | 45 | } |
49 | public function setCode_client(string $value) | 46 | public function setCodeClient($value) |
50 | { | 47 | { |
51 | $this->code_client = $value; | 48 | $this->code_client = (string) $value; |
52 | return($this); | 49 | return($this); |
53 | } | 50 | } |
54 | public function setAdresse(string $value) | 51 | public function setAdresse($value) |
55 | { | 52 | { |
56 | $this->adresse = $value; | 53 | $this->adresse = (string) $value; |
57 | return($this); | 54 | return($this); |
58 | } | 55 | } |
59 | public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début | 56 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
60 | { | 57 | { |
61 | if(is_numeric($value)) | 58 | if(is_numeric($value)) |
62 | { | 59 | { |
63 | $this->telephone = $value; | 60 | $this->telephone = (string) $value; |
61 | } | ||
62 | else | ||
63 | { | ||
64 | $this->telephone = ''; | ||
65 | echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; | ||
64 | } | 66 | } |
65 | return($this); | 67 | return($this); |
66 | } | 68 | } |
67 | public function setCourriel(string $value) | 69 | public function setCourriel($value) |
68 | { | 70 | { |
69 | $this->courriel = $value; | 71 | $this->courriel = (string) $value; |
70 | return($this); | 72 | return($this); |
71 | } | 73 | } |
72 | public function setCommentaires(string $value) | 74 | public function setCommentaires($value) |
73 | { | 75 | { |
74 | $this->commentaires = $value; | 76 | $this->commentaires = (string) $value; |
75 | return($this); | 77 | return($this); |
76 | } | 78 | } |
77 | 79 | ||
78 | 80 | ||
79 | public function newRow(array $input) | ||
80 | { | ||
81 | $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); | ||
82 | $this->create(); | ||
83 | // ID obtenu par auto-incrémentation | ||
84 | $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
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 | //~ } | ||
91 | |||
92 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite | 81 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite |
93 | { | 82 | { |
94 | $result = []; | 83 | $result = []; |