summaryrefslogtreecommitdiff
path: root/src/model/Clients.php
blob: 96615627f38de5e07604328f6a6568623d1b44ee (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
<?php
// model/Clients.php

class Clients extends Model
{
    // lecture des données ou hydratation
    protected $ID; // auto-incrémentée
    protected $prenom_nom;
    protected $code_client;
    protected $adresse;
    protected $telephone;
    protected $courriel;
    protected $commentaires;
	
    use ModelChildren; // pour hydrateFromForm()
    
    public function __construct()
    {
        $this->table = 'clients'; // à mettre dans ModelChildren
    }
    
    //~ public function set(string $variable, $value)
    //~ {
        //~ $this->$variable = $value;
        //~ return($this);
    //~ }
    
    // getters
    public function getID(): int
    {
        return $this->ID;
    }
    public function getCodeClient(): string
    {
        return $this->code_client;
    }
    
    // setters
    //~ public function setID() -> dans le trait ModelChildren
    
    public function setPrenomNom($value)
    {
        $this->prenom_nom = (string) $value;
        return($this);
    }
    public function setCodeClient($value)
    {
        $this->code_client = (string) $value;
        return($this);
    }
    public function setAdresse($value)
    {
        $this->adresse = (string) $value;
        return($this);
    }
    public function setTelephone($value) // chaine parce que zenity renvoie une chaine et parce qu'on garde le 0 au début
    {
        if(is_numeric($value))
        {
            $this->telephone = (string) $value;
        }
        else
        {
            $this->telephone = '';
            echo 'debug: le champ "telephone" ne doit comporter que des nombres, aucun numéro ne sera utilisé' . "\n";
        }
        return($this);
    }
    public function setCourriel($value)
    {
        $this->courriel = (string) $value;
        return($this);
    }
    public function setCommentaires($value)
    {
        $this->commentaires = (string) $value;
        return($this);
    }
    
    
    public function findByKeywords(array $keywords, string $field): array // n'hydrate pas les variables, on doit choisir un client et hydrater ensuite
    {
        $result = [];
        for($i = 0; $i < count($keywords); $i++)
        {
            // tableau à deux dimensions obtenu pour un mot clé
            $query_result = $this->execQuery('SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' LIKE "%' . $keywords[$i] . '%"')->fetchAll();
            foreach($query_result as $one_array) // pour chaque sous tableau
            {
                $already_exist = false;
                for($j = 0; $j < count($result); $j++) // pour chaque tableau déjà enregistré dans le tableau $result
                {
                    if($result[$j]['ID'] === $one_array['ID'])
                    {
                        $already_exist = true;
                    }
                }
                if(!$already_exist)
                {
                    $result[] = $one_array;
                }
            }
        }
        return($result);
    }
}