diff options
author | polo <ordipolo@gmx.fr> | 2023-01-10 13:08:54 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-01-10 13:08:54 +0100 |
commit | 945af9fda5146405ab9903d4d268bcb2fe95da25 (patch) | |
tree | 0c3af5ae3e4068e65c3e066c83c7d72058339a7d /src/model | |
parent | 1894fc377e6b938ea34df9980567a1634ec6ef48 (diff) | |
download | AppliGestionPHP-945af9fda5146405ab9903d4d268bcb2fe95da25.zip |
enregistrement section 1
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/Clients.php | 65 | ||||
-rw-r--r-- | src/model/DevisFactures.php | 102 | ||||
-rw-r--r-- | src/model/Model.php | 30 | ||||
-rw-r--r-- | src/model/Prestations.php | 73 | ||||
-rw-r--r-- | src/model/StructTablesDB.php | 3 | ||||
-rw-r--r-- | src/model/traits.php | 83 |
6 files changed, 217 insertions, 139 deletions
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 | |||
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | protected $ID; // auto-incrémentée | 7 | protected $ID; // auto-incrémentée |
8 | protected $prenom_nom = ''; | 8 | protected $prenom_nom; |
9 | protected $code_client = ''; | 9 | protected $code_client; |
10 | protected $adresse = ''; | 10 | protected $adresse; |
11 | protected $telephone = ''; | 11 | protected $telephone; |
12 | protected $courriel = ''; | 12 | protected $courriel; |
13 | protected $commentaires = ''; | 13 | protected $commentaires; |
14 | 14 | ||
15 | use ModelChildren; // renseigne parent::table | 15 | use ModelChildren; // pour hydrateFromForm() |
16 | 16 | ||
17 | public function __construct() | 17 | public function __construct() |
18 | { | 18 | { |
19 | $this->table = 'clients'; | 19 | $this->table = 'clients'; // à mettre dans ModelChildren |
20 | } | 20 | } |
21 | 21 | ||
22 | //~ public function set(string $variable, $value) | 22 | //~ public function set(string $variable, $value) |
@@ -36,59 +36,48 @@ class Clients extends Model | |||
36 | } | 36 | } |
37 | 37 | ||
38 | // setters | 38 | // setters |
39 | public function setID(int $value) // inutile? il s'autoincrémente | 39 | //~ public function setID() -> dans le trait ModelChildren |
40 | { | 40 | |
41 | $this->ID = $value; | 41 | public function setPrenomNom($value) |
42 | return($this); | ||
43 | } | ||
44 | public function setPrenom_nom(string $value) | ||
45 | { | 42 | { |
46 | $this->prenom_nom = $value; | 43 | $this->prenom_nom = (string) $value; |
47 | return($this); | 44 | return($this); |
48 | } | 45 | } |
49 | public function setCode_client(string $value) | 46 | public function setCodeClient($value) |
50 | { | 47 | { |
51 | $this->code_client = $value; | 48 | $this->code_client = (string) $value; |
52 | return($this); | 49 | return($this); |
53 | } | 50 | } |
54 | public function setAdresse(string $value) | 51 | public function setAdresse($value) |
55 | { | 52 | { |
56 | $this->adresse = $value; | 53 | $this->adresse = (string) $value; |
57 | return($this); | 54 | return($this); |
58 | } | 55 | } |
59 | public function setTelephone(string $value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début | 56 | public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début |
60 | { | 57 | { |
61 | if(is_numeric($value)) | 58 | if(is_numeric($value)) |
62 | { | 59 | { |
63 | $this->telephone = $value; | 60 | $this->telephone = (string) $value; |
61 | } | ||
62 | else | ||
63 | { | ||
64 | $this->telephone = ''; | ||
65 | echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n"; | ||
64 | } | 66 | } |
65 | return($this); | 67 | return($this); |
66 | } | 68 | } |
67 | public function setCourriel(string $value) | 69 | public function setCourriel($value) |
68 | { | 70 | { |
69 | $this->courriel = $value; | 71 | $this->courriel = (string) $value; |
70 | return($this); | 72 | return($this); |
71 | } | 73 | } |
72 | public function setCommentaires(string $value) | 74 | public function setCommentaires($value) |
73 | { | 75 | { |
74 | $this->commentaires = $value; | 76 | $this->commentaires = (string) $value; |
75 | return($this); | 77 | return($this); |
76 | } | 78 | } |
77 | 79 | ||
78 | 80 | ||
79 | public function newRow(array $input) | ||
80 | { | ||
81 | $this->hydrate(['prenom_nom' => $input[0], 'code_client' => $input[1], 'adresse' => $input[2], 'telephone' => $input[3], 'courriel' => $input[4], 'commentaires' => $input[5]]); | ||
82 | $this->create(); | ||
83 | // ID obtenu par auto-incrémentation | ||
84 | $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
85 | } | ||
86 | //~ public function setIdFromLastInsertID() // à faire juste après l'écriture d'une nouvelle entrée | ||
87 | //~ { | ||
88 | //~ $this->db = parent::getInstance(); // $db est créée dans Model::execQuery() | ||
89 | //~ $this->ID = $this->db->lastInsertId(); // méthode de PDO | ||
90 | //~ } | ||
91 | |||
92 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite | 81 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite |
93 | { | 82 | { |
94 | $result = []; | 83 | $result = []; |
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index 1ed3a5c..ff80960 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php | |||
@@ -3,49 +3,42 @@ | |||
3 | 3 | ||
4 | class DevisFactures extends Model | 4 | class DevisFactures extends Model |
5 | { | 5 | { |
6 | //~ public $type = ''; // deux tables séparées devis ou factures | ||
7 | |||
6 | // lecture des données ou hydratation | 8 | // lecture des données ou hydratation |
7 | private $ID_devis_facture; // auto-incrémentée | 9 | protected $ID; // auto-incrémentée |
8 | private $ID_presta = 0; | 10 | protected $ID_presta; |
9 | private $validite_devis; | 11 | protected $taches; |
10 | private $signature_devis; | 12 | protected $machine; |
11 | private $taches; | 13 | protected $OS; |
12 | private $machine; | 14 | protected $donnees; |
13 | private $OS; | 15 | protected $cles_licences; |
14 | private $donnees; | 16 | protected $temps; |
15 | private $cles_licences; | 17 | protected $total_main_d_oeuvre; |
16 | private $total_main_d_oeuvre; | 18 | protected $pieces; |
17 | private $pieces; | 19 | protected $total_pieces; |
18 | private $total_pieces; | 20 | protected $deplacement; |
19 | private $deplacement; | 21 | protected $total_HT; |
20 | private $total_HT; | 22 | protected $validite_devis; |
23 | protected $signature_devis; | ||
21 | 24 | ||
22 | //~ use ModelChildren; | 25 | use ModelChildren; // pour hydrateFromForm() |
23 | 26 | ||
24 | public function __construct(int $ID_presta) | 27 | public function __construct(int $ID_presta, string $table) |
25 | { | 28 | { |
26 | $this->table = 'devisfactures'; | ||
27 | $this->ID_presta = $ID_presta; | 29 | $this->ID_presta = $ID_presta; |
30 | $this->table = $table; // deux tables séparées devis et factures | ||
28 | } | 31 | } |
29 | 32 | ||
30 | // setters | 33 | // setters |
31 | public function setIDDevisFacture(int $value = 0) | 34 | //~ public function setID() -> dans le trait ModelChildren |
32 | { | 35 | |
33 | if($value === 0) | ||
34 | { | ||
35 | $this->ID_devis_facture = $this->db->lastInsertId(); // méthode de PDO | ||
36 | } | ||
37 | else | ||
38 | { | ||
39 | $this->ID_devis_facture = $value; | ||
40 | } | ||
41 | return($this); | ||
42 | } | ||
43 | public function setIDPresta(int $value) | 36 | public function setIDPresta(int $value) |
44 | { | 37 | { |
45 | $this->ID_presta = $value; | 38 | $this->ID_presta = $value; |
46 | return($this); | 39 | return($this); |
47 | } | 40 | } |
48 | public function setValiditeDdevis(string $value) | 41 | public function setValiditedevis(string $value) |
49 | { | 42 | { |
50 | $this->validite_devis = $value; | 43 | $this->validite_devis = $value; |
51 | return($this); | 44 | return($this); |
@@ -80,9 +73,15 @@ class DevisFactures extends Model | |||
80 | $this->cles_licences = $value; | 73 | $this->cles_licences = $value; |
81 | return($this); | 74 | return($this); |
82 | } | 75 | } |
83 | public function setTotalMainDOeuvre(float $value) | 76 | public function setTemps(string $value) |
84 | { | 77 | { |
85 | $this->total_main_d_oeuvre = $value; | 78 | $this->temps = $value; |
79 | return($this); | ||
80 | } | ||
81 | public function setTotalMainDOeuvre($value) | ||
82 | { | ||
83 | $value = str_replace(',', '.', $value); | ||
84 | $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) | ||
86 | return($this); | 85 | return($this); |
87 | } | 86 | } |
88 | public function setPieces(string $value) | 87 | public function setPieces(string $value) |
@@ -90,28 +89,39 @@ class DevisFactures extends Model | |||
90 | $this->pieces = $value; | 89 | $this->pieces = $value; |
91 | return($this); | 90 | return($this); |
92 | } | 91 | } |
93 | public function setTotalPieces(float $value) | 92 | public function setTotalPieces($value) |
94 | { | 93 | { |
95 | $this->total_pieces = $value; | 94 | $value = str_replace(',', '.', $value); |
95 | $this->total_pieces = (float) $value; | ||
96 | return($this); | 96 | return($this); |
97 | } | 97 | } |
98 | public function setDeplacement(float $value) | 98 | public function setDeplacement($value) |
99 | { | 99 | { |
100 | $this->deplacement = $value; | 100 | $value = str_replace(',', '.', $value); |
101 | $this->deplacement = (float) $value; | ||
101 | return($this); | 102 | return($this); |
102 | } | 103 | } |
103 | public function setTotalHT(float $value) | 104 | public function setTotalHT($value) |
104 | { | 105 | { |
105 | $this->total_HT = $value; | 106 | $value = str_replace(',', '.', $value); |
107 | $this->total_HT = (float) $value; | ||
106 | return($this); | 108 | return($this); |
107 | } | 109 | } |
108 | 110 | ||
109 | public function newRow(array $input, array $quotations_input = []) | 111 | //~ public function newRow(array $input) |
110 | { | 112 | //~ { |
111 | if(!empty($quotations_input)) // cas d'un devis | 113 | //~ if($this->table === 'devis') // comme la table 'factures' avec deux champs en plus |
112 | { | 114 | //~ { |
113 | $this->hydrate(['validite_devis' => $quotations_input[0], 'signature_devis' => $quotations_input[1]]); | 115 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]], |
114 | } | 116 | //~ ['validite_devis' => $input[12], 'signature_devis' => $input[13]]); |
115 | $this->hydrate([]); | 117 | //~ $this->hydrate(['validite_devis' => $quotations_input[0], 'signature_devis' => $quotations_input[1]]); |
116 | } | 118 | //~ } |
119 | //~ elseif($this->table === 'factures') | ||
120 | //~ { | ||
121 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]]); | ||
122 | //~ } | ||
123 | //~ $this->hydrate(['ID' => $input[0], 'ID_presta' => $input[1], 'taches' => $input[2], 'machine' => $input[3], 'OS' => $input[4], 'donnees' => $input[5], 'cles_licences' => $input[6], 'total_main_d_oeuvre' => $input[7], 'pieces' => $input[8], 'total_pieces' => $input[9], 'deplacement' => $input[10], 'total_HT' => $input[11]]); | ||
124 | //~ $this->create(); | ||
125 | //~ $this->ID_devis_facture = $this->db->lastInsertId(); // méthode de PDO | ||
126 | //~ } | ||
117 | } | 127 | } |
diff --git a/src/model/Model.php b/src/model/Model.php index 938e3dd..4c1fb4d 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -19,22 +19,26 @@ class Model extends DB | |||
19 | return($this->table); | 19 | return($this->table); |
20 | } | 20 | } |
21 | 21 | ||
22 | // setters (plusieurs en même temps) | 22 | // setters |
23 | public function hydrate(array $data) // $data = tableau associatif en entrée: nom_du_champ => valeur | 23 | public function hydrate(array $data): bool // $data = tableau associatif en entrée: nom_du_champ => valeur |
24 | { | 24 | { |
25 | foreach($data as $key => $value) | 25 | foreach($data as $key => $value) |
26 | { | 26 | { |
27 | // nom d'un setter, forme "setMachin()" | 27 | // nom du setter |
28 | $setterName = 'set' . ucfirst($key); // ucfirst met la première lettre en majuscule | 28 | // nom_du_champ devient setNomDuChamp |
29 | // détection | 29 | // on sépare les mots par des espaces, ucwords met la première lettre de chaque mot en majuscule, puis on supprime les espaces |
30 | if(method_exists($this, $setterName) && $value != NULL) // on trouve aussi la méthode is_callable() | 30 | $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); // ucwords: première lettre de chaque mot en majuscule |
31 | if(method_exists($this, $setter_name)) | ||
31 | { | 32 | { |
32 | //~ var_dump($value); | 33 | $this->$setter_name($value); |
33 | // on renseigne les propriétés des l'instance | ||
34 | $this->$setterName($value); // nom d'une méthode dans une variable | ||
35 | } | 34 | } |
35 | else | ||
36 | { | ||
37 | echo "debug: la méthode $setter_name n'existe pas\n"; | ||
38 | return false; | ||
39 | } | ||
36 | } | 40 | } |
37 | return($this); | 41 | return true; |
38 | } | 42 | } |
39 | 43 | ||
40 | 44 | ||
@@ -47,6 +51,8 @@ class Model extends DB | |||
47 | 51 | ||
48 | if($attributes !== null) // requête préparée | 52 | if($attributes !== null) // requête préparée |
49 | { | 53 | { |
54 | var_dump($sql); | ||
55 | var_dump($attributes); | ||
50 | $query = $this->db->prepare($sql); | 56 | $query = $this->db->prepare($sql); |
51 | $query->execute($attributes); | 57 | $query->execute($attributes); |
52 | return $query; | 58 | return $query; |
@@ -66,10 +72,12 @@ class Model extends DB | |||
66 | $fields = []; | 72 | $fields = []; |
67 | $question_marks = []; // ? | 73 | $question_marks = []; // ? |
68 | $values = []; | 74 | $values = []; |
75 | //~ var_dump($this); | ||
69 | foreach($this as $field => $value) | 76 | foreach($this as $field => $value) |
70 | { | 77 | { |
78 | var_dump($field); var_dump($value); | ||
71 | // champs non renseignées et variables de l'objet qui ne sont pas des champs | 79 | // champs non renseignées et variables de l'objet qui ne sont pas des champs |
72 | // note: avec le !== (au lieu de !=) une valeur 0 passe le filtre | 80 | // note: avec le !== (au lieu de !=) une valeur 0 est différente de null |
73 | if($value !== null && $field != 'db' && $field != 'table') | 81 | if($value !== null && $field != 'db' && $field != 'table') |
74 | { | 82 | { |
75 | $fields[] = $field; // push | 83 | $fields[] = $field; // push |
diff --git a/src/model/Prestations.php b/src/model/Prestations.php index cbe8e6c..2f84daa 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php | |||
@@ -4,66 +4,59 @@ | |||
4 | class Prestations extends Model | 4 | class Prestations extends Model |
5 | { | 5 | { |
6 | // lecture des données ou hydratation | 6 | // lecture des données ou hydratation |
7 | protected $ID_presta; // auto-incrémentée | 7 | protected $ID; // auto-incrémentée |
8 | protected $ID_client = 0; | 8 | protected $ID_client = 0; |
9 | protected $combientieme_fois = 0; | 9 | //~ protected $combientieme_fois = 0; |
10 | protected $code_presta = ''; | 10 | protected $code_presta = ''; |
11 | protected $date = 0; // timestamp unix | 11 | protected $date = 0; // timestamp unix |
12 | protected $type_presta = ''; | 12 | protected $type_presta = ''; |
13 | protected $mode_paiement = ''; | 13 | protected $mode_paiement = ''; |
14 | protected $commentaires = ''; | 14 | protected $commentaires = ''; |
15 | 15 | ||
16 | //~ use ModelChildren; | 16 | use ModelChildren; |
17 | 17 | ||
18 | public function __construct(int $ID_client) | 18 | public function __construct(int $ID_client) |
19 | { | 19 | { |
20 | $this->table = 'prestations'; | 20 | $this->table = 'prestations'; |
21 | $this->ID_client = $ID_client; | 21 | $this->ID_client = $ID_client; |
22 | $this->combientiemeFois(); | 22 | //~ $this->combientiemeFois(); |
23 | } | 23 | } |
24 | 24 | ||
25 | // getters | 25 | // getters |
26 | public function getIDPresta(): int | 26 | public function getID(): int |
27 | { | 27 | { |
28 | return $this->ID_presta; | 28 | return $this->ID; |
29 | } | 29 | } |
30 | public function getIDClient(): int | 30 | public function getIDClient(): int |
31 | { | 31 | { |
32 | return $this->ID_client; | 32 | return $this->ID_client; |
33 | } | 33 | } |
34 | public function getCombientiemeFois(): int | 34 | //~ public function getCombientiemeFois(): int |
35 | { | 35 | //~ { |
36 | return $this->combientieme_fois; | 36 | //~ return $this->combientieme_fois; |
37 | } | 37 | //~ } |
38 | public function getDate(): int | 38 | public function getDate(): int |
39 | { | 39 | { |
40 | return $this->date; | 40 | return $this->date; |
41 | } | 41 | } |
42 | 42 | public function getTypePresta(): string | |
43 | // setters | ||
44 | public function setIDPresta(int $value = 0) | ||
45 | { | 43 | { |
46 | if($value === 0) | 44 | return $this->type_presta; |
47 | { | ||
48 | $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | $this->ID_presta = $value; | ||
53 | } | ||
54 | return($this); | ||
55 | } | 45 | } |
46 | |||
47 | // setters | ||
48 | //~ public function setID() -> dans le trait ModelChildren | ||
56 | 49 | ||
57 | public function setIDClient(int $value) | 50 | public function setIDClient(int $value) |
58 | { | 51 | { |
59 | $this->ID_client = $value; | 52 | $this->ID_client = $value; |
60 | return($this); | 53 | return($this); |
61 | } | 54 | } |
62 | public function setCombientiemeFois(int $value) | 55 | //~ public function setCombientiemeFois(int $value) |
63 | { | 56 | //~ { |
64 | $this->combientieme_fois = $value; | 57 | //~ $this->combientieme_fois = $value; |
65 | return($this); | 58 | //~ return($this); |
66 | } | 59 | //~ } |
67 | public function setCodePresta(string $value) | 60 | public function setCodePresta(string $value) |
68 | { | 61 | { |
69 | $this->code_presta = $value; | 62 | $this->code_presta = $value; |
@@ -90,25 +83,21 @@ class Prestations extends Model | |||
90 | return($this); | 83 | return($this); |
91 | } | 84 | } |
92 | 85 | ||
93 | protected function combientiemeFois() | 86 | //~ protected function combientiemeFois() |
94 | { | 87 | //~ { |
95 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) | 88 | //~ // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) |
96 | $array = $this->find(['ID_client' => $this->ID_client]); | 89 | //~ $array = $this->find(['ID_client' => $this->ID_client]); |
97 | $this->combientieme_fois = count($array) + 1; | 90 | //~ //$this->combientieme_fois = count($array) + 1; |
98 | } | 91 | //~ return count($array) + 1; |
92 | //~ } | ||
99 | 93 | ||
100 | // code client = année-mois-jour-codeclient-combientièmefois | 94 | // code client = année-mois-jour-codeclient-combientièmefois |
101 | public function makeCodePresta(Dates $Date, string $code_client) | 95 | public function makeCodePresta(Dates $Date, string $code_client) |
102 | { | 96 | { |
103 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $this->combientieme_fois]; | 97 | // on récupère un tableau contenant toutes les prestations d'un client tous types confondus (devis, facture, cesu, location, enregistrement sans vente) |
98 | $combientieme_fois = count($this->find(['ID_client' => $this->ID_client])) + 1; | ||
99 | |||
100 | $array_code = [$Date->getYear(), $Date->getMonth(), $Date->getDay(), $code_client, $combientieme_fois]; | ||
104 | $this->code_presta = implode('-', $array_code); | 101 | $this->code_presta = implode('-', $array_code); |
105 | } | 102 | } |
106 | |||
107 | //~ public function newRow(array $input) | ||
108 | //~ { | ||
109 | //~ $this->hydrate(['ID_client' => $input[0], 'code_presta' => $input[1], 'date' => $input[2], 'type_presta' => $input[3], 'mode_paiement' => $input[4], 'commentaires' => $input[5]]); | ||
110 | //~ $this->create(); | ||
111 | //~ // ID obtenu par auto-incrémentation | ||
112 | //~ $this->ID_presta = $this->db->lastInsertId(); // méthode de PDO | ||
113 | //~ } | ||
114 | } | 103 | } |
diff --git a/src/model/StructTablesDB.php b/src/model/StructTablesDB.php index 0f13b80..00c5321 100644 --- a/src/model/StructTablesDB.php +++ b/src/model/StructTablesDB.php | |||
@@ -11,7 +11,8 @@ class StructTablesDB | |||
11 | // les tables devis_factures, cesu et locations sont liées à la table prestations | 11 | // les tables devis_factures, cesu et locations sont liées à la table prestations |
12 | 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'commentaires' => 'TEXT'], | 12 | 'clients' => ['ID' => 'INTEGER', 'prenom_nom' => 'TEXT', 'code_client' => 'TEXT', 'adresse' => 'TEXT', 'telephone' => 'TEXT', 'courriel' => 'TEXT', 'commentaires' => 'TEXT'], |
13 | 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], | 13 | 'prestations' => ['ID' => 'INTEGER', 'ID_client' => 'INTEGER', 'code_presta' => 'TEXT', 'date' => 'INTEGER', 'type_presta' => 'TEXT', 'mode_paiement' => 'TEXT', 'commentaires' => 'TEXT'], |
14 | 'devisfactures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT', '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'], | 14 | 'devis' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'temps' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL', 'validite_devis' => 'TEXT', 'signature_devis' => 'TEXT'], |
15 | 'factures' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'machine' => 'TEXT', 'OS' => 'TEXT', 'donnees' => 'TEXT', 'cles_licences' => 'TEXT', 'temps' => 'TEXT', 'total_main_d_oeuvre' => 'REAL', 'pieces' => 'TEXT', 'total_pieces' => 'REAL', 'deplacement' => 'REAL', 'total_HT' => 'REAL'], | ||
15 | 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], | 16 | 'cesu' => ['ID' => 'INTEGER', 'ID_presta' => 'INTEGER', 'taches' => 'TEXT', 'duree_travail' => 'TEXT', 'salaire' => 'REAL'], |
16 | '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' => 'INTEGER', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] | 17 | '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' => 'INTEGER', 'loyer_mensuel' => 'REAL', 'loyers_payes' => 'INTEGER', 'caution' => 'INTEGER'] |
17 | ]; | 18 | ]; |
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 | ||
4 | trait ModelChildren // pour ne pas toucher au constructeur de la classe Model | 6 | trait 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 | } |