From b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 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/CESU.php | 71 ++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) (limited to 'src/model/entities/CESU.php') diff --git a/src/model/entities/CESU.php b/src/model/entities/CESU.php index b840ac9..3e7ab10 100644 --- a/src/model/entities/CESU.php +++ b/src/model/entities/CESU.php @@ -2,7 +2,6 @@ // src/entities/CESU.php use Doctrine\ORM\Mapping as ORM; -use Doctrine\ORM\EntityManager; #[ORM\Entity] #[ORM\Table(name: 'cesu')] @@ -18,17 +17,7 @@ class CESU extends Prestation /*#[ORM\Column]*/ // pour plus tard private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage - public static EntityManager $entityManager; - - public function __construct(?Prestation $presta = null){ - $this->setPresta($presta); - } - // getters - public function getPresta(): ?Prestation - { - return $this->presta; - } public function getSalaire(): float { return $this->salaire; @@ -41,14 +30,15 @@ class CESU extends Prestation public function getAllWithWindowFields(): array { - return [ + $common_data = parent::getAllWithWindowFields(); + return array_merge($common_data, [ "Tâche effectuée:" => $this->taches, "Durée du travail:" => $this->duree_travail, - "Salaire:" => $this->salaire]; + "Salaire:" => $this->salaire]); } // setters - public function set(string $entry, string $input) + public function set(string $entry, string $input): void { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide switch($entry) @@ -62,11 +52,9 @@ class CESU extends Prestation case "Salaire:": $this->setSalaire($input); break; - } - } - private function setPresta(Prestation $input): void - { - $this->presta = $input; + default: // gérer les champ dans Prestation + parent::set($entry, $input); + } } public function setTaches(string $value): CESU { @@ -78,7 +66,7 @@ class CESU extends Prestation $this->duree_travail = $value; return($this); } - public function setSalaire($value): CESU + public function setSalaire(string $value): CESU { $value = str_replace(',', '.', $value); $this->salaire = (float) $value; @@ -97,38 +85,23 @@ class CESU extends Prestation $this->salaire = (float)$input[2]; } - // à 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 CESU::hydrate(), la chaine \$answers est vide.\n"; - return; - } - $data_array = explode('|', $answers); // array - - if(count($data_array) === 4) // facture normale - { - $this->getPresta()->setModePaiement($data_array[3]); - //array_pop($data_array); // supprime la dernière case - unset($data_array[3]); - $this->setAll($data_array); + if(count($data_array) === 4){ + return true; } - else - { - echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; - return; + else{ + echo "erreur de CESU::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($data_array[3]); + //array_pop($data_array); // supprime la dernière case + unset($data_array[3]); + $this->setAll($data_array); } } -- cgit v1.2.3