1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
<?php
// src/model/Clients.php
class Clients extends Model
{
// lecture des données ou hydratation
protected $ID; // auto-incrémentée
protected $prenom_nom;
protected $code_client;
protected $adresse;
protected $code_postal;
protected $ville;
protected $telephone;
protected $courriel;
protected $apropos;
protected $type = 'prospect';
public function __construct()
{
$this->table = strtolower(__CLASS__); // clients
}
// getters
public function getID(): int
{
return $this->ID;
}
public function getCodeClient(): string
{
return $this->code_client;
}
public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this)
{
return [
"Prénom Nom:" => $this->prenom_nom,
"Code client (J.C.Dusse):" => $this->code_client,
"Adresse:" => $this->adresse,
"Code postal:" => $this->code_postal,
"Ville:" => $this->ville,
"Telephone:" => $this->telephone,
"Courriel:" => $this->courriel,
"À propos:" => $this->apropos,
"Client ou Prospect?" => $this->type];
}
public function getSetterAndSet(string $entry, string $input)
{
switch($entry)
{
case "Prénom Nom:":
$this->setPrenomNom($input);
break;
case "Code client (J.C.Dusse):":
$this->setCodeClient($input);
break;
case "Adresse:":
$this->setAdresse($input);
break;
case "Code postal:":
$this->setCodePostal($input);
break;
case "Ville:":
$this->setVille($input);
break;
case "Telephone:":
$this->setTelephone($input);
break;
case "Courriel:":
$this->setCourriel($input);
break;
case "À propos:":
$this->setApropos($input);
break;
case "Client ou Prospect?":
$this->setType($input);
break;
}
}
// setters
public function setPrenomNom($value)
{
$this->prenom_nom = (string) $value;
return $this;
}
public function setCodeClient($value)
{
$this->code_client = (string) $value;
return $this;
}
public function setAdresse($value)
{
$this->adresse = (string) $value;
return $this;
}
public function setCodePostal($value)
{
$this->code_postal = (string) $value;
return $this;
}
public function setVille($value)
{
$this->ville = (string) $value;
return $this;
}
public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début
{
if(is_numeric($value))
{
$this->telephone = (string) $value;
}
else
{
$this->telephone = '';
echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n";
}
return $this;
}
public function setCourriel($value)
{
$this->courriel = (string) $value;
return $this;
}
public function setApropos($value)
{
$this->apropos = (string) $value;
return $this;
}
public function setType($value)
{
$this->type = (string) $value;
return $this;
}
public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite
{
$result = [];
for($i = 0; $i < count($keywords); $i++)
{
// tableau à deux dimensions obtenu pour un mot clé
$query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll();
foreach($query_result as $one_array) // pour chaque sous tableau
{
$already_exist = false;
for($j = 0; $j < count($result); $j++) // pour chaque tableau déjà enregistré dans le tableau $result
{
if($result[$j]['ID'] === $one_array['ID'])
{
$already_exist = true;
}
}
if(!$already_exist)
{
$result[] = $one_array;
}
}
}
return $result;
}
}
|