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(); } }