blob: 92a4b3158d71d7d0595128f6f47bfca5e9d5c9e6 (
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
|
<?php
// model/Clients.php
class Clients extends Model
{
// lecture des données ou hydratation
public $ID;
public $prenom_nom;
public $adresse;
public $code_client;
public $commentaires;
use ModelChildren; // renseigne parent::table
//~ public function set(string $variable, $value)
//~ {
//~ $this->$variable = $value;
//~ return($this);
//~ }
// setters
public function setID(int $value) // inutile? il s'autoincrémente
{
$this->ID = $value;
return($this);
}
public function setPrenom_nom(string $value)
{
$this->prenom_nom = $value;
return($this);
}
public function setAdresse(string $value)
{
$this->adresse = $value;
return($this);
}
public function setCode_client(string $value)
{
$this->code_client = $value;
return($this);
}
public function setCommentaires(string $value)
{
$this->commentaires = $value;
return($this);
}
public function newRow(array $input)
{
$this->hydrate(['prenom_nom' => $input[0], 'adresse' => $input[1], 'code_client' => $input[2], 'commentaires' => $input[3]]);
$this->create();
$this->setIdFromLastInsertID(); // dans ModelChildren, n'utilise pas Model::execQuery()
}
public function findByKeywords(array $keywords, string $field): array
{
$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);
}
}
|