From 9ca2e7f3b212ca7434bb169f7c1b9ac0f8b2b22e Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 17 Jul 2026 23:04:59 +0200 Subject: param ?Client dans newService() et modifyData(), gitignore, config-template --- src/model/entities/Client.php | 12 ++++++------ src/sections/2_service.php | 10 ++++------ src/sections/3_modify_data.php | 11 ++++------- 3 files changed, 14 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/model/entities/Client.php b/src/model/entities/Client.php index 7dd3be6..a81519a 100644 --- a/src/model/entities/Client.php +++ b/src/model/entities/Client.php @@ -216,7 +216,7 @@ class Client return true; } - public static function getObject(ZenityEntry $SearchCustomerForm, ZenityList $SearchCustomerResults) // renvoie un Client ou 0 + public static function find(ZenityEntry $SearchCustomerForm, ZenityList $SearchCustomerResults): ?Client { // fenêtres /*$SearchCustomerForm = new ZenityEntry(ZenitySetup::$recherche_client_text); @@ -228,11 +228,11 @@ class Client if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients { echo "debug: recherche annulée ou saisie vide\n"; - return 0; + return null; } echo "debug: recherche effectuée\n"; - $MatchedObjects = self::searchCustomer($input, $Customer); + $MatchedObjects = self::search($input, $Customer); if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! { $repository = self::$entityManager->getRepository('Client'); @@ -241,7 +241,7 @@ class Client if(count($MatchedObjects) === 0) // toujours rien { echo "debug: aucun client dans la base de données\n"; - return 0; + return null; } } @@ -261,7 +261,7 @@ class Client if($input == '') { echo "debug: client pas trouvé ou pas sélectionné\n"; - return 0; + return null; } echo "debug: client sélectionné\n"; @@ -273,7 +273,7 @@ class Client return $Customer; } - private static function searchCustomer(string $input, Client $Customer): array + private static function search(string $input, Client $Customer): 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 diff --git a/src/sections/2_service.php b/src/sections/2_service.php index e25d677..9ebf303 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php @@ -3,9 +3,7 @@ // // -- SECTION 2: Prestation et devis -- -use Doctrine\ORM\EntityManager; - -function newService($Client): array // $Client est un Client ou null +function newService(?Client $Client = null): array { // fenêtres recherche d'un client $RechercheClient = new zenityEntry(ZenitySetup::$recherche_client['text']); @@ -25,11 +23,11 @@ function newService($Client): array // $Client est un Client ou null // -- partie 1: le client -- - if($Client == null || get_class($Client) !== 'Client') + if(!$Client) { - $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 + $Client = Client::find($RechercheClient, $ResultatsRechercheClient); // retourne un Client ou 0 //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction - if($Client === 0) + if(!$Client) { echo "debug: annulation sélection client\n"; return [0, null]; // menu principal diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php index 00fe220..607638b 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -5,9 +5,7 @@ require('3-1_windows.php'); -use Doctrine\ORM\EntityManager; - -function modifyData($Client): array +function modifyData(?Client $Client = null): array { // -- partie 1: rechercher un client -- @@ -19,12 +17,11 @@ function modifyData($Client): array $TypeDeClient = new ZenityList(ZenitySetup::$type_client['text'], ZenitySetup::$type_client['entrees']); $Calendrier = new ZenityCalendar(ZenitySetup::$calendar['section3']); - if($Client == null || get_class($Client) !== 'Client') // étape sautable + if(!$Client) { - $Client = Client::getObject($RechercheClient, $ResultatsRechercheClient); // = 0 ou type "Client" + $Client = Client::find($RechercheClient, $ResultatsRechercheClient); //$ResultatsRechercheClient->cleanCommand(); // inutile parce qu'on ne boucle pas dans cette fonction - //if(!is_object($Client) || !get_class($Client) == 'Client') - if($Client === 0) + if(!$Client) { echo "debug: annulation sélection client\n"; return [0, null]; // menu principal -- cgit v1.2.3