MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
msubdetailvalidators.class
Ir para a documentação deste ficheiro.
1
<?php
2
29
class
MSubDetailValidators
extends
MGrid
30
{
31
public
$errors
;
32
public
$validators
= array();
33
public
$form
;
34
35
public
function
__construct
()
36
{
37
}
38
44
public
function
setValidators
(
$validators
)
45
{
46
$this->validators = (array)
$validators
;
47
}
48
54
public
function
getValidators
()
55
{
56
return
$this->validators
;
57
}
58
65
public
function
transformToStdClasses
($valids=NULL)
66
{
67
$validators
= array();
68
69
if
( !$valids )
70
{
71
$valids =
$this->validators
;
72
}
73
74
foreach
( $valids as $line => $validator )
75
{
76
$validators
[$line] =
new
stdClass();
77
$validators
[$line]->id = $validator->id;
78
$validators
[$line]->field = $validator->field;
79
$validators
[$line]->min = $validator->min;
80
$validators
[$line]->max = $validator->max;
81
$validators
[$line]->type = $validator->type;
82
$validators
[$line]->chars = $validator->chars;
83
$validators
[$line]->mask = $validator->mask;
84
$validators
[$line]->checker = $validator->checker;
85
$validators
[$line]->msgerr = $validator->msgerr;
86
$validators
[$line]->html = $validator->html;
87
$validators
[$line]->label = $validator->label;
88
$validators
[$line]->value = $validator->value;
89
$validators
[$line]->hint = $validator->hint;
90
$validators
[$line]->regexp = $validator->regexp;
91
$validators
[$line]->name = $validator->name;
92
$validators
[$line]->form = $validator->form;
93
}
94
95
return
$validators
;
96
}
97
104
public
static
function
transformToMValidators
($valids)
105
{
106
$validators
= array();
107
108
foreach
( $valids as $line => $validator )
109
{
110
switch
( $validator->checker )
111
{
112
case
'EMAIL'
:
113
$validators
[$line] =
new
MEmailValidator
($validator->field);
114
break
;
115
case
'PASSWORD'
:
116
$validators
[$line] =
new
MPasswordValidator
($validator->field);
117
break
;
118
case
'TIME'
:
119
$validators
[$line] =
new
MTIMEValidator
($validator->field);
120
break
;
121
case
'CPF'
:
122
$validators
[$line] =
new
MCPFValidator
($validator->field);
123
break
;
124
case
'CNPJ'
:
125
$validators
[$line] =
new
MCNPJValidator
($validator->field);
126
break
;
127
case
'DATEDMY'
:
128
$validators
[$line] =
new
MDATEDMYValidator
($validator->field);
129
break
;
130
case
'DATEYMD'
:
131
$validators
[$line] =
new
MDATEYMDValidator
($validator->field);
132
break
;
133
case
'COMPARE'
:
134
$validators
[$line] =
new
MCompareValidator
($validator->field);
135
break
;
136
case
'RANGE'
:
137
$validators
[$line] =
new
MRangeValidator
($validator->field);
138
break
;
139
case
'REGEXP'
:
140
$validators
[$line] =
new
MRegExpValidator
($validator->field);
141
break
;
142
case
'DATETimeDMY'
:
143
$validators
[$line] =
new
MDATETimeDMYValidator
($validator->field);
144
break
;
145
default
:
146
$validators
[$line] =
new
MValidator
();
147
break
;
148
}
149
$validators
[$line]->id = $validator->id;
150
$validators
[$line]->field = $validator->field;
151
$validators
[$line]->min = $validator->min;
152
$validators
[$line]->max = $validator->max;
153
$validators
[$line]->type = $validator->type;
154
$validators
[$line]->chars = $validator->chars;
155
$validators
[$line]->mask = $validator->mask;
156
$validators
[$line]->checker = $validator->checker;
157
$validators
[$line]->msgerr = $validator->msgerr;
158
$validators
[$line]->html = $validator->html;
159
$validators
[$line]->label = $validator->label;
160
$validators
[$line]->value = $validator->value;
161
$validators
[$line]->hint = $validator->hint;
162
$validators
[$line]->regexp = $validator->regexp;
163
$validators
[$line]->name = $validator->name;
164
$validators
[$line]->form = $validator->form;
165
}
166
167
return
$validators
;
168
}
169
170
public
function
setForm
(
MForm
$form
)
171
{
172
$this->form =
$form
;
173
}
174
182
public
function
getValidatorMessage
($message, $valid)
183
{
184
$msg = _M($message, NULL, $valid->field);
185
186
if
( $valid->msgerr )
187
{
188
$msg = $valid->msgerr;
189
}
190
else
if
( $valid->label )
191
{
192
$msg = _M($message, NULL, $valid->label);
193
}
194
else
if
( $this->form )
195
{
196
//Get label name of form field
197
$field = $this->form->getField($valid->field);
198
if
( $field->label )
199
{
200
$msg = _M($message, NULL, $field->label);
201
}
202
}
203
return
$msg;
204
}
205
206
public
function
validate
(
$data
= NULL,
$validators
= NULL)
207
{
208
$errors
=
$this->errors
;
209
if
( !
$data
)
210
{
211
foreach
( $this->validators as $v )
212
{
213
$data
[] =
MIOLO::_REQUEST
($v->field);
214
}
215
}
216
217
if
( !
$validators
)
218
{
219
$validators
= $this->
getValidators
();
220
}
221
222
if
( !
$validators
|| !is_array(
$validators
) )
223
{
224
return
null
;
225
}
226
227
foreach
(
$validators
as $line => $valid )
228
{
229
$field = $valid->field;
230
if
( ($valid->type ==
'required'
) && (
$data
->$field ==
''
) )
231
{
232
$errors
[] = $this->
getValidatorMessage
(_M(
'The field "@1" is required.'
), $valid);
233
}
234
else
if
(
$data
->$field )
235
{
236
$msg_invalid = $this->
getValidatorMessage
(_M(
'The field "@1" is invalid.'
), $valid);
237
if
( ($valid->checker ==
'REGEXP'
) && ($valid->regexp) )
238
{
239
$ok = preg_match(
'/'
.$valid->regexp.
'/'
,
$data
->$field);
240
if
( !$ok )
241
{
242
$errors
[] = $msg_invalid;
243
}
244
}
245
else
if
( $valid->checker ==
'DATEDMY'
)
246
{
247
$date = explode(
'/'
,
$data
->$field);
248
if
( !preg_match(
'/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/'
,
$data
->$field) || !checkdate($date[1], $date[0], $date[2]) )
249
{
250
$errors
[] = $msg_invalid;
251
}
252
}
253
else
if
( ($valid->checker ==
'TIME'
) && (!preg_match(
'/^[0-9]{2}:[0-5][0-9]$/'
,
$data
->$field)) )
254
{
255
$errors
[] = $msg_invalid;
256
}
257
else
if
( ($valid->checker ==
'EMAIL'
) && (!
is_valid_email
(
$data
->$field)) )
258
{
259
$errors
[] = $msg_invalid;
260
}
261
else
if
( ($valid->id ==
'cep'
) && (!preg_match(
"/^[0-9]{5}-[0-9]{3}$/"
,
$data
->$field)) )
262
{
263
$errors
[] = $msg_invalid;
264
}
265
// TODO: CPF, CNPJ, PHONE and RANGE validator
266
// TODO: Put focus at the first unvalid field
267
}
268
269
if
( $valid->checker ==
'unique'
)
270
{
271
$tempData = MSubDetail::getData(
$data
->MSubDetail);
272
if
( is_array($tempData) && $tempData )
273
{
274
foreach
( $tempData as $l => $i )
275
{
276
if
( !$i->removeData )
277
{
278
if
( $i->$field ==
$data
->$field && !empty($i->$field) )
279
{
280
// If is the edited line, it is not duplicating.
281
if
( is_null(
$data
->arrayItemTemp) || (
$data
->arrayItemTemp != $i->arrayItem) )
282
{
283
$errors
[] = $this->
getValidatorMessage
(_M(
'The field "@1" must be unique.'
), $valid);
284
}
285
}
286
}
287
}
288
}
289
}
290
}
291
292
return
$errors
;
293
}
294
295
}
296
297
class
MSubDetailUniqueValidator
extends
MValidator
298
{
299
308
function
__construct
(
$field
,
$label
=
null
,
$type
=
'optional'
,
$msgerr
=
null
)
309
{
310
parent::__construct();
311
$this->
id
=
'unique'
;
312
$this->field =
$field
;
313
$this->label =
$label
;
314
$this->mask =
''
;
315
$this->type =
$type
;
316
$this->checker =
'unique'
;
317
//$this->min = 0;
318
//$this->max = $max;
319
$this->chars =
'ALL'
;
320
$this->msgerr =
$msgerr
;
321
}
322
323
}
324
325
class
MSubDetailDateValidator
extends
MValidator
326
{
327
328
function
__construct
(
$field
,
$label
=
null
,
$msgerr
=
null
,
$mask
=
"dd/mm/yyyy"
)
329
{
330
parent::__construct();
331
$this->
id
=
'date'
;
332
$this->field =
$field
;
333
$this->label =
$label
;
334
$this->mask =
$mask
;
335
$this->type =
'date'
;
336
$this->chars =
'ALL'
;
337
$this->msgerr =
$msgerr
;
338
}
339
340
}
341
342
function
is_valid_email
($email)
343
{
344
if
( !preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/"
, $email) )
345
{
346
return
false
;
347
}
348
return
true
;
349
}
350
351
?>
MCNPJValidator
Definição
mvalidator.class:390
MCPFValidator
Definição
mvalidator.class:354
MCompareValidator
Definição
mvalidator.class:498
MDATEDMYValidator
Definição
mvalidator.class:426
MDATETimeDMYValidator
Definição
mvalidator.class:767
MDATEYMDValidator
Definição
mvalidator.class:462
MEmailValidator
Definição
mvalidator.class:182
MFormControl\$label
$label
Definição
mformcontrol.class:5
MForm
Definição
mform.class:9
MGrid
Definição
gridcontrols.class:739
MGrid\$data
$data
Definição
gridcontrols.class:746
MIOLO\_REQUEST
static _REQUEST( $vars, $from='ALL')
Definição
miolo.class:1109
MPasswordValidator
Definição
mvalidator.class:214
MRangeValidator
Definição
mvalidator.class:573
MRegExpValidator
Definição
mvalidator.class:654
MSubDetailDateValidator
Definição
msubdetailvalidators.class:326
MSubDetailDateValidator\__construct
__construct($field, $label=null, $msgerr=null, $mask="dd/mm/yyyy")
Definição
msubdetailvalidators.class:328
MSubDetailUniqueValidator
Definição
msubdetailvalidators.class:298
MSubDetailUniqueValidator\__construct
__construct($field, $label=null, $type='optional', $msgerr=null)
Definição
msubdetailvalidators.class:308
MSubDetailValidators
Definição
msubdetailvalidators.class:30
MSubDetailValidators\__construct
__construct()
Definição
msubdetailvalidators.class:35
MSubDetailValidators\$form
$form
Definição
msubdetailvalidators.class:33
MSubDetailValidators\transformToStdClasses
transformToStdClasses($valids=NULL)
Definição
msubdetailvalidators.class:65
MSubDetailValidators\transformToMValidators
static transformToMValidators($valids)
Definição
msubdetailvalidators.class:104
MSubDetailValidators\getValidators
getValidators()
Definição
msubdetailvalidators.class:54
MSubDetailValidators\setForm
setForm(MForm $form)
Definição
msubdetailvalidators.class:170
MSubDetailValidators\$validators
$validators
Definição
msubdetailvalidators.class:32
MSubDetailValidators\setValidators
setValidators($validators)
Definição
msubdetailvalidators.class:44
MSubDetailValidators\$errors
$errors
Definição
msubdetailvalidators.class:31
MSubDetailValidators\validate
validate($data=NULL, $validators=NULL)
Definição
msubdetailvalidators.class:206
MSubDetailValidators\getValidatorMessage
getValidatorMessage($message, $valid)
Definição
msubdetailvalidators.class:182
MTIMEValidator
Definição
mvalidator.class:318
MValidator
Definição
mvalidator.class:7
MValidator\$field
$field
Definição
mvalidator.class:12
MValidator\$type
$type
Definição
mvalidator.class:27
MValidator\$msgerr
$msgerr
Definição
mvalidator.class:47
MValidator\$mask
$mask
Definição
mvalidator.class:37
is_valid_email
is_valid_email($email)
Definição
msubdetailvalidators.class:342
classes
ui
controls
msubdetailvalidators.class
Gerado por
1.10.0