From 1894fc377e6b938ea34df9980567a1634ec6ef48 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 28 Dec 2022 05:19:55 +0100 Subject: =?UTF-8?q?r=C3=A9organisation=20+=20bient=C3=B4t=20finie=20la=20s?= =?UTF-8?q?ection=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Clients.php | 56 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/model/Clients.php') diff --git a/src/model/Clients.php b/src/model/Clients.php index 92a4b31..aeb39c1 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -4,20 +4,37 @@ class Clients extends Model { // lecture des données ou hydratation - public $ID; - public $prenom_nom; - public $adresse; - public $code_client; - public $commentaires; + protected $ID; // auto-incrémentée + protected $prenom_nom = ''; + protected $code_client = ''; + protected $adresse = ''; + protected $telephone = ''; + protected $courriel = ''; + protected $commentaires = ''; use ModelChildren; // renseigne parent::table + public function __construct() + { + $this->table = 'clients'; + } + //~ public function set(string $variable, $value) //~ { //~ $this->$variable = $value; //~ return($this); //~ } + // getters + public function getID(): int + { + return $this->ID; + } + public function getCodeClient(): string + { + return $this->code_client; + } + // setters public function setID(int $value) // inutile? il s'autoincrémente { @@ -29,14 +46,27 @@ class Clients extends Model $this->prenom_nom = $value; return($this); } + public function setCode_client(string $value) + { + $this->code_client = $value; + return($this); + } public function setAdresse(string $value) { $this->adresse = $value; return($this); } - public function setCode_client(string $value) + public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début { - $this->code_client = $value; + if(is_numeric($value)) + { + $this->telephone = $value; + } + return($this); + } + public function setCourriel(string $value) + { + $this->courriel = $value; return($this); } public function setCommentaires(string $value) @@ -48,12 +78,18 @@ class Clients extends Model public function newRow(array $input) { - $this->hydrate(['prenom_nom' => $input[0], 'adresse' => $input[1], 'code_client' => $input[2], 'commentaires' => $input[3]]); + $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); $this->create(); - $this->setIdFromLastInsertID(); // dans ModelChildren, n'utilise pas Model::execQuery() + // ID obtenu par auto-incrémentation + $this->ID = $this->db->lastInsertId(); // méthode de PDO } + //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée + //~ { + //~ $this->db = parent::getInstance(); // $db est créée dans Model::execQuery() + //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO + //~ } - public function findByKeywords(array $keywords, string $field): array + 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++) -- cgit v1.2.3