-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusers.php
131 lines (123 loc) · 3.56 KB
/
users.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
class Users {
protected static $users = array(
array(
"login" => "puyouart",
"nom" => "Puyou",
"prenom" => "Arthur",
"mail" => "[email protected]",
"type" => "etu",
"is_adulte" => true,
"badge_uid" => "123456AB",
"expiration_badge" => "2018-02-16"
),
array(
"login" => "trecouvr",
"nom" => "Recouvreux",
"prenom" => "Thomas",
"mail" => "[email protected]",
"type" => "etu",
"is_adulte" => true,
"badge_uid" => "ABCDABCD",
"expiration_badge" => "2018-01-01"
),
array(
"login" => "mguffroy",
"nom" => "Guffroy",
"prenom" => "Matthieu",
"mail" => "[email protected]",
"type" => "etu",
"is_adulte" => true,
"badge_uid" => "01234567",
"expiration_badge" => "2018-01-01"
),
array(
"login" => "amiotnoe",
"nom" => "Amiot",
"prenom" => "Noe",
"mail" => "[email protected]",
"type" => "etu",
"is_adulte" => true,
"badge_uid" => "00000001",
"expiration_badge" => "2020-01-01"
),
);
public static function getByLogin($login){
foreach(self::$users as $user){
if($user["login"] == $login){
$user["is_cotisant"] = self::isCotisant($login);
return $user;
}
}
return null;
}
public static function getByEmail($email){
foreach(self::$users as $user){
if($user["mail"] == $email){
$user["is_cotisant"] = self::isCotisant($user["login"]);
return $user;
}
}
return null;
}
public static function getByBadge($badge){
foreach(self::$users as $user){
if($user["badge_uid"] == $badge){
$user["is_cotisant"] = self::isCotisant($user["login"]);
return $user;
}
}
return null;
}
public static function isCotisant($login) {
$cotiz = Cotisations::getByUser($login);
foreach ($cotiz as $cotisation) {
if($cotisation["fin"] > date("Y-m-d")) {
return true;
}
}
return false;
}
}
class Cotisations {
protected static $cotisations = array(
array(
"user" => "amiotnoe",
"id" => 1,
"debut" => "1999-01-01",
"fin" => "2017-01-01",
"montant" => "20.00"
),
array(
"user" => "amiotnoe",
"id" => 2,
"debut" => "2017-12-31",
"fin" => "2999-01-01",
"montant" => "20.00"
),
array(
"user" => "puyouart",
"id" => 3,
"debut" => "2017-12-31",
"fin" => "2999-01-01",
"montant" => "20.00"
),
array(
"user" => "mguffroy",
"id" => 4,
"debut" => "2015-01-01",
"fin" => "2016-01-01",
"montant" => "10.00"
),
);
public static function getByUser($login){
$cotiz = [];
foreach(self::$cotisations as $cotisation){
if($cotisation["user"] == $login){
unset($cotisation["user"]);
$cotiz[] = $cotisation;
}
}
return !empty($cotiz) ? $cotiz : null;
}
}