summaryrefslogtreecommitdiff
path: root/src/model/entities/Location.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/entities/Location.php')
-rw-r--r--src/model/entities/Location.php63
1 files changed, 18 insertions, 45 deletions
diff --git a/src/model/entities/Location.php b/src/model/entities/Location.php
index 3574272..c18c40a 100644
--- a/src/model/entities/Location.php
+++ b/src/model/entities/Location.php
@@ -2,7 +2,6 @@
2// src/entities/Location.php 2// src/entities/Location.php
3 3
4use Doctrine\ORM\Mapping as ORM; 4use Doctrine\ORM\Mapping as ORM;
5use Doctrine\ORM\EntityManager;
6 5
7#[ORM\Entity] 6#[ORM\Entity]
8#[ORM\Table(name: 'locations')] 7#[ORM\Table(name: 'locations')]
@@ -27,17 +26,7 @@ class Location extends Prestation
27 #[ORM\Column] 26 #[ORM\Column]
28 protected float $caution; 27 protected float $caution;
29 28
30 public static EntityManager $entityManager;
31
32 public function __construct(?Prestation $presta = null){
33 $this->setPresta($presta);
34 }
35
36 // getters 29 // getters
37 public function getPresta(): Prestation
38 {
39 return $this->presta;
40 }
41 public function getLoyer(): float 30 public function getLoyer(): float
42 { 31 {
43 return $this->loyer_hebdo; 32 return $this->loyer_hebdo;
@@ -54,7 +43,8 @@ class Location extends Prestation
54 43
55 public function getAllWithWindowFields(): array 44 public function getAllWithWindowFields(): array
56 { 45 {
57 return [ 46 $common_data = parent::getAllWithWindowFields();
47 return array_merge($common_data, [
58 "Désignation:" => $this->designation, 48 "Désignation:" => $this->designation,
59 "Description du modèle:" => $this->modele_description, 49 "Description du modèle:" => $this->modele_description,
60 "Valeur:" => $this->valeur, 50 "Valeur:" => $this->valeur,
@@ -63,7 +53,7 @@ class Location extends Prestation
63 "Durée de la location:" => $this->duree_location, 53 "Durée de la location:" => $this->duree_location,
64 "Loyer Hebdomadaire:" => $this->loyer_hebdo, 54 "Loyer Hebdomadaire:" => $this->loyer_hebdo,
65 "Loyers Payés:" => $this->loyers_payes, 55 "Loyers Payés:" => $this->loyers_payes,
66 "Caution:" => $this->caution]; 56 "Caution:" => $this->caution]);
67 } 57 }
68 58
69 // setters 59 // setters
@@ -99,11 +89,9 @@ class Location extends Prestation
99 case "Caution:": 89 case "Caution:":
100 $this->setCaution($input); 90 $this->setCaution($input);
101 break; 91 break;
102 } 92 default: // gérer les champ dans Prestation
103 } 93 parent::set($entry, $input);
104 private function setPresta(Prestation $input): void // private? 94 }
105 {
106 $this->presta = $input;
107 } 95 }
108 public function setDesignation(string $value): Location 96 public function setDesignation(string $value): Location
109 { 97 {
@@ -168,36 +156,21 @@ class Location extends Prestation
168 $this->caution = (int)$input[7]; 156 $this->caution = (int)$input[7];
169 } 157 }
170 158
171 // à mettre plus tard dans une classe mère 159 public function validateForm(array $data_array): bool
172 protected function cleanSpecialChars(string $data): string
173 {
174 $search = ['"'];
175 return str_replace($search, '', $data);
176 }
177 // à mettre plus tard dans une classe mère
178 public function hydrate(string $answers): void
179 { 160 {
180 $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide 161 if(count($data_array) === 8){
181 if($answers == '') 162 return true;
182 {
183 echo "erreur de Location::hydrate(), la chaine \$answers est vide.\n";
184 return;
185 }
186 $data_array = explode('|', $answers); // array
187
188 if(count($data_array) === 8)
189 {
190 $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null"
191 $this->setAll($data_array);
192 } 163 }
193 else 164 else{
194 { 165 echo "erreur de Location::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
195 echo "erreur de Location::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; 166 return false;
196 return;
197 } 167 }
168 }
198 169
199 //self::$entityManager->persist('Prestation'); 170 // à mettre plus tard dans une classe mère
200 self::$entityManager->persist($this); // $Presta avec en cascade! 171 public function hydrate(array $data_array): void
201 self::$entityManager->flush(); 172 {
173 //$this->setModePaiement(''); // vaut déjà ''
174 $this->setAll($data_array);
202 } 175 }
203} 176}