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
|
{
continue;
}
}
if (isset($data[$key]))
{
if ($config->type == 'email' && trim($data[$key]) !== '' && !filter_var($data[$key], FILTER_VALIDATE_EMAIL))
{
throw new UserException('Adresse e-mail invalide dans le champ "' . $config->title . '".');
}
elseif ($config->type == 'url' && trim($data[$key]) !== '' && !filter_var($data[$key], FILTER_VALIDATE_URL))
{
throw new UserException('Adresse URL invalide dans le champ "' . $config->title . '".');
}
elseif ($config->type == 'date' && trim($data[$key]) !== '' && !Utils::checkDate($data[$key]))
{
throw new UserException('Date invalide "' . $config->title . '", format attendu : AAAA-MM-JJ.');
}
elseif ($config->type == 'datetime' && trim($data[$key]) !== '')
{
if (!Utils::checkDateTime($data[$key]) || !($dt = new DateTime($data[$key])))
{
throw new UserException('Date invalide "' . $config->title . '", format attendu : AAAA-MM-JJ HH:mm.');
}
$data[$key] = $dt->format('Y-m-d H:i');
}
elseif ($config->type == 'tel')
{
$data[$key] = Utils::normalizePhoneNumber($data[$key]);
}
elseif ($config->type == 'country')
{
$data[$key] = strtoupper(substr($data[$key], 0, 2));
}
elseif ($config->type == 'checkbox')
{
$data[$key] = empty($data[$key]) ? 0 : 1;
}
elseif ($config->type == 'number' && trim($data[$key]) !== '')
{
if (empty($data[$key]))
{
$data[$key] = 0;
}
if (!is_numeric($data[$key]))
throw new UserException('Le champ "' . $config->title . '" doit contenir un chiffre.');
}
elseif ($config->type == 'select' && !in_array($data[$key], $config->options))
{
throw new UserException('Le champ "' . $config->title . '" ne correspond pas à un des choix proposés.');
}
elseif ($config->type == 'multiple')
{
|
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
|
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
|
{
continue;
}
}
if (isset($data[$key]))
{
if ($config->type == 'datetime' && trim($data[$key]) !== '')
{
$dt = new DateTime($data[$key]);
$data[$key] = $dt->format('Y-m-d H:i');
}
elseif ($config->type == 'tel')
{
$data[$key] = Utils::normalizePhoneNumber($data[$key]);
}
elseif ($config->type == 'country')
{
$data[$key] = strtoupper(substr($data[$key], 0, 2));
}
elseif ($config->type == 'checkbox')
{
$data[$key] = empty($data[$key]) ? 0 : 1;
}
elseif ($config->type == 'number' && trim($data[$key]) !== '')
{
if (empty($data[$key]))
{
$data[$key] = 0;
}
}
elseif ($config->type == 'select' && !in_array($data[$key], $config->options))
{
throw new UserException('Le champ "' . $config->title . '" ne correspond pas à un des choix proposés.');
}
elseif ($config->type == 'multiple')
{
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
if (is_string($data[$key]) && trim($data[$key]) === '')
{
$data[$key] = null;
}
}
}
if (isset($data['code_postal']) && trim($data['code_postal']) != '')
{
if (!empty($data['pays']) && $data['pays'] == 'FR' && !preg_match('!^\d{5}$!', $data['code_postal']))
{
throw new UserException('Code postal invalide.');
}
}
if (!empty($data['passe']) && strlen($data['passe']) < 5)
{
throw new UserException('Le mot de passe doit faire au moins 5 caractères.');
}
return true;
}
public function add($data = [])
{
$this->_checkFields($data);
$db = DB::getInstance();
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
if (is_string($data[$key]) && trim($data[$key]) === '')
{
$data[$key] = null;
}
}
}
return true;
}
public function add($data = [])
{
$this->_checkFields($data);
$db = DB::getInstance();
|