diff options
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/CESU.php | 1 | ||||
-rw-r--r-- | src/model/Clients.php | 8 | ||||
-rw-r--r-- | src/model/DB.php | 20 | ||||
-rw-r--r-- | src/model/DevisFactures.php | 1 | ||||
-rw-r--r-- | src/model/Locations.php | 1 | ||||
-rw-r--r-- | src/model/Model.php | 13 | ||||
-rw-r--r-- | src/model/Prestations.php | 3 |
7 files changed, 29 insertions, 18 deletions
diff --git a/src/model/CESU.php b/src/model/CESU.php index f6c6630..8bea94d 100644 --- a/src/model/CESU.php +++ b/src/model/CESU.php | |||
@@ -26,6 +26,7 @@ class CESU extends Model | |||
26 | } | 26 | } |
27 | public function set(string $entry, string $input) | 27 | public function set(string $entry, string $input) |
28 | { | 28 | { |
29 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
29 | switch($entry) | 30 | switch($entry) |
30 | { | 31 | { |
31 | case "Tâche effectuée:": | 32 | case "Tâche effectuée:": |
diff --git a/src/model/Clients.php b/src/model/Clients.php index 0f70eb6..ce38d86 100644 --- a/src/model/Clients.php +++ b/src/model/Clients.php | |||
@@ -44,6 +44,7 @@ class Clients extends Model | |||
44 | } | 44 | } |
45 | public function set(string $entry, string $input) | 45 | public function set(string $entry, string $input) |
46 | { | 46 | { |
47 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
47 | switch($entry) | 48 | switch($entry) |
48 | { | 49 | { |
49 | case "Prénom Nom:": | 50 | case "Prénom Nom:": |
@@ -104,8 +105,9 @@ class Clients extends Model | |||
104 | } | 105 | } |
105 | public function setTelephone($value) | 106 | public function setTelephone($value) |
106 | { | 107 | { |
107 | // type string parce que | 108 | // type string parce que: |
108 | // zenity renvoie une chaine, on peut ainsi garder le 0 au début et avoir plusieurs numéros (séparés par virgule et espace) | 109 | // - zenity renvoie une chaine |
110 | // - permet de garder le 0 au début et d'inscrire plusieurs numéros | ||
109 | $this->telephone = (string) $value; | 111 | $this->telephone = (string) $value; |
110 | return $this; | 112 | return $this; |
111 | } | 113 | } |
@@ -124,6 +126,7 @@ class Clients extends Model | |||
124 | $this->type = (string) $value; | 126 | $this->type = (string) $value; |
125 | return $this; | 127 | return $this; |
126 | } | 128 | } |
129 | |||
127 | public function typeToClient(): bool | 130 | public function typeToClient(): bool |
128 | { | 131 | { |
129 | if($this->type != 'client') | 132 | if($this->type != 'client') |
@@ -137,7 +140,6 @@ class Clients extends Model | |||
137 | } | 140 | } |
138 | } | 141 | } |
139 | 142 | ||
140 | |||
141 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite | 143 | public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite |
142 | { | 144 | { |
143 | $result = []; | 145 | $result = []; |
diff --git a/src/model/DB.php b/src/model/DB.php index 4e54015..47407ba 100644 --- a/src/model/DB.php +++ b/src/model/DB.php | |||
@@ -1,22 +1,22 @@ | |||
1 | <?php | 1 | <?php |
2 | // src/model/DB.php | 2 | // src/model/DB.php |
3 | 3 | ||
4 | // cette classe applique le pattern "singleton" | 4 | // cette classe applique le pattern "singleton", il empêche la classe PDO d'être instanciée plusieurs fois |
5 | // but: ne permettre qu'une seule instance de la classe (laquelle sera éventuellement globale) | 5 | // l'instance est récupérable partout mais sans les inconvénients d'une variable globale |
6 | 6 | ||
7 | // comment? | 7 | // comment? |
8 | // - Un attribut privé et statique contiendra l'instance unique de la classe | 8 | // - le constructeur est privé, c'est à cette condition que l'instanciation devient contrôlable |
9 | // - Un constructeur privé afin d'empêcher l'instanciation depuis l'extérieur de la classe | 9 | // - notre instance unique est stockée dans un attribut privé et statique |
10 | // - Une méthode statique qui permet soit d'instancier la classe soit de retourner l'unique instance créée. | 10 | // - une méthode statique appele le contructeur si l'instance unique n'existe pas encore, puis retourne l'instance |
11 | 11 | ||
12 | class DB extends PDO | 12 | class DB extends PDO |
13 | { | 13 | { |
14 | // paramètres du constructeur de PDO (avec sqlite seul le premier est nécessaire) | 14 | // paramètres du constructeur de PDO |
15 | public static $dsn = ''; // Data Source Name = 1er paramètre | 15 | public static $dsn = ''; // Data Source Name = préfixe + hôte + port + nom de la base + encodage |
16 | //~ public static $dbms = 'sqlite'; | ||
17 | //~ public static $user = ''; | 16 | //~ public static $user = ''; |
18 | //~ public static $password = ''; | 17 | //~ public static $password = ''; |
19 | //~ public static $options = ''; | 18 | //~ public static $options = ''; |
19 | |||
20 | private static $Instance; | 20 | private static $Instance; |
21 | 21 | ||
22 | private function __construct() // exécuté une seul fois à cause du "if" dans getInstance() | 22 | private function __construct() // exécuté une seul fois à cause du "if" dans getInstance() |
@@ -36,12 +36,12 @@ class DB extends PDO | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | // créer son objet avec: $Bdd = parent::getInstance(); | 39 | // créer son objet depuis Model avec: $db = parent::getInstance(); |
40 | public static function getInstance(): self | 40 | public static function getInstance(): self |
41 | { | 41 | { |
42 | if(self::$Instance === null) | 42 | if(self::$Instance === null) |
43 | { | 43 | { |
44 | self::$Instance = new self(); | 44 | self::$Instance = new self; |
45 | } | 45 | } |
46 | return self::$Instance; | 46 | return self::$Instance; |
47 | } | 47 | } |
diff --git a/src/model/DevisFactures.php b/src/model/DevisFactures.php index 7c31f13..c667fb2 100644 --- a/src/model/DevisFactures.php +++ b/src/model/DevisFactures.php | |||
@@ -65,6 +65,7 @@ class DevisFactures extends Model | |||
65 | 65 | ||
66 | public function set(string $entry, string $input) // trouve la bonne méthode | 66 | public function set(string $entry, string $input) // trouve la bonne méthode |
67 | { | 67 | { |
68 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
68 | switch($entry) | 69 | switch($entry) |
69 | { | 70 | { |
70 | case "Tâches:": | 71 | case "Tâches:": |
diff --git a/src/model/Locations.php b/src/model/Locations.php index ead2727..103cecd 100644 --- a/src/model/Locations.php +++ b/src/model/Locations.php | |||
@@ -36,6 +36,7 @@ class Locations extends Model | |||
36 | } | 36 | } |
37 | public function set(string $entry, string $input) | 37 | public function set(string $entry, string $input) |
38 | { | 38 | { |
39 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
39 | switch($entry) | 40 | switch($entry) |
40 | { | 41 | { |
41 | case "Désignation:": | 42 | case "Désignation:": |
diff --git a/src/model/Model.php b/src/model/Model.php index 1fdab7d..fad25b3 100644 --- a/src/model/Model.php +++ b/src/model/Model.php | |||
@@ -64,8 +64,7 @@ abstract class Model extends DB | |||
64 | // méthode lancée par des objets de type enfants | 64 | // méthode lancée par des objets de type enfants |
65 | function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $Details, on hydrate aussi $Presta | 65 | function hydrateFromForm(string $data_string, Object $Presta = NULL): bool // quand l'objet est $Details, on hydrate aussi $Presta |
66 | { | 66 | { |
67 | //~ $tableSize = count(StructTablesDB::$structureOfTables[$this->getTable()]); // int | 67 | $data_string = $this->cleanSpecialChars($data_string); // possibilité que $data_string devienne une chaine vide |
68 | |||
69 | if($data_string !== '') | 68 | if($data_string !== '') |
70 | { | 69 | { |
71 | $data_array = explode('|', $data_string); // array | 70 | $data_array = explode('|', $data_string); // array |
@@ -130,13 +129,19 @@ abstract class Model extends DB | |||
130 | } | 129 | } |
131 | } | 130 | } |
132 | 131 | ||
132 | protected function cleanSpecialChars(string $data): string | ||
133 | { | ||
134 | $search = ['"']; | ||
135 | return str_replace($search, '', $data); | ||
136 | } | ||
137 | |||
133 | 138 | ||
134 | // exécuter le SQL | 139 | // exécuter le SQL |
135 | // les attributs correspondent aux ? dans les requêtes préparées | 140 | // les $attributs correspondent aux ? dans les requêtes préparées |
136 | // ne pas surcharger la méthode PDO::query() qui n'est pas compatible | 141 | // ne pas surcharger la méthode PDO::query() qui n'est pas compatible |
137 | protected function execQuery(string $sql, array $attributes = null) | 142 | protected function execQuery(string $sql, array $attributes = null) |
138 | { | 143 | { |
139 | $this->db = parent::getInstance(); // connexion | 144 | $this->db = parent::getInstance(); // parent::, self:: et DB:: sont équivalents |
140 | 145 | ||
141 | if($attributes !== null) // requête préparée | 146 | if($attributes !== null) // requête préparée |
142 | { | 147 | { |
diff --git a/src/model/Prestations.php b/src/model/Prestations.php index 8591e83..88eb4f0 100644 --- a/src/model/Prestations.php +++ b/src/model/Prestations.php | |||
@@ -70,6 +70,7 @@ class Prestations extends Model | |||
70 | } | 70 | } |
71 | public function set(string $entry, string $input) | 71 | public function set(string $entry, string $input) |
72 | { | 72 | { |
73 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaine vide | ||
73 | switch($entry) | 74 | switch($entry) |
74 | { | 75 | { |
75 | case "Numéro prestation:": | 76 | case "Numéro prestation:": |
@@ -134,7 +135,7 @@ class Prestations extends Model | |||
134 | } | 135 | } |
135 | public function setCommentaires(string $value) | 136 | public function setCommentaires(string $value) |
136 | { | 137 | { |
137 | $this->commentaires = $value; | 138 | $this->commentaires = $this->cleanSpecialChars($value); // possibilité que $this->commentaires devienne une chaine vide |
138 | return $this; | 139 | return $this; |
139 | } | 140 | } |
140 | public function setNumeroPresta($value) | 141 | public function setNumeroPresta($value) |