From bf6655a534a6775d30cafa67bd801276bda1d98d Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 13 Aug 2024 23:45:21 +0200 Subject: =?UTF-8?q?VERSION=200.2=20doctrine=20ORM=20et=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/CESU.php | 131 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/model/entities/CESU.php (limited to 'src/model/entities/CESU.php') diff --git a/src/model/entities/CESU.php b/src/model/entities/CESU.php new file mode 100644 index 0000000..09a2542 --- /dev/null +++ b/src/model/entities/CESU.php @@ -0,0 +1,131 @@ +setPresta($presta); + } + } + + // getters + public function getPresta(): Prestation + { + return $this->presta; + } + + public function getAllWithWindowFields(): array + { + return [ + "Tâche effectuée:" => $this->taches, + "Durée du travail:" => $this->duree_travail, + "Salaire:" => $this->salaire]; + } + + // setters + public function set(string $entry, string $input) + { + $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide + switch($entry) + { + case "Tâche effectuée:": + $this->setTaches($input); + break; + case "Durée du travail:": + $this->setDureeTravail($input); + break; + case "Salaire:": + $this->setSalaire($input); + break; + } + } + private function setPresta(Prestation $input) // private? + { + $this->presta = $input; + } + public function setTaches(string $value) + { + $this->taches = $value; + return($this); + } + public function setDureeTravail(string $value) + { + $this->duree_travail = $value; + return($this); + } + public function setSalaire($value) + { + $value = str_replace(',', '.', $value); + $this->salaire = (float) $value; + return($this); + } + + private function setAll(array $input) // private? + { + $this->taches = $input[0]; + $this->duree_travail = $input[1]; + $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) + { + $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 false; + } + $data_array = explode('|', $answers); // array + + $check = false; + 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); + } + else + { + echo "erreur de CESU::hydrate(), 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(); + } +} -- cgit v1.2.3