summaryrefslogtreecommitdiff
path: root/src/model/entities/CESU.php
blob: 3e7ab1041a755b226e07da96b6fed63d2712e97f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
// src/entities/CESU.php

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'cesu')]
class CESU extends Prestation
{
    #[ORM\Column]
    private string $taches;
    #[ORM\Column]
    private string $duree_travail;
    #[ORM\Column]
    private float $salaire;

    /*#[ORM\Column]*/ // pour plus tard
    private ?string $date_bulletin_paie = null; // format Y-m-d conservé tout du long: formulaire, BDD, affichage

    // getters
    public function getSalaire(): float
    {
        return $this->salaire;
    }

    public function getPaySlipDate(): string
    {
        return $this->date_bulletin_paie;
    }
    
    public function getAllWithWindowFields(): array
    {
        $common_data = parent::getAllWithWindowFields();
        return array_merge($common_data, [
            "Tâche effectuée:" => $this->taches,
            "Durée du travail:" => $this->duree_travail,
            "Salaire:" => $this->salaire]);
    }

    // setters
    public function set(string $entry, string $input): void
    {
        $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;
            default: // gérer les champ dans Prestation
                parent::set($entry, $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(string $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];
    }

    public function validateForm(array $data_array): bool
    {
        if(count($data_array) === 4){
            return true;
        }
        else{
            echo "erreur de CESU::validateForm(), le tableau \$data_array n'a pas la taille attendue.\n";
            return false;
        }
    }

    // à mettre plus tard dans une classe mère
    public function hydrate(array $data_array): void
    {
        $this->setModePaiement($data_array[3]);
        //array_pop($data_array); // supprime la dernière case
        unset($data_array[3]);
        $this->setAll($data_array);
    }
}