'non'])] private string $signature_devis = 'non'; public static EntityManager $entityManager; public function __construct(Prestation $presta = null) { if($presta != null) { $this->setPresta($presta); } } // getters public function getPresta(): Prestation { return $this->presta; } public function getAll(): array { // n'utiliser get_object_vars() qu'avec une entité parce qu'on maîtrise le nombre de propriétés return get_object_vars($this); } public function getAllWithWindowFields(): array { //~ $taches = ["Tâches:" => $this->taches]; //~ $champs_communs = [ //~ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, //~ "Pièces:" => $this->pieces, //~ "Total des pièces:" => $this->total_pieces, //~ "Déplacement:" => $this->deplacement, //~ "Total HT:" => $this->total_HT]; //~ $champs_devis = [ //~ "Delai de livraison:" => $this->delai_livraison, //~ "Durée de validité:" => $this->validite_devis, //~ "Devis signé:" => $this->signature_devis]; //~ return $champs_communs + $champs_devis; return [ "Tâches:" => $this->taches, // JUSTE AJOUTÉ "Total Main d'oeuvre:" => $this->total_main_d_oeuvre, "Pièces:" => $this->pieces, "Total des pièces:" => $this->total_pieces, "Déplacement:" => $this->deplacement, "Total HT:" => $this->total_HT, "Delai de livraison:" => $this->delai_livraison, "Durée de validité:" => $this->validite_devis, "Devis signé:" => $this->signature_devis]; } // setters public function set(string $entry, string $input) // trouve la bonne méthode { $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide switch($entry) { case "Tâches:": $this->setTaches($input); break; case "Total Main d'oeuvre:": $this->setTotalMainDOeuvre($input); break; case "Pièces:": $this->setPieces($input); break; case "Total des pièces:": $this->setTotalPieces($input); break; case "Déplacement:": $this->setDeplacement($input); break; case "Prix du devis:": $this->setPrixDevis($input); break; case "Total HT:": $this->setTotalHT($input); break; case "Delai de livraison:": $this->setDelaiLivraison($input); break; case "Durée de validité:": $this->setValiditedevis($input); break; case "Devis signé:": $this->setSignatureDevis($input); break; } } private function setPresta(Prestation $input) // private? { $this->presta = $input; } public function setTaches(string $value) { $this->taches = $value; return($this); } public function setTotalMainDOeuvre($value) { $value = str_replace(',', '.', $value); $this->total_main_d_oeuvre = (float) $value; // float "nettoie" tous les caractères après le dernier chiffre trouvé (ex: 50€ => 50, abc => 0) return($this); } public function setPieces(string $value) { $this->pieces = $value; return($this); } public function setTotalPieces($value) { $value = str_replace(',', '.', $value); $this->total_pieces = (float) $value; return($this); } public function setDeplacement($value) { $value = str_replace(',', '.', $value); $this->deplacement = (float) $value; return($this); } public function setTotalHT($value) { $value = str_replace(',', '.', $value); $this->total_HT = (float) $value; return($this); } public function setPrixDevis($value) { $value = str_replace(',', '.', $value); $this->prix_devis = (float) $value; return($this); } public function setDelaiLivraison(string $value) { $this->delai_livraison = $value; return($this); } public function setValiditedevis(string $value) { $this->validite_devis = $value; return($this); } public function setSignatureDevis(string $value) { $this->signature_devis = $value; return($this); } private function setAll(array $input) // private? { $this->taches = $input[0]; $this->total_main_d_oeuvre = (float)$input[1]; $this->pieces = $input[2]; $this->total_pieces = (float)$input[3]; $this->deplacement = (float)$input[4]; $this->prix_devis = (float)$input[5]; $this->total_HT = (float)$input[6]; $this->delai_livraison = $input[7]; $this->validite_devis = $input[8]; // $signature_devis est renseigné plus tard en modifiant le devis } // à 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 Devis::hydrate(), la chaine \$answers est vide.\n"; return false; } $data_array = explode('|', $answers); // array $check = false; if(count($data_array) === 9) // facture normale { $this->getPresta()->setModePaiement(''); // sécurité, doctrine plante si "null" $this->setAll($data_array); } else { echo "erreur de Devis::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(); } // création d'une facture à partir d'un devis public static function getQuotation(Prestation $Quotation) { $repository = self::$entityManager->getRepository('Devis'); return $repository->findOneBy(['presta' => $Quotation->getId()]); // ne peut y en avoir deux } }