diff options
Diffstat (limited to 'src/model/entities/CESU.php')
-rw-r--r-- | src/model/entities/CESU.php | 131 |
1 files changed, 131 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | // src/entities/CESU.php | ||
3 | |||
4 | use Doctrine\ORM\Mapping as ORM; | ||
5 | use Doctrine\ORM\EntityManager; | ||
6 | |||
7 | #[ORM\Entity] | ||
8 | #[ORM\Table(name: 'cesu')] | ||
9 | class CESU | ||
10 | { | ||
11 | #[ORM\Id] | ||
12 | #[ORM\Column(type: 'integer')] | ||
13 | #[ORM\GeneratedValue] | ||
14 | private int|null $id = null; | ||
15 | |||
16 | #[ORM\ManyToOne(targetEntity: Prestation::class, cascade: ['persist'])] | ||
17 | #[ORM\JoinColumn(name: 'id_presta', referencedColumnName: 'id')] | ||
18 | private Prestation|null $presta = null; | ||
19 | |||
20 | #[ORM\Column] | ||
21 | private string $taches; | ||
22 | #[ORM\Column] | ||
23 | private string $duree_travail; | ||
24 | #[ORM\Column] | ||
25 | private float $salaire; | ||
26 | |||
27 | public static EntityManager $entityManager; | ||
28 | |||
29 | public function __construct(Prestation $presta = null) | ||
30 | { | ||
31 | if($presta != null) | ||
32 | { | ||
33 | $this->setPresta($presta); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | // getters | ||
38 | public function getPresta(): Prestation | ||
39 | { | ||
40 | return $this->presta; | ||
41 | } | ||
42 | |||
43 | public function getAllWithWindowFields(): array | ||
44 | { | ||
45 | return [ | ||
46 | "Tâche effectuée:" => $this->taches, | ||
47 | "Durée du travail:" => $this->duree_travail, | ||
48 | "Salaire:" => $this->salaire]; | ||
49 | } | ||
50 | |||
51 | // setters | ||
52 | public function set(string $entry, string $input) | ||
53 | { | ||
54 | $input = $this->cleanSpecialChars($input); // possibilité que $input devienne une chaîne vide | ||
55 | switch($entry) | ||
56 | { | ||
57 | case "Tâche effectuée:": | ||
58 | $this->setTaches($input); | ||
59 | break; | ||
60 | case "Durée du travail:": | ||
61 | $this->setDureeTravail($input); | ||
62 | break; | ||
63 | case "Salaire:": | ||
64 | $this->setSalaire($input); | ||
65 | break; | ||
66 | } | ||
67 | } | ||
68 | private function setPresta(Prestation $input) // private? | ||
69 | { | ||
70 | $this->presta = $input; | ||
71 | } | ||
72 | public function setTaches(string $value) | ||
73 | { | ||
74 | $this->taches = $value; | ||
75 | return($this); | ||
76 | } | ||
77 | public function setDureeTravail(string $value) | ||
78 | { | ||
79 | $this->duree_travail = $value; | ||
80 | return($this); | ||
81 | } | ||
82 | public function setSalaire($value) | ||
83 | { | ||
84 | $value = str_replace(',', '.', $value); | ||
85 | $this->salaire = (float) $value; | ||
86 | return($this); | ||
87 | } | ||
88 | |||
89 | private function setAll(array $input) // private? | ||
90 | { | ||
91 | $this->taches = $input[0]; | ||
92 | $this->duree_travail = $input[1]; | ||
93 | $this->salaire = (float)$input[2]; | ||
94 | } | ||
95 | |||
96 | // à mettre plus tard dans une classe mère | ||
97 | protected function cleanSpecialChars(string $data): string | ||
98 | { | ||
99 | $search = ['"']; | ||
100 | return str_replace($search, '', $data); | ||
101 | } | ||
102 | // à mettre plus tard dans une classe mère | ||
103 | public function hydrate(string $answers) | ||
104 | { | ||
105 | $answers = $this->cleanSpecialChars($answers); // possibilité que $answers devienne une chaine vide | ||
106 | if($answers == '') | ||
107 | { | ||
108 | echo "erreur de CESU::hydrate(), la chaine \$answers est vide.\n"; | ||
109 | return false; | ||
110 | } | ||
111 | $data_array = explode('|', $answers); // array | ||
112 | |||
113 | $check = false; | ||
114 | if(count($data_array) === 4) // facture normale | ||
115 | { | ||
116 | $this->getPresta()->setModePaiement($data_array[3]); | ||
117 | //array_pop($data_array); // supprime la dernière case | ||
118 | unset($data_array[3]); | ||
119 | $this->setAll($data_array); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | echo "erreur de CESU::hydrate(), le tableau \$data_array n'a pas la taille attendue.\n"; | ||
124 | return false; | ||
125 | } | ||
126 | |||
127 | //self::$entityManager->persist('Prestation'); | ||
128 | self::$entityManager->persist($this); // $Presta avec en cascade! | ||
129 | self::$entityManager->flush(); | ||
130 | } | ||
131 | } | ||