diff options
| -rw-r--r-- | src/model/entities/Client.php | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/model/entities/Client.php b/src/model/entities/Client.php index a81519a..e3ce4b0 100644 --- a/src/model/entities/Client.php +++ b/src/model/entities/Client.php | |||
| @@ -222,8 +222,6 @@ class Client | |||
| 222 | /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); | 222 | /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); |
| 223 | $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ | 223 | $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ |
| 224 | 224 | ||
| 225 | $Customer = new self; // se serait bien d'hériter d'EntityManager? | ||
| 226 | |||
| 227 | $input = exec($SearchCustomerForm->get()); | 225 | $input = exec($SearchCustomerForm->get()); |
| 228 | if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients | 226 | if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients |
| 229 | { | 227 | { |
| @@ -232,7 +230,7 @@ class Client | |||
| 232 | } | 230 | } |
| 233 | echo "debug: recherche effectuée\n"; | 231 | echo "debug: recherche effectuée\n"; |
| 234 | 232 | ||
| 235 | $MatchedObjects = self::search($input, $Customer); | 233 | $MatchedObjects = self::search($input); |
| 236 | if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! | 234 | if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! |
| 237 | { | 235 | { |
| 238 | $repository = self::$entityManager->getRepository('Client'); | 236 | $repository = self::$entityManager->getRepository('Client'); |
| @@ -251,35 +249,31 @@ class Client | |||
| 251 | $clients_array[] = get_object_vars($object); | 249 | $clients_array[] = get_object_vars($object); |
| 252 | } | 250 | } |
| 253 | 251 | ||
| 254 | $SearchCustomerResults->setListRows( | 252 | $SearchCustomerResults->setListRows($clients_array, count($clients_array[0])); |
| 255 | $clients_array, | ||
| 256 | //count($clients_array[$id])); | ||
| 257 | count($clients_array[0])); | ||
| 258 | 253 | ||
| 259 | // sélection parmi les résultats | 254 | // sélection parmi les résultats |
| 260 | $input = exec($SearchCustomerResults->get()); // renvoie l'id de la table 'clients' | 255 | $input = exec($SearchCustomerResults->get()); // renvoie l'id de la table 'clients' |
| 261 | if($input == '') | 256 | if($input == ''){ |
| 262 | { | ||
| 263 | echo "debug: client pas trouvé ou pas sélectionné\n"; | 257 | echo "debug: client pas trouvé ou pas sélectionné\n"; |
| 264 | return null; | 258 | return null; |
| 265 | } | 259 | } |
| 266 | |||
| 267 | echo "debug: client sélectionné\n"; | 260 | echo "debug: client sélectionné\n"; |
| 268 | //$Customer->setId($input); | 261 | |
| 269 | //$Customer->hydrate($Customer->findById()); | 262 | foreach($MatchedObjects as $object){ |
| 270 | $Customer = $MatchedObjects[$input]; | 263 | if((int)$input === $object->getId()){ |
| 271 | //var_dump($Customer); | 264 | return $object; |
| 272 | 265 | } | |
| 273 | return $Customer; | 266 | } |
| 267 | return null; | ||
| 274 | } | 268 | } |
| 275 | 269 | ||
| 276 | private static function search(string $input, Client $Customer): array | 270 | private static function search(string $input): array |
| 277 | { | 271 | { |
| 278 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre | 272 | $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre |
| 279 | return $Customer->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées | 273 | return self::findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées |
| 280 | } | 274 | } |
| 281 | 275 | ||
| 282 | private function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets | 276 | private static function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets |
| 283 | { | 277 | { |
| 284 | $results = []; | 278 | $results = []; |
| 285 | for($i = 0; $i < count($keywords); $i++) | 279 | for($i = 0; $i < count($keywords); $i++) |
| @@ -308,7 +302,6 @@ class Client | |||
| 308 | } | 302 | } |
| 309 | } | 303 | } |
| 310 | } | 304 | } |
| 311 | //var_dump($results); | ||
| 312 | return $results; | 305 | return $results; |
| 313 | } | 306 | } |
| 314 | } | 307 | } |
