From 9c9cda0ac823863c6760d77984ea2ecaf87c52ab Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 16 Jul 2024 05:04:13 +0200 Subject: =?UTF-8?q?renommage=20complet=20des=20ID=20en=20id:=20variables,?= =?UTF-8?q?=20m=C3=A9thodes,=20BDD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions.php | 16 ++++++++-------- src/main.php | 14 ++++++++------ src/model/CESU.php | 8 ++++---- src/model/Clients.php | 8 ++++---- src/model/DevisFactures.php | 12 ++++++------ src/model/Locations.php | 8 ++++---- src/model/Model.php | 18 +++++++++--------- src/model/Prestations.php | 28 ++++++++++++++-------------- src/model/StructTablesDB.php | 12 ++++++------ src/sections/2_service.php | 12 ++++++------ src/sections/3_modify_data.php | 2 +- 11 files changed, 70 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/functions.php b/src/functions.php index e7c2e5b..47cea42 100644 --- a/src/functions.php +++ b/src/functions.php @@ -40,7 +40,7 @@ function enterCustomer($Client): bool unset($input); $Client->create(); // écrire dans la base - $Client->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + $Client->setId(); // sans paramètre, exécute un $this->db->lastInsertId() return true; } @@ -76,7 +76,7 @@ function makeObjectClient() } echo "debug: client sélectionné\n"; - $Client->setID($input); + $Client->setId($input); $Client->hydrate($Client->findById()); return $Client; @@ -100,18 +100,18 @@ function getServices(Clients $Client, string $type = '') { echo "debug: recherche d'une prestation\n"; - // on recherche les ID des prestas dans la table 'prestations' avec 'ID_client' - $Presta = new Prestations($Client->getID()); + // on recherche les ID des prestas dans la table 'prestations' avec 'id_client' + $Presta = new Prestations($Client->getId()); $Presta->setTypePresta($type); - $IDs = $Presta->getIDsByIdClient(); // comportement différent si le type est connu + $IDs = $Presta->getIdsByIdClient(); // comportement différent si le type est connu unset($Presta); // mettres toutes les données dans un tableau $PrestaList = []; foreach($IDs as $id) { - $PrestaList[$id] = new Prestations($Client->getID()); // renseigne 'ID_client' - $PrestaList[$id]->setID($id); // ID de la prestation = clé du tableau + $PrestaList[$id] = new Prestations($Client->getId()); // renseigne 'id_client' + $PrestaList[$id]->setId($id); // ID de la prestation = clé du tableau $PrestaList[$id]->hydrate($PrestaList[$id]->findById()); // données copiés de la table à l'objet } @@ -119,7 +119,7 @@ function getServices(Clients $Client, string $type = '') $entrees = []; foreach($PrestaList as $Presta) { - $id = $Presta->getID(); + $id = $Presta->getId(); $entrees[$id][] = $id; $Date = new Dates((int)$Presta->getDate()); // envoi du timestamp, (int) est là par sécurité $entrees[$id][] = $Date->getDate(); diff --git a/src/main.php b/src/main.php index fb2b85e..e90c1d5 100644 --- a/src/main.php +++ b/src/main.php @@ -2,21 +2,23 @@ ID_presta = $value; + $this->id_presta = $value; return($this); } public function setTaches(string $value) diff --git a/src/model/Clients.php b/src/model/Clients.php index ce38d86..32cf0c5 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php @@ -4,7 +4,7 @@ class Clients extends Model { // lecture des données ou hydratation - protected $ID; // auto-incrémentée + protected $id; // auto-incrémentée protected $prenom_nom; protected $code_client; protected $adresse; @@ -21,9 +21,9 @@ class Clients extends Model } // getters - public function getID(): int + public function getId(): int { - return $this->ID; + return $this->id; } public function getCodeClient(): string { @@ -152,7 +152,7 @@ class Clients extends Model $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']) + if($result[$j]['id'] === $one_array['id']) { $already_exist = true; } diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index 967067f..06a0a59 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php @@ -6,8 +6,8 @@ class DevisFactures extends Model //~ public $type = ''; // deux tables séparées devis ou factures // lecture des données ou hydratation - protected $ID; // auto-incrémentée - protected $ID_presta; + protected $id; // auto-incrémentée + protected $id_presta; protected $taches; protected $machine; protected $OS; @@ -114,14 +114,14 @@ class DevisFactures extends Model } // setters - //~ public function setID(int $value = 0) + //~ public function setId(int $value = 0) //~ { - //~ $this->ID = $value; + //~ $this->id = $value; //~ return($this); //~ } - public function setIDPresta(int $value) + public function setIdPresta(int $value) { - $this->ID_presta = $value; + $this->id_presta = $value; return($this); } public function setTaches(string $value) diff --git a/src/model/Locations.php b/src/model/Locations.php index 103cecd..c6b8deb 100644 --- a/src/model/Locations.php +++ b/src/model/Locations.php @@ -4,8 +4,8 @@ class Locations extends Model { // lecture des données ou hydratation - protected $ID; - protected $ID_presta; + protected $id; + protected $id_presta; protected $designation; protected $modele_description; protected $valeur; @@ -70,9 +70,9 @@ class Locations extends Model } // setters - public function setIDPresta(int $value) + public function setIdPresta(int $value) { - $this->ID_presta = $value; + $this->id_presta = $value; return($this); } public function setDesignation(string $value) diff --git a/src/model/Model.php b/src/model/Model.php index 9ada9a4..b3d157d 100644 --- a/src/model/Model.php +++ b/src/model/Model.php @@ -21,15 +21,15 @@ abstract class Model extends DB } // setters - public function setID(int $value = 0) + public function setId(int $value = 0) { if($value === 0) { - $this->ID = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence + $this->id = $this->db->lastInsertId(); // méthode de PDO, attention lastInsertId() ne gère pas la concurence } else { - $this->ID = $value; + $this->id = $value; } return $this; } @@ -202,7 +202,7 @@ abstract class Model extends DB public function findById() // obtenir une entrée grace à son ID { - return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->ID)->fetch()); + return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id = ' . $this->id)->fetch()); } public function getDetailsByIdPresta() { @@ -214,7 +214,7 @@ abstract class Model extends DB } else { - return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->ID_presta)->fetch(); // type array + return $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE id_Presta = ' . $this->id_presta)->fetch(); // type array } } @@ -223,13 +223,13 @@ abstract class Model extends DB $fields = []; $values = []; - // change "'ID' => 2" en "'ID' = ?" et "2" + // change "'id' => 2" en "'id' = ?" et "2" foreach($criteria as $field => $value) { $fields[] = "$field = ?"; // même chose que: $field . " = ?" $values[] = $value; } - $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND ID = ?' + $field_list = implode(' AND ', $fields); // créer une chaîne reliant les morceaux avec le morceau AND en paramètre: 'adresse = ? AND id = ?' // SELECT * FROM annonces WHERE actif = 1; return($this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field_list, $values)->fetchAll()); @@ -252,7 +252,7 @@ abstract class Model extends DB $values[] = $value; } } - $values[] = $this->ID; // cette syntaxe ajoute une valeur au tableau + $values[] = $this->id; // cette syntaxe ajoute une valeur au tableau $field_list = implode(', ', $fields); // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ? @@ -261,7 +261,7 @@ abstract class Model extends DB public function updateOneValue(string $field, $value) { - return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->ID])); + return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->id])); } diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 1666018..3a415be 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php @@ -4,8 +4,8 @@ class Prestations extends Model { // lecture des données ou hydratation - protected $ID; // auto-incrémentée - protected $ID_client = 0; + protected $id; // auto-incrémentée + protected $id_client = 0; protected $code_presta = ''; protected $date = 0; // timestamp unix protected $type_presta = ''; @@ -13,24 +13,24 @@ class Prestations extends Model protected $commentaires = ''; //protected $numero_presta = 0; - public function __construct(int $ID_client) + public function __construct(int $id_client) { - $this->ID_client = $ID_client; + $this->id_client = $id_client; $this->table = strtolower(__CLASS__); // prestations } // getters - public function getID(): int + public function getId(): int { - return $this->ID; + return $this->id; } - public function getIDClient(): int + public function getIdClient(): int { - return $this->ID_client; + return $this->id_client; } - public function getIDsByIdClient() // obtenir une entrée avec son ID_client, comportement différent si le type est connu + public function getIdsByIdClient() // obtenir une entrée avec son id_client, comportement différent si le type est connu { - $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->ID_client; + $sql = 'SELECT id FROM ' . $this->table . ' WHERE id_client = ' . $this->id_client; if($this->type_presta != '') { $sql .= " AND type_presta = '" . $this->type_presta . "'"; @@ -40,7 +40,7 @@ class Prestations extends Model $IDs = []; // si $IDs reste vide, ne pas être de type NULL for($i = 0; $i < count($data); $i++) { - $IDs[$i] = $data[$i]['ID']; // tableau simple + $IDs[$i] = $data[$i]['id']; // tableau simple } return($IDs); } @@ -92,9 +92,9 @@ class Prestations extends Model } // setters - public function setIDClient(int $value) + public function setIdClient(int $value) { - $this->ID_client = $value; + $this->id_client = $value; return $this; } //~ public function setCombientiemeFois(int $value) @@ -152,7 +152,7 @@ class Prestations extends Model { // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) // inconvénient: il peut y avoir plusieurs prestations avec le même numéro au compteur, à améliorer - $combientieme_fois = count($this->find(['ID_client' => $this->ID_client])) + 1; + $combientieme_fois = count($this->find(['id_client' => $this->id_client])) + 1; $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->type_presta, $combientieme_fois]; $this->code_presta = implode('-', $array_code); diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 48bf8e5..303af46 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php @@ -9,12 +9,12 @@ class StructTablesDB static public $structureOfTables = [ // la table prestations est liée à la table clients // les tables devis_factures, cesu et locations sont liées à la table prestations - 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT', 'type' => 'TEXT DEFAULT prospect'], - 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], - 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'prix_devis' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT DEFAULT non'], - 'factures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], - 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], - 'locations' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'designation' => 'TEXT', 'modele_description' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'TEXT', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] + 'clients' => ['id' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'code_postal' => 'TEXT', 'ville' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'apropos' => 'TEXT', 'type' => 'TEXT DEFAULT prospect'], + 'prestations' => ['id' => 'INTEGER', 'id_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], + 'devis' => ['id' => 'INTEGER', 'id_presta' => 'INTEGER', 'taches' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'prix_devis' => 'REAL', 'total_HT' => 'REAL', 'delai_livraison' => 'TEXT', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT DEFAULT non'], + 'factures' => ['id' => 'INTEGER', 'id_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], + 'cesu' => ['id' => 'INTEGER', 'id_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], + 'locations' => ['id' => 'INTEGER', 'id_presta' => 'INTEGER', 'designation' => 'TEXT', 'modele_description' => 'TEXT', 'valeur' => 'REAL', 'etat_des_lieux_debut' => 'TEXT', 'etat_des_lieux_fin' => 'TEXT', 'duree_location' => 'TEXT', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] ]; // les types de variables de sqlite sont peu nombreux et autorisent un typage automatique diff --git a/src/sections/2_service.php b/src/sections/2_service.php index 78e4dd4..3dd620d 100644 --- a/src/sections/2_service.php +++ b/src/sections/2_service.php @@ -48,7 +48,7 @@ function newService($Client): array // $Client est un Client ou null return [0, null]; // menu principal } - $Presta = new Prestations($Client->getID()); + $Presta = new Prestations($Client->getId()); $Presta->setDate($Date->getTimestamp()); // un entier pour la BDD // formulaire - étape 2/3 @@ -67,7 +67,7 @@ function newService($Client): array // $Client est un Client ou null break; case ZenitySetup::$menu_enregistrement_entrees[2]: // "Facture à partir d'un devis" // recherche du devis - $Quotation = getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié pour $Presta->getIDsByIdClient() + $Quotation = getServices($Client, 'devis'); // rechercher un devis, type 'devis' spécifié pour $Presta->getIdsByIdClient() if(!is_object($Quotation) || get_class($Quotation) != 'Prestations' || $Quotation->getTypePresta() != 'devis') { echo "debug: annulation sélection client\n"; @@ -124,7 +124,7 @@ function newService($Client): array // $Client est un Client ou null if($choix_niv2 === ZenitySetup::$menu_enregistrement_entrees[2]) // cas: facture à partir d'un devis { // devis retrouvé ($Quotation est déjà hydraté) - $QuotationDetails->setIDPresta($Quotation->getID()); + $QuotationDetails->setIdPresta($Quotation->getId()); $QuotationDetails->hydrate($QuotationDetails->getDetailsByIdPresta()); // facture avec le devis @@ -148,13 +148,13 @@ function newService($Client): array // $Client est un Client ou null // mise à jour base de données $Presta->create(); - $Presta->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + $Presta->setId(); // sans paramètre, exécute un $this->db->lastInsertId() if(isset($PrestaDetails)) // presta vendue { - $PrestaDetails->setIDPresta($Presta->getID()); // d'un objet à l'autre + $PrestaDetails->setIdPresta($Presta->getId()); // d'un objet à l'autre $PrestaDetails->create(); - $PrestaDetails->setID(); // sans paramètre, exécute un $this->db->lastInsertId() + $PrestaDetails->setId(); // sans paramètre, exécute un $this->db->lastInsertId() } // si encore de type prospect, devient un type client diff --git a/src/sections/3_modify_data.php b/src/sections/3_modify_data.php index 279310b..c2f683a 100644 --- a/src/sections/3_modify_data.php +++ b/src/sections/3_modify_data.php @@ -114,7 +114,7 @@ function modifyData($Client): array } if($type != 'non_vendue') { - $PrestaDetails->setIDPresta($Presta->getID()); + $PrestaDetails->setIdPresta($Presta->getId()); $PrestaDetails->hydrate($PrestaDetails->getDetailsByIdPresta()); } -- cgit v1.2.3