diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-20 21:49:17 +0200 |
| commit | b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878 (patch) | |
| tree | bbaea156e9d32edf14adad8fe5ce3338014e7710 /src/model/entities/CESU.php | |
| parent | 79bc73d7985f51f2a6a1b3cb6e0115f59afb2ac4 (diff) | |
| download | AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.gz AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.tar.bz2 AppliGestionPHP-b0f06b1d7dc3a790d6d8babe5f0855c08c5f7878.zip | |
mise en place de l'héritage 2, nombreuses simplifications et factorisations
Diffstat (limited to 'src/model/entities/CESU.php')
| -rw-r--r-- | src/model/entities/CESU.php | 71 |
1 files changed, 22 insertions, 49 deletions
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 @@ | |||
| 2 | // src/entities/CESU.php | 2 | // src/entities/CESU.php |
| 3 | 3 | ||
| 4 | use Doctrine\ORM\Mapping as ORM; | 4 | use Doctrine\ORM\Mapping as ORM; |
| 5 | use Doctrine\ORM\EntityManager; | ||
| 6 | 5 | ||
| 7 | #[ORM\Entity] | 6 | #[ORM\Entity] |
| 8 | #[ORM\Table(name: 'cesu')] | 7 | #[ORM\Table(name: 'cesu')] |
| @@ -18,17 +17,7 @@ class CESU extends Prestation | |||
| 18 | /*#[ORM\Column]*/ // pour plus tard | 17 | /*#[ORM\Column]*/ // pour plus tard |
| 19 | private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage | 18 | private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage |
| 20 | 19 | ||
| 21 | public static EntityManager $entityManager; | ||
| 22 | |||
| 23 | public function __construct(?Prestation $presta = null){ | ||
| 24 | $this->setPresta($presta); | ||
| 25 | } | ||
| 26 | |||
| 27 | // getters | 20 | // getters |
| 28 | public function getPresta(): ?Prestation | ||
| 29 | { | ||
| 30 | return $this->presta; | ||
| 31 | } | ||
| 32 | public function getSalaire(): float | 21 | public function getSalaire(): float |
| 33 | { | 22 | { |
| 34 | return $this->salaire; | 23 | return $this->salaire; |
| @@ -41,14 +30,15 @@ class CESU extends Prestation | |||
| 41 | 30 | ||
| 42 | public function getAllWithWindowFields(): array | 31 | public function getAllWithWindowFields(): array |
| 43 | { | 32 | { |
| 44 | return [ | 33 | $common_data = parent::getAllWithWindowFields(); |
| 34 | return array_merge($common_data, [ | ||
| 45 | "Tâche effectuée:" => $this->taches, | 35 | "Tâche effectuée:" => $this->taches, |
| 46 | "Durée du travail:" => $this->duree_travail, | 36 | "Durée du travail:" => $this->duree_travail, |
| 47 | "Salaire:" => $this->salaire]; | 37 | "Salaire:" => $this->salaire]); |
| 48 | } | 38 | } |
| 49 | 39 | ||
| 50 | // setters | 40 | // setters |
| 51 | public function set(string $entry, string $input) | 41 | public function set(string $entry, string $input): void |
| 52 | { | 42 | { |
| 53 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | 43 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide |
| 54 | switch($entry) | 44 | switch($entry) |
| @@ -62,11 +52,9 @@ class CESU extends Prestation | |||
| 62 | case "Salaire:": | 52 | case "Salaire:": |
| 63 | $this->setSalaire($input); | 53 | $this->setSalaire($input); |
| 64 | break; | 54 | break; |
| 65 | } | 55 | default: // gérer les champ dans Prestation |
| 66 | } | 56 | parent::set($entry, $input); |
| 67 | private function setPresta(Prestation $input): void | 57 | } |
| 68 | { | ||
| 69 | $this->presta = $input; | ||
| 70 | } | 58 | } |
| 71 | public function setTaches(string $value): CESU | 59 | public function setTaches(string $value): CESU |
| 72 | { | 60 | { |
| @@ -78,7 +66,7 @@ class CESU extends Prestation | |||
| 78 | $this->duree_travail = $value; | 66 | $this->duree_travail = $value; |
| 79 | return($this); | 67 | return($this); |
| 80 | } | 68 | } |
| 81 | public function setSalaire($value): CESU | 69 | public function setSalaire(string $value): CESU |
| 82 | { | 70 | { |
| 83 | $value = str_replace(',', '.', $value); | 71 | $value = str_replace(',', '.', $value); |
| 84 | $this->salaire = (float) $value; | 72 | $this->salaire = (float) $value; |
| @@ -97,38 +85,23 @@ class CESU extends Prestation | |||
| 97 | $this->salaire = (float)$input[2]; | 85 | $this->salaire = (float)$input[2]; |
| 98 | } | 86 | } |
| 99 | 87 | ||
| 100 | // à mettre plus tard dans une classe mère | 88 | public function validateForm(array $data_array): bool |
| 101 | protected function cleanSpecialChars(string $data): string | ||
| 102 | { | ||
| 103 | $search = ['"']; | ||
| 104 | return str_replace($search, '', $data); | ||
| 105 | } | ||
| 106 | // à mettre plus tard dans une classe mère | ||
| 107 | public function hydrate(string $answers): void | ||
| 108 | { | 89 | { |
| 109 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | 90 | if(count($data_array) === 4){ |
| 110 | if($answers == '') | 91 | return true; |
| 111 | { | ||
| 112 | echo "erreur de CESU::hydrate(), la chaine \$answers est vide.\n"; | ||
| 113 | return; | ||
| 114 | } | ||
| 115 | $data_array = explode('|', $answers); // array | ||
| 116 | |||
| 117 | if(count($data_array) === 4) // facture normale | ||
| 118 | { | ||
| 119 | $this->getPresta()->setModePaiement($data_array[3]); | ||
| 120 | //array_pop($data_array); // supprime la dernière case | ||
| 121 | unset($data_array[3]); | ||
| 122 | $this->setAll($data_array); | ||
| 123 | } | 92 | } |
| 124 | else | 93 | else{ |
| 125 | { | 94 | echo "erreur de CESU::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n"; |
| 126 | echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | 95 | return false; |
| 127 | return; | ||
| 128 | } | 96 | } |
| 97 | } | ||
| 129 | 98 | ||
| 130 | //self::$entityManager->persist('Prestation'); | 99 | // à mettre plus tard dans une classe mère |
| 131 | self::$entityManager->persist($this); // $Presta avec en cascade! | 100 | public function hydrate(array $data_array): void |
| 132 | self::$entityManager->flush(); | 101 | { |
| 102 | $this->setModePaiement($data_array[3]); | ||
| 103 | //array_pop($data_array); // supprime la dernière case | ||
| 104 | unset($data_array[3]); | ||
| 105 | $this->setAll($data_array); | ||
| 133 | } | 106 | } |
| 134 | } | 107 | } |
