From 5fb0a2785718160317069c87496d1602e32ea3d6 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 14 Aug 2024 17:20:10 +0200 Subject: autoload avec composer --- old/model version 0.1/Clients.php | 168 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 old/model version 0.1/Clients.php (limited to 'old/model version 0.1/Clients.php') diff --git a/old/model version 0.1/Clients.php b/old/model version 0.1/Clients.php new file mode 100644 index 0000000..32cf0c5 --- /dev/null +++ b/old/model version 0.1/Clients.php @@ -0,0 +1,168 @@ +table = strtolower(__CLASS__); // clients + } + + // getters + public function getId(): int + { + return $this->id; + } + public function getCodeClient(): string + { + return $this->code_client; + } + public function getAllWithWindowFields(): array // différent de Model::getAll() qui retourne get_object_vars($this) + { + return [ + "Prénom Nom:" => $this->prenom_nom, + "Code client (J.C.Dusse):" => $this->code_client, + "Adresse:" => $this->adresse, + "Code postal:" => $this->code_postal, + "Ville:" => $this->ville, + "Telephone:" => $this->telephone, + "Courriel:" => $this->courriel, + "À propos:" => $this->apropos, + "Client ou Prospect?" => $this->type]; + } + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide + switch($entry) + { + case "Prénom Nom:": + $this->setPrenomNom($input); + break; + case "Code client (J.C.Dusse):": + $this->setCodeClient($input); + break; + case "Adresse:": + $this->setAdresse($input); + break; + case "Code postal:": + $this->setCodePostal($input); + break; + case "Ville:": + $this->setVille($input); + break; + case "Telephone:": + $this->setTelephone($input); + break; + case "Courriel:": + $this->setCourriel($input); + break; + case "À propos:": + $this->setApropos($input); + break; + case "Client ou Prospect?": + $this->setType($input); + break; + } + } + + // setters + public function setPrenomNom($value) + { + $this->prenom_nom = (string) $value; + return $this; + } + public function setCodeClient($value) + { + $this->code_client = (string) $value; + return $this; + } + public function setAdresse($value) + { + $this->adresse = (string) $value; + return $this; + } + public function setCodePostal($value) + { + $this->code_postal = (string) $value; + return $this; + } + public function setVille($value) + { + $this->ville = (string) $value; + return $this; + } + public function setTelephone($value) + { + // 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; + return $this; + } + public function setCourriel($value) + { + $this->courriel = (string) $value; + return $this; + } + public function setApropos($value) + { + $this->apropos = (string) $value; + return $this; + } + public function setType($value) + { + $this->type = (string) $value; + return $this; + } + + public function typeToClient(): bool + { + if($this->type != 'client') + { + $this->type = 'client'; + return true; + } + else + { + return false; + } + } + + public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite + { + $result = []; + 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(); + foreach($query_result as $one_array) // pour chaque sous tableau + { + $already_exist = false; + for($j = 0; $j < count($result); $j++) // pour chaque tableau déjà enregistré dans le tableau $result + { + if($result[$j]['id'] === $one_array['id']) + { + $already_exist = true; + } + } + if(!$already_exist) + { + $result[] = $one_array; + } + } + } + return $result; + } +} -- cgit v1.2.3