From f2f5560339203baad7951006c5a63d10f237ee6a Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 9 Oct 2026 16:12:46 +0200 Subject: =?UTF-8?q?cr=C3=A9er=20un=20devis=20ne=20fait=20plus=20d'un=20pro?= =?UTF-8?q?spect=20un=20client,=20typage=20dans=20Client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Client.php | 93 ++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 59 deletions(-) (limited to 'src/model/entities/Client.php') 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 private string $type = 'prospect'; // valeur par défaut utilisée à l'instanciation, pas par doctrine public static EntityManager $entityManager; - - /*public function __construct() - { - global $entityManager; - self::$entityManager = $entityManager; - }*/ - // getters public function getId(): int @@ -75,7 +68,7 @@ class Client } // setters - public function set(string $entry, string $input) + public function set(string $entry, string $input): void { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide switch($entry) @@ -110,64 +103,58 @@ class Client } //self::$entityManager->flush(); } - public function setPrenomNom($value) + public function setPrenomNom(string $value): Client { - $this->prenom_nom = (string) $value; + $this->prenom_nom = $value; return $this; } - public function setCodeClient($value) + public function setCodeClient(string $value): Client { - $this->code_client = (string) $value; + $this->code_client = $value; return $this; } - public function setAdresse($value) + public function setAdresse(string $value): Client { - $this->adresse = (string) $value; + $this->adresse = $value; return $this; } - public function setCodePostal($value) + public function setCodePostal(string $value): Client { - $this->code_postal = (string) $value; + $this->code_postal = $value; return $this; } - public function setVille($value) + public function setVille(string $value): Client { - $this->ville = (string) $value; + $this->ville = $value; return $this; } - public function setTelephone($value) + public function setTelephone(string $value): Client { // type string parce que: // - zenity renvoie une chaine // - permet de garder le 0 au début et d'inscrire plusieurs numéros - $this->telephone = (string) $value; + $this->telephone = $value; return $this; } - public function setCourriel($value) + public function setCourriel(string $value): Client { - $this->courriel = (string) $value; + $this->courriel = $value; return $this; } - public function setApropos($value) + public function setApropos(string $value): Client { - $this->apropos = (string) $value; + $this->apropos = $value; return $this; } - public function setType($value) + public function setType(string $value): Client { - $this->type = (string) $value; - return $this; - } - - public function typeToClient() - { - if($this->type != 'client') - { - $this->type = 'client'; + if($this->type !== $value){ + $this->type = $value; } + return $this; } - private function setAll(array $input) + private function setAll(array $input): void { $this->prenom_nom = $input[0]; $this->code_client = $input[1]; @@ -191,20 +178,17 @@ class Client public function enterCustomer(ZenityForms $Form): bool { $input = exec($Form->get()); - if($input == '') - { + if($input == ''){ echo "debug: annulation lors de l'enregistrement d'un nouveau client\n"; return false; } $data_array = explode('|', $input); // array - if($data_array[0] == '') - { + if($data_array[0] == ''){ echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n"; return false; } - else - { + else{ $this->setAll($data_array); } @@ -223,29 +207,25 @@ class Client $SearchCustomerResults = new ZenityList(ZenitySetup::$resultats_recherche_client_text, []);*/ $input = exec($SearchCustomerForm->get()); - if($input == '') // commenter ce if pour qu'une saisie vide permette d'obtenir tous les clients - { + 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 null; } echo "debug: recherche effectuée\n"; $MatchedObjects = self::search($input); - if(count($MatchedObjects) === 0) // si aucun client ne correspond, les prendre tous! - { + if(count($MatchedObjects) === 0){ // si aucun client ne correspond, les prendre tous! $repository = self::$entityManager->getRepository('Client'); $MatchedObjects = $repository->findAll(); - if(count($MatchedObjects) === 0) // toujours rien - { + if(count($MatchedObjects) === 0){ // toujours rien echo "debug: aucun client dans la base de données\n"; return null; } } $clients_array = []; - foreach($MatchedObjects as $object) // d'objets en tableaux - { + foreach($MatchedObjects as $object){ // d'objets en tableaux $clients_array[] = get_object_vars($object); } @@ -276,28 +256,23 @@ class Client private static function findByKeywords(array $keywords, string $field): array // renvoie un tableau d'objets { $results = []; - for($i = 0; $i < count($keywords); $i++) - { + 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(); $query = self::$entityManager->createQuery('SELECT u FROM Client u WHERE u.' . $field . ' LIKE :expression'); $query->setParameter('expression', '%' . $keywords[$i] . '%'); $query_result = $query->getResult(); - foreach($query_result as $object) - { + foreach($query_result as $object){ $id = $object->getId(); $already_exist = false; //for($j = 0; $j < count($results); $j++) - foreach($results as $one_result) // pour chaque tableau déjà enregistré dans le tableau $results - { - if($one_result->getId() === $id) - { + foreach($results as $one_result){ // pour chaque tableau déjà enregistré dans le tableau $results + if($one_result->getId() === $id){ $already_exist = true; } } - if(!$already_exist) - { + if(!$already_exist){ $results[$id] = $object; } } -- cgit v1.2.3