summaryrefslogtreecommitdiff
path: root/src/model/traits.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2023-01-10 13:08:54 +0100
committerpolo <ordipolo@gmx.fr>2023-01-10 13:08:54 +0100
commit945af9fda5146405ab9903d4d268bcb2fe95da25 (patch)
tree0c3af5ae3e4068e65c3e066c83c7d72058339a7d /src/model/traits.php
parent1894fc377e6b938ea34df9980567a1634ec6ef48 (diff)
downloadAppliGestionPHP-945af9fda5146405ab9903d4d268bcb2fe95da25.zip
enregistrement section 1
Diffstat (limited to 'src/model/traits.php')
-rw-r--r--src/model/traits.php83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/model/traits.php b/src/model/traits.php
index 3d446c1..41f1c35 100644
--- a/src/model/traits.php
+++ b/src/model/traits.php
@@ -1,7 +1,9 @@
1<?php 1<?php
2// model/traits.php 2// model/traits.php
3//
4// fonctions à utiliser par les enfants de Model
3 5
4trait ModelChildren // pour ne pas toucher au constructeur de la classe Model 6trait ModelChildren
5{ 7{
6 //~ public function __construct() 8 //~ public function __construct()
7 //~ { 9 //~ {
@@ -13,4 +15,83 @@ trait ModelChildren // pour ne pas toucher au constructeur de la classe Model
13 //~ $this->db = parent::getInstance(); 15 //~ $this->db = parent::getInstance();
14 //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO 16 //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO
15 //~ } 17 //~ }
18
19 public function setID(int $value = 0)
20 {
21 if($value === 0)
22 {
23 $this->ID = $this->db->lastInsertId(); // méthode de PDO
24 }
25 else
26 {
27 $this->ID = $value;
28 }
29 return($this);
30 }
31
32 function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $DetailsPresta, on hydrate aussi $Presta
33 {
34 //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int
35
36 if($data_string !== '')
37 {
38 $data_array = explode('|', $data_string); // array
39 //~ var_dump($data_array);
40 //~ if(count($data_array) === $tableSize - 1) // nombre de champs sauf ID qui est auto-incrémenté automatiquement
41 //~ {
42 //~ var_dump($this->getTable());
43 //~ var_dump($data_array);
44 $check = false;
45 switch($this->getTable())
46 {
47 case 'clients';
48 if($data_array[0] == '')
49 {
50 echo "debug: données insuffisantes, le nom du client doit au minimum être renseigné\n";
51 return false;
52 }
53 else
54 {
55 $check = $this->hydrate(['prenom_nom' => $data_array[0], 'code_client' => $data_array[1], 'adresse' => $data_array[2], 'telephone' => $data_array[3], 'courriel' => $data_array[4], 'commentaires' => $data_array[5]]);
56 }
57 break;
58 case 'prestations'; // inutilisé
59 break;
60 case 'devis';
61 $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]);
62 if($check)
63 {
64 $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'temps' => $data_array[5], 'total_main_d_oeuvre' => $data_array[6], 'pieces' => $data_array[7], 'total_pieces' => $data_array[8], 'deplacement' => $data_array[9], 'total_HT' => $data_array[10],
65 'validite_devis' => $data_array[12], 'signature_devis' => $data_array[13]]);
66 }
67 break;
68 case 'factures';
69 $check = $Presta->hydrate(['mode_paiement' => $data_array[11]]);
70 if($check)
71 {
72 $check = $this->hydrate(['taches' => $data_array[0], 'machine' => $data_array[1], 'OS' => $data_array[2], 'donnees' => $data_array[3], 'cles_licences' => $data_array[4], 'temps' => $data_array[5], 'total_main_d_oeuvre' => $data_array[6], 'pieces' => $data_array[7], 'total_pieces' => $data_array[8], 'deplacement' => $data_array[9], 'total_HT' => $data_array[10]]);
73 }
74 break;
75 case 'cesu';
76 break;
77 case 'locations';
78 break;
79 default: // inutilisé
80 echo "debug: table inconnue hydrateFromForm()";
81 return false;
82 }
83 return $check;
84 //~ }
85 //~ else
86 //~ {
87 //~ echo "debug: mauvais tableau, il doit avoir " . $tableSize - 1 . " cases\n"; // ou -3 pour les factures
88 //~ return false;
89 //~ }
90 }
91 else
92 {
93 echo "debug: annulation lors du formulaire\n";
94 return false;
95 }
96 }
16} 97}