From 0161ac4d632af7d45f4fe9d68c1ba3a86f094fc4 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 20 Oct 2026 21:49:17 +0200 Subject: =?UTF-8?q?mise=20en=20place=20de=20l'h=C3=A9ritage=202,=20nombreu?= =?UTF-8?q?ses=20simplifications=20et=20factorisations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/Location.php | 63 ++++++++++++----------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'src/model/entities/Location.php') 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 @@ // src/entities/Location.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'locations')] @@ -27,17 +26,7 @@ class Location extends Prestation #[ORM\Column] protected float $caution; - public static EntityManager $entityManager; - - public function __construct(?Prestation $presta = null){ - $this->setPresta($presta); - } - // getters - public function getPresta(): Prestation - { - return $this->presta; - } public function getLoyer(): float { return $this->loyer_hebdo; @@ -54,7 +43,8 @@ class Location extends Prestation public function getAllWithWindowFields(): array { - return [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Désignation:" => $this->designation, "Description du modèle:" => $this->modele_description, "Valeur:" => $this->valeur, @@ -63,7 +53,7 @@ class Location extends Prestation "Durée de la location:" => $this->duree_location, "Loyer Hebdomadaire:" => $this->loyer_hebdo, "Loyers Payés:" => $this->loyers_payes, - "Caution:" => $this->caution]; + "Caution:" => $this->caution]); } // setters @@ -99,11 +89,9 @@ class Location extends Prestation case "Caution:": $this->setCaution($input); break; - } - } - private function setPresta(Prestation $input): void // private? - { - $this->presta = $input; + default: // gérer les champ dans Prestation + parent::set($entry, $input); + } } public function setDesignation(string $value): Location { @@ -168,36 +156,21 @@ class Location extends Prestation $this->caution = (int)$input[7]; } - // à mettre plus tard dans une classe mère - protected function cleanSpecialChars(string $data): string - { - $search = ['"']; - return str_replace($search, '', $data); - } - // à mettre plus tard dans une classe mère - public function hydrate(string $answers): void + public function validateForm(array $data_array): bool { - $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide - if($answers == '') - { - echo "erreur de Location::hydrate(), la chaine \$answers est vide.\n"; - return; - } - $data_array = explode('|', $answers); // array - - if(count($data_array) === 8) - { - $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" - $this->setAll($data_array); + if(count($data_array) === 8){ + return true; } - else - { - echo "erreur de Location::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; - return; + else{ + echo "erreur de Location::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; + return false; } + } - //self::$entityManager->persist('Prestation'); - self::$entityManager->persist($this); // $Presta avec en cascade! - self::$entityManager->flush(); + // à mettre plus tard dans une classe mère + public function hydrate(array $data_array): void + { + //$this->setModePaiement(''); // vaut déjà '' + $this->setAll($data_array); } } -- cgit v1.2.3