summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/model/entities/Client.php93
-rw-r--r--src/model/entities/Prestation.php2
-rw-r--r--src/sections/2_service.php4
3 files changed, 38 insertions, 61 deletions
diff --git a/src/model/entities/Client.php b/src/model/entities/Client.php
index e3ce4b0..97951be 100644
--- a/src/model/entities/Client.php
+++ b/src/model/entities/Client.php
@@ -32,13 +32,6 @@ class Client
32 private string $type = 'prospect'; // valeur par défaut utilisée à l'instanciation, pas par doctrine 32 private string $type = 'prospect'; // valeur par défaut utilisée à l'instanciation, pas par doctrine
33 33
34 public static EntityManager $entityManager; 34 public static EntityManager $entityManager;
35
36 /*public function __construct()
37 {
38 global $entityManager;
39 self::$entityManager = $entityManager;
40 }*/
41
42 35
43 // getters 36 // getters
44 public function getId(): int 37 public function getId(): int
@@ -75,7 +68,7 @@ class Client
75 } 68 }
76 69
77 // setters 70 // setters
78 public function set(string $entry, string $input) 71 public function set(string $entry, string $input): void
79 { 72 {
80 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide 73 $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide
81 switch($entry) 74 switch($entry)
@@ -110,64 +103,58 @@ class Client
110 } 103 }
111 //self::$entityManager->flush(); 104 //self::$entityManager->flush();
112 } 105 }
113 public function setPrenomNom($value) 106 public function setPrenomNom(string $value): Client
114 { 107 {
115 $this->prenom_nom = (string) $value; 108 $this->prenom_nom = $value;
116 return $this; 109 return $this;
117 } 110 }
118 public function setCodeClient($value) 111 public function setCodeClient(string $value): Client
119 { 112 {
120 $this->code_client = (string) $value; 113 $this->code_client = $value;
121 return $this; 114 return $this;
122 } 115 }
123 public function setAdresse($value) 116 public function setAdresse(string $value): Client
124 { 117 {
125 $this->adresse = (string) $value; 118 $this->adresse = $value;
126 return $this; 119 return $this;
127 } 120 }
128 public function setCodePostal($value) 121 public function setCodePostal(string $value): Client
129 { 122 {
130 $this->code_postal = (string) $value; 123 $this->code_postal = $value;
131 return $this; 124 return $this;
132 } 125 }
133 public function setVille($value) 126 public function setVille(string $value): Client
134 { 127 {
135 $this->ville = (string) $value; 128 $this->ville = $value;
136 return $this; 129 return $this;
137 } 130 }
138 public function setTelephone($value) 131 public function setTelephone(string $value): Client
139 { 132 {
140 // type string parce que: 133 // type string parce que:
141 // - zenity renvoie une chaine 134 // - zenity renvoie une chaine
142 // - permet de garder le 0 au début et d'inscrire plusieurs numéros 135 // - permet de garder le 0 au début et d'inscrire plusieurs numéros
143 $this->telephone = (string) $value; 136 $this->telephone = $value;
144 return $this; 137 return $this;
145 } 138 }
146 public function setCourriel($value) 139 public function setCourriel(string $value): Client
147 { 140 {
148 $this->courriel = (string) $value; 141 $this->courriel = $value;
149 return $this; 142 return $this;
150 } 143 }
151 public function setApropos($value) 144 public function setApropos(string $value): Client
152 { 145 {
153 $this->apropos = (string) $value; 146 $this->apropos = $value;
154 return $this; 147 return $this;
155 } 148 }
156 public function setType($value) 149 public function setType(string $value): Client
157 { 150 {
158 $this->type = (string) $value; 151 if($this->type !== $value){
159 return $this; 152 $this->type = $value;
160 }
161
162 public function typeToClient()
163 {
164 if($this->type != 'client')
165 {
166 $this->type = 'client';
167 } 153 }
154 return $this;
168 } 155 }
169 156
170 private function setAll(array $input) 157 private function setAll(array $input): void
171 { 158 {
172 $this->prenom_nom = $input[0]; 159 $this->prenom_nom = $input[0];
173 $this->code_client = $input[1]; 160 $this->code_client = $input[1];
@@ -191,20 +178,17 @@ class Client
191 public function enterCustomer(ZenityForms $Form): bool 178 public function enterCustomer(ZenityForms $Form): bool
192 { 179 {
193 $input = exec($Form->get()); 180 $input = exec($Form->get());
194 if($input == '') 181 if($input == ''){
195 {
196 echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; 182 echo "debug: annulation lors de l'enregistrement d'un nouveau client\n";
197 return false; 183 return false;
198 } 184 }
199 185
200 $data_array = explode('|', $input); // array 186 $data_array = explode('|', $input); // array
201 if($data_array[0] == '') 187 if($data_array[0] == ''){
202 {
203 echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; 188 echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n";
204 return false; 189 return false;
205 } 190 }
206 else 191 else{
207 {
208 $this->setAll($data_array); 192 $this->setAll($data_array);
209 } 193 }
210 194
@@ -223,29 +207,25 @@ class Client
223 $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ 207 $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/
224 208
225 $input = exec($SearchCustomerForm->get()); 209 $input = exec($SearchCustomerForm->get());
226 if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients 210 if($input == ''){ // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients
227 {
228 echo "debug: recherche annulée ou saisie vide\n"; 211 echo "debug: recherche annulée ou saisie vide\n";
229 return null; 212 return null;
230 } 213 }
231 echo "debug: recherche effectuée\n"; 214 echo "debug: recherche effectuée\n";
232 215
233 $MatchedObjects = self::search($input); 216 $MatchedObjects = self::search($input);
234 if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! 217 if(count($MatchedObjects) === 0){ // si aucun client ne correspond, les prendre tous!
235 {
236 $repository = self::$entityManager->getRepository('Client'); 218 $repository = self::$entityManager->getRepository('Client');
237 $MatchedObjects = $repository->findAll(); 219 $MatchedObjects = $repository->findAll();
238 220
239 if(count($MatchedObjects) === 0) // toujours rien 221 if(count($MatchedObjects) === 0){ // toujours rien
240 {
241 echo "debug: aucun client dans la base de données\n"; 222 echo "debug: aucun client dans la base de données\n";
242 return null; 223 return null;
243 } 224 }
244 } 225 }
245 226
246 $clients_array = []; 227 $clients_array = [];
247 foreach($MatchedObjects as $object) // d'objets en tableaux 228 foreach($MatchedObjects as $object){ // d'objets en tableaux
248 {
249 $clients_array[] = get_object_vars($object); 229 $clients_array[] = get_object_vars($object);
250 } 230 }
251 231
@@ -276,28 +256,23 @@ class Client
276 private static function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets 256 private static function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets
277 { 257 {
278 $results = []; 258 $results = [];
279 for($i = 0; $i < count($keywords); $i++) 259 for($i = 0; $i < count($keywords); $i++){
280 {
281 // tableau à deux dimensions obtenu pour un mot clé 260 // tableau à deux dimensions obtenu pour un mot clé
282 //$query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll(); 261 //$query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll();
283 $query = self::$entityManager->createQuery('SELECT u FROM Client u WHERE u.' . $field . ' LIKE :expression'); 262 $query = self::$entityManager->createQuery('SELECT u FROM Client u WHERE u.' . $field . ' LIKE :expression');
284 $query->setParameter('expression', '%' . $keywords[$i] . '%'); 263 $query->setParameter('expression', '%' . $keywords[$i] . '%');
285 $query_result = $query->getResult(); 264 $query_result = $query->getResult();
286 265
287 foreach($query_result as $object) 266 foreach($query_result as $object){
288 {
289 $id = $object->getId(); 267 $id = $object->getId();
290 $already_exist = false; 268 $already_exist = false;
291 //for($j = 0; $j < count($results); $j++) 269 //for($j = 0; $j < count($results); $j++)
292 foreach($results as $one_result) // pour chaque tableau déjà enregistré dans le tableau $results 270 foreach($results as $one_result){ // pour chaque tableau déjà enregistré dans le tableau $results
293 { 271 if($one_result->getId() === $id){
294 if($one_result->getId() === $id)
295 {
296 $already_exist = true; 272 $already_exist = true;
297 } 273 }
298 } 274 }
299 if(!$already_exist) 275 if(!$already_exist){
300 {
301 $results[$id] = $object; 276 $results[$id] = $object;
302 } 277 }
303 } 278 }
diff --git a/src/model/entities/Prestation.php b/src/model/entities/Prestation.php
index ce98911..ee9b3c0 100644
--- a/src/model/entities/Prestation.php
+++ b/src/model/entities/Prestation.php
@@ -40,7 +40,7 @@ class Prestation
40 public static EntityManager $entityManager; 40 public static EntityManager $entityManager;
41 41
42 42
43 public function __construct(Client $client = null) 43 public function __construct(?Client $client = null)
44 { 44 {
45 if($client != null) 45 if($client != null)
46 { 46 {
diff --git a/src/sections/2_service.php b/src/sections/2_service.php
index 9ebf303..9269503 100644
--- a/src/sections/2_service.php
+++ b/src/sections/2_service.php
@@ -132,7 +132,9 @@ function newService(?Client $Client = null): array
132 if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue 132 if($choix_niv2 != ZenitySetup::$menu_enregistrement['entrees'][5]) // cas: tous les cas sauf presta non vendue
133 { 133 {
134 //var_dump($answers); 134 //var_dump($answers);
135 $Client->typeToClient(); 135 if($Presta->getTypePresta() !== 'devis'){
136 $Client->setType('client');
137 }
136 if($answers == '') // annulation 138 if($answers == '') // annulation
137 { 139 {
138 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n"; 140 echo "debug: annulation lors de l'enregistrement des détails de la prestation\n";