From a8a6c6178efc97247c4859e183e4360f52d8893e Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 17 Jul 2026 23:42:29 +0200 Subject: =?UTF-8?q?bug=20s=C3=A9lection=20d'un=20client=20quand=20recherch?= =?UTF-8?q?e=20avec=20mot=20cl=C3=A9=20non=20trouv=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Client.php | 33 +++++++++++++-------------------- 1 file 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 /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ - $Customer = new self; // se serait bien d'hériter d'EntityManager? - $input = exec($SearchCustomerForm->get()); if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients { @@ -232,7 +230,7 @@ class Client } echo "debug: recherche effectuée\n"; - $MatchedObjects = self::search($input, $Customer); + $MatchedObjects = self::search($input); if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! { $repository = self::$entityManager->getRepository('Client'); @@ -251,35 +249,31 @@ class Client $clients_array[] = get_object_vars($object); } - $SearchCustomerResults->setListRows( - $clients_array, - //count($clients_array[$id])); - count($clients_array[0])); + $SearchCustomerResults->setListRows($clients_array, count($clients_array[0])); // sélection parmi les résultats $input = exec($SearchCustomerResults->get()); // renvoie l'id de la table 'clients' - if($input == '') - { + if($input == ''){ echo "debug: client pas trouvé ou pas sélectionné\n"; return null; } - echo "debug: client sélectionné\n"; - //$Customer->setId($input); - //$Customer->hydrate($Customer->findById()); - $Customer = $MatchedObjects[$input]; - //var_dump($Customer); - - return $Customer; + + foreach($MatchedObjects as $object){ + if((int)$input === $object->getId()){ + return $object; + } + } + return null; } - private static function search(string $input, Client $Customer): array + private static function search(string $input): array { $input_array = explode(' ', $input); // si plusieurs mot, on les recherche tous l'un après l'autre - return $Customer->findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées + return self::findByKeywords($input_array, 'prenom_nom'); // on obtient un tableau à deux dimensions avec les entrées trouvées } - private function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets + private static function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets { $results = []; for($i = 0; $i < count($keywords); $i++) @@ -308,7 +302,6 @@ class Client } } } - //var_dump($results); return $results; } } -- cgit v1.2.3