From 945af9fda5146405ab9903d4d268bcb2fe95da25 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 10 Jan 2023 13:08:54 +0100 Subject: enregistrement section 1 --- src/model/Clients.php | 65 +++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 38 deletions(-) (limited to 'src/model/Clients.php') diff --git a/src/model/Clients.php b/src/model/Clients.php index aeb39c1..9661562 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -5,18 +5,18 @@ class Clients extends Model { // lecture des données ou hydratation protected $ID; // auto-incrémentée - protected $prenom_nom = ''; - protected $code_client = ''; - protected $adresse = ''; - protected $telephone = ''; - protected $courriel = ''; - protected $commentaires = ''; + protected $prenom_nom; + protected $code_client; + protected $adresse; + protected $telephone; + protected $courriel; + protected $commentaires; - use ModelChildren; // renseigne parent::table + use ModelChildren; // pour hydrateFromForm() public function __construct() { - $this->table = 'clients'; + $this->table = 'clients'; // à mettre dans ModelChildren } //~ public function set(string $variable, $value) @@ -36,59 +36,48 @@ class Clients extends Model } // setters - public function setID(int $value) // inutile? il s'autoincrémente - { - $this->ID = $value; - return($this); - } - public function setPrenom_nom(string $value) + //~ public function setID() -> dans le trait ModelChildren + + public function setPrenomNom($value) { - $this->prenom_nom = $value; + $this->prenom_nom = (string) $value; return($this); } - public function setCode_client(string $value) + public function setCodeClient($value) { - $this->code_client = $value; + $this->code_client = (string) $value; return($this); } - public function setAdresse(string $value) + public function setAdresse($value) { - $this->adresse = $value; + $this->adresse = (string) $value; return($this); } - public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début + public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début { if(is_numeric($value)) { - $this->telephone = $value; + $this->telephone = (string) $value; + } + else + { + $this->telephone = ''; + echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; } return($this); } - public function setCourriel(string $value) + public function setCourriel($value) { - $this->courriel = $value; + $this->courriel = (string) $value; return($this); } - public function setCommentaires(string $value) + public function setCommentaires($value) { - $this->commentaires = $value; + $this->commentaires = (string) $value; return($this); } - public function newRow(array $input) - { - $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); - $this->create(); - // 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 // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite { $result = []; -- cgit v1.2.3