From 7d564efbccc4b361d2fa2db2902fb35882304aae Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 20 Dec 2022 03:31:33 +0100 Subject: recherche de clients --- src/model/Clients.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/model/Clients.php') diff --git a/src/model/Clients.php b/src/model/Clients.php index 816cff3..92a4b31 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -46,10 +46,36 @@ class Clients extends Model } - public function newRow(array $entry) + public function newRow(array $input) { - $this->hydrate(['prenom_nom' => $entry[0], 'adresse' => $entry[1], 'code_client' => $entry[2], 'commentaires' => $entry[3]]); + $this->hydrate(['prenom_nom' => $input[0], 'adresse' => $input[1], 'code_client' => $input[2], 'commentaires' => $input[3]]); $this->create(); - $this->setIdFromLastInsertID(); + $this->setIdFromLastInsertID(); // dans ModelChildren, n'utilise pas Model::execQuery() + } + + public function findByKeywords(array $keywords, string $field): array + { + $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