setPresta($presta); } // getters public function getPresta(): ?Prestation { return $this->presta; } public function getSalaire(): float { return $this->salaire; } public function getPaySlipDate(): string { return $this->date_bulletin_paie; } 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): void { $this->presta = $input; } public function setTaches(string $value): CESU { $this->taches = $value; return($this); } public function setDureeTravail(string $value): CESU { $this->duree_travail = $value; return($this); } public function setSalaire($value): CESU { $value = str_replace(',', '.', $value); $this->salaire = (float) $value; return($this); } public function setPaySlipDate(string $date): void // date 'aaaa-mm-jj' (sans heure) { $this->date_bulletin_paie = $date; } private function setAll(array $input): void { $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): void { $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); } else { echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; return; } //self::$entityManager->persist('Prestation'); self::$entityManager->persist($this); // $Presta avec en cascade! self::$entityManager->flush(); } }