MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mstepbystepform.class
Ir para a documentação deste ficheiro.
1
<?php
2
33
class
MStepByStepForm
extends
MForm
34
{
35
public
$steps
;
36
public
$step
;
37
public
$nextStep
;
38
public
$stepName
;
39
public
$prevStep
;
40
public
$data
;
41
private
static
$defaultButtons =
true
;
42
private
static
$showImageOnButtons =
false
;
43
44
const
BUTTONS_DIV_ID
=
'stepButtonsDiv'
;
45
const
BUTTONS_DIV_STYLE
=
'm-stepbystep-buttons'
;
46
const
BUTTONS_DIV_IMG_STYLE
=
'm-stepbystep-buttons-img'
;
47
56
public
function
__construct
(
$title
,
$steps
= NULL,
$step
= NULL,
$nextStep
= NULL)
57
{
58
$MIOLO
=
MIOLO::getInstance
();
59
60
$this->steps =
$steps
;
61
$this->stepName =
MIOLO::getCurrentAction
();
62
63
parent::__construct(
$title
);
64
$this->
eventHandler
();
65
66
$this->buttons = array();
67
$this->step =
$step
;
68
$this->nextStep =
$nextStep
;
69
}
70
71
public
function
createFields
()
72
{
73
$MIOLO
=
MIOLO::getInstance
();
74
$module =
MIOLO::getCurrentModule
();
75
76
parent::createFields();
77
78
if
( !self::getCurrentStep() )
79
{
80
$this->
cleanStepData
();
81
}
82
83
$this->step = $this->step ? $this->step :
self::getCurrentStep
() ?
self::getCurrentStep
() : 1;
84
$this->nextStep = $this->nextStep ? $this->nextStep : $this->step+1;
85
86
foreach
( $this->steps as $k => $stp )
87
{
88
if
( $this->step == $k )
89
{
90
$type =
MStep::TYPE_CURRENT
;
91
}
92
elseif ( $this->step < $k )
93
{
94
$type =
MStep::TYPE_NEXT
;
95
}
96
elseif ( $this->step > $k )
97
{
98
$type =
MStep::TYPE_PREVIOUS
;
99
}
100
101
$stepsDiv[$k] =
new
MStep
($k, $stp, $type);
102
}
103
104
/*
105
* If it has more than five steps shows the first, the previous,
106
* the current, the next and the last one.
107
*/
108
if
( count($this->steps) > 5 )
109
{
110
$asteps[] = $stepsDiv[1];
111
if
( $this->step <= 3 )
112
{
113
$asteps[] = $stepsDiv[2];
114
$asteps[] = $stepsDiv[3];
115
$asteps[] = $stepsDiv[4];
116
$asteps[] =
new
MDiv
(NULL,
'...'
,
MStep::HIDE_STYLE
);
117
$asteps[] = $stepsDiv[count($this->steps)];
118
}
119
elseif ( $this->step >= (count($this->steps) - 2) )
120
{
121
$step
= count($this->steps) - 2;
122
$asteps[] =
new
MDiv
(NULL,
'...'
,
MStep::HIDE_STYLE
);
123
$asteps[] = $stepsDiv[
$step
- 1];
124
$asteps[] = $stepsDiv[
$step
];
125
$asteps[] = $stepsDiv[
$step
+ 1];
126
$asteps[] = $stepsDiv[count($this->steps)];
127
}
128
else
129
{
130
$asteps[] =
new
MDiv
(NULL,
'...'
,
MStep::HIDE_STYLE
);
131
$asteps[] = $stepsDiv[$this->step - 1];
132
$asteps[] = $stepsDiv[
$this->step
];
133
$asteps[] = $stepsDiv[$this->step + 1];
134
$asteps[] =
new
MDiv
(
''
,
'...'
,
MStep::HIDE_STYLE
);
135
$asteps[] = $stepsDiv[count($this->steps)];
136
}
137
}
138
else
139
{
140
$asteps = $stepsDiv;
141
}
142
143
$fields
[] =
new
MBaseGroup
(NULL, NULL, $asteps);
144
145
$this->addFields(
$fields
);
146
}
147
152
public
function
nextStepButton_click
()
153
{
154
if
( !$this->nextStep )
155
{
156
$this->nextStep = $this->step ? $this->step + 1 : 2;
157
}
158
159
$this->
prepareData
($this->
getData
());
160
self::setCurrentStep
($this->nextStep);
161
162
$this->
redirect
(
MIOLO::getCurrentModule
(),
MIOLO::getCurrentAction
(), $_GET);
163
}
164
169
public
function
previousStepButton_click
()
170
{
171
if
( !$this->prevStep )
172
{
173
$this->prevStep = $this->step - 1;
174
}
175
176
if
( $this->prevStep < 1 )
177
{
178
$this->prevStep = 1;
179
}
180
181
$this->
prepareData
($this->
getData
());
182
self::setCurrentStep
($this->prevStep);
183
184
$this->
redirect
(
MIOLO::getCurrentModule
(),
MIOLO::getCurrentAction
(), $_GET);
185
}
186
192
public
function
gotoStep
(
$step
)
193
{
194
self::setCurrentStep
(
$step
);
195
$this->
redirect
(
MIOLO::getCurrentModule
(),
MIOLO::getCurrentAction
(), $_GET);
196
}
197
204
public
function
objectToArray
($object)
205
{
206
if
( count($object) > 1 )
207
{
208
$arr = array( );
209
for
( $i = 0; $i < count($object); $i++ )
210
{
211
$arr[] = get_object_vars($object[$i]);
212
}
213
return
$arr;
214
}
215
else
216
{
217
return
get_object_vars($object);
218
}
219
}
220
224
public
function
getStepName
()
225
{
226
return
$this->stepName
;
227
}
228
232
public
function
setStepName
(
$stepName
)
233
{
234
$this->stepName =
$stepName
;
235
}
236
243
public
function
setStepData
(
$data
,
$step
=
null
)
244
{
245
$data
= (object) array_merge($this->
getStepData
(
$step
,
false
), (array)
$data
);
246
$this->
prepareData
(
$data
,
$step
);
247
}
248
256
public
function
getStepData
(
$step
=
null
, $returnAsObject =
true
)
257
{
258
$stepsData = $this->
getAllStepData
();
259
260
// gets the last step data because it's not on session yet
261
if
( $this->
isLastStep
() )
262
{
263
$data
=
self::objectToArray
($this->
getData
());
264
$lastStep = array_pop(array_keys($this->steps));
265
$stepsData[$lastStep] =
$data
;
266
}
267
268
// if a step is given, returns only the specific step data
269
if
(
$step
)
270
{
271
$data
= $returnAsObject ? (object) $stepsData[
$step
] : $stepsData[
$step
];
272
}
273
else
274
{
275
if
( $returnAsObject )
276
{
277
$returnData = array();
278
foreach
( $stepsData as $key =>
$data
)
279
{
280
$returnData = array_merge($returnData,
$data
);
281
}
282
283
$data
= (object) $returnData;
284
}
285
else
286
{
287
$data
= $stepsData;
288
}
289
}
290
291
return
$data
;
292
}
293
299
public
function
cleanStepData
(
$step
=
null
)
300
{
301
if
(
$step
)
302
{
303
$stepsData = $this->
getAllStepData
();
304
$stepsData[
$step
] = NULL;
305
306
$this->
setAllStepData
($stepsData);
307
}
308
else
309
{
310
$this->
setAllStepData
(NULL);
311
}
312
}
313
320
public
function
prepareData
(
$data
=
null
,
$step
=
null
)
321
{
322
if
( !
$step
)
323
{
324
// the first time on the first step, the step is still undefined
325
$step
= $this->step ? $this->step : 1;
326
}
327
328
if
( is_object(
$data
) )
329
{
330
$data
=
self::objectToArray
(
$data
);
331
}
332
333
// verifies if there is already data on session of this step by step
334
$stepData = $this->
getStepData
(
null
,
false
);
335
336
// adds the step data array to be saved on session
337
$stepData[
$step
] =
$data
;
338
339
$this->
setAllStepData
($stepData);
340
}
341
347
public
function
setAllStepData
($stepData)
348
{
349
// serializes the data and saves it
350
$MIOLO
=
MIOLO::getInstance
();
351
$MIOLO
->getSession()->setValue($this->
getStepName
(), serialize($stepData));
352
}
353
359
public
function
getAllStepData
()
360
{
361
$MIOLO
=
MIOLO::getInstance
();
362
$data
= unserialize(
$MIOLO
->getSession()->getValue($this->getStepName()));
363
return
$data
;
364
}
365
369
public
static
function
getCurrentStep
()
370
{
371
return
MIOLO::_REQUEST
(
'step'
);
372
}
373
377
public
static
function
setCurrentStep
(
$step
)
378
{
379
$_GET[
'step'
] =
$step
;
380
}
381
385
public
static
function
getShowImageOnButtons
()
386
{
387
return
self::$showImageOnButtons;
388
}
389
393
public
static
function
setShowImageOnButtons
($showImageOnButtons)
394
{
395
self::$showImageOnButtons = $showImageOnButtons;
396
}
397
403
public
function
getButtons
()
404
{
405
if
( $this->
isFirstStep
() )
406
{
407
$buttons
= $this->
firstStepButtons
();
408
}
409
elseif ( $this->
isLastStep
() )
410
{
411
$buttons
= $this->
lastStepButtons
();
412
}
413
else
414
{
415
$buttons
= $this->
innerStepButtons
();
416
}
417
418
return
$this->
buttonsDiv
(
$buttons
);
419
}
420
427
public
function
finalizeStepByStep
(
$buttons
= NULL)
428
{
429
$label = _M(
'Finished step'
);
430
431
$jsCode =
"
432
document.getElementById('"
.self::BUTTONS_DIV_ID.
"').innerHTML = '';
433
document.getElementById('stepImage_{$this->step}').className = '"
.
MStep::PREVIOUS_ICON_STYLE
.
"';
434
document.getElementById('stepDescription_{$this->step}').innerHTML = '$label'; "
;
435
436
foreach
( $this->steps as
$step
=>
$stepName
)
437
{
438
$jsCode .=
"
439
var element = document.getElementById('divStep_$step');
440
if ( element )
441
{
442
element.className = '"
.MStep::DISABLED_STYLE.
"';
443
element.onclick = '';
444
}"
;
445
}
446
447
$this->page->onLoad($jsCode);
448
449
if
(
$buttons
)
450
{
451
$this->addField($this->
buttonsDiv
(
$buttons
));
452
}
453
else
454
{
455
$div = $this->
buttonsDiv
(array(
new
MButton
(
'closeButton'
, _M(
'Close'
)) ));
456
$this->addField($div);
457
}
458
}
459
463
public
static
function
setDefaultButtons
($defaultButtons)
464
{
465
self::$defaultButtons = $defaultButtons;
466
}
467
471
public
static
function
getDefaultButtons
()
472
{
473
return
self::$defaultButtons;
474
}
475
480
public
function
onLoad
()
481
{
482
if
( self::$defaultButtons )
483
{
484
$this->addFields(array( $this->
getButtons
() ));
485
}
486
487
if
( !$this->
isFirstAccess
($this->step) )
488
{
489
parent::setData($this->
getStepData
($this->step));
490
}
491
}
492
496
public
function
isFirstStep
()
497
{
498
if
( self::getCurrentStep() == 1 || !self::getCurrentStep() )
499
{
500
return
true
;
501
}
502
else
503
{
504
return
false
;
505
}
506
}
507
511
public
function
isLastStep
()
512
{
513
$lastStep = array_pop(array_keys($this->steps));
514
return
$lastStep ==
$this->step
;
515
}
516
523
public
function
isFirstAccess
(
$step
= NULL)
524
{
525
$MIOLO
=
MIOLO::getInstance
();
526
527
if
( !
$step
)
528
{
529
$step
=
$this->step
;
530
}
531
532
$stepsData = $this->
getAllStepData
();
533
534
$data
= $stepsData[
$step
];
535
536
// if is set, returns true
537
return
!
$data
;
538
}
539
544
public
function
cancelButton_click
($args)
545
{
546
$this->
redirect
(
MIOLO::getCurrentModule
(),
MIOLO::getCurrentAction
());
547
}
548
554
public
function
finalizeButton_click
($args)
555
{
556
$MIOLO
=
MIOLO::getInstance
();
557
$module =
MIOLO::getCurrentModule
();
558
$url
=
$MIOLO
->getActionUrl($module,
'main'
);
559
$buttons
[] =
new
MButton
(NULL, _M(
'Close'
),
$url
);
560
$this->
finalizeStepByStep
(
$buttons
);
561
}
562
571
public
function
redirect
($module,
$action
, $args = NULL)
572
{
573
$MIOLO
=
MIOLO::getInstance
();
574
$url
=
$MIOLO
->getActionURL($module,
$action
,
''
, $args);
575
$MIOLO
->page->redirect(
$url
);
576
}
577
581
public
function
cancelButton
()
582
{
583
if
( self::$showImageOnButtons )
584
{
585
$image =
MIOLO::getInstance
()->getUI()->getImageTheme(
MIOLO::getInstance
()->getTheme()->
id
,
'button_cancel.png'
);
586
}
587
return
new
MButton
(
'cancelButton'
,
'<span>'
._M(
'Cancel'
).
'</span>'
, NULL, $image);
588
}
589
593
public
function
nextStepButton
()
594
{
595
if
( self::$showImageOnButtons )
596
{
597
$image =
MIOLO::getInstance
()->getUI()->getImageTheme(
MIOLO::getInstance
()->getTheme()->
id
,
'button_next.png'
);
598
}
599
return
new
MButton
(
'nextStepButton'
,
'<span>'
._M(
'Next step'
).
'</span>'
, NULL, $image);
600
}
601
605
public
function
previousStepButton
()
606
{
607
if
( self::$showImageOnButtons )
608
{
609
$image =
MIOLO::getInstance
()->getUI()->getImageTheme(
MIOLO::getInstance
()->getTheme()->
id
,
'button_previous.png'
);
610
}
611
return
new
MButton
(
'previousStepButton'
,
'<span>'
._M(
'Previous step'
).
'</span>'
, NULL, $image);
612
}
613
617
public
function
finalizeButton
()
618
{
619
if
( self::$showImageOnButtons )
620
{
621
$image =
MIOLO::getInstance
()->getUI()->getImageTheme(
MIOLO::getInstance
()->getTheme()->
id
,
'button_finalize.png'
);
622
}
623
return
new
MButton
(
'finalizeButton'
,
'<span>'
._M(
'Finalize'
).
'</span>'
, NULL, $image);
624
}
625
629
public
function
firstStepButtons
()
630
{
631
return
$this->
buttonsDiv
(array( $this->
nextStepButton
(), $this->
cancelButton
() ));
632
}
633
637
public
function
innerStepButtons
()
638
{
639
return
$this->
buttonsDiv
(array( $this->
nextStepButton
(), $this->
previousStepButton
(), $this->
cancelButton
() ));
640
}
641
645
public
function
lastStepButtons
()
646
{
647
return
$this->
buttonsDiv
(array( $this->
finalizeButton
(), $this->
previousStepButton
(), $this->
cancelButton
() ));
648
}
649
654
public
function
buttonsDiv
(
$buttons
)
655
{
656
$class = self::$showImageOnButtons ?
self::BUTTONS_DIV_IMG_STYLE
:
self::BUTTONS_DIV_STYLE
;
657
$div =
new
MDiv
(self::BUTTONS_DIV_ID,
$buttons
, $class);
658
$div->addBoxStyle(
'direction'
,
'rtl'
);
659
$div->addBoxStyle(
'width'
,
'100%'
);
660
return
$div;
661
}
662
}
663
?>
MBaseGroup
Definição
groupcontrols.class:4
MButton
Definição
buttoncontrols.class:4
MControl\eventHandler
eventHandler()
Definição
mcontrol.class:723
MDiv
Definição
blockcontrols.class:23
MForm
Definição
mform.class:9
MForm\$buttons
$buttons
Definição
mform.class:28
MForm\getData
getData()
Definição
mform.class:1474
MForm\$action
$action
Definição
mform.class:18
MForm\$fields
$fields
Definição
mform.class:33
MForm\$title
$title
Definição
mform.class:13
MIOLO\getCurrentModule
static getCurrentModule()
Definição
miolo.class:1066
MIOLO\_REQUEST
static _REQUEST( $vars, $from='ALL')
Definição
miolo.class:1109
MIOLO\getCurrentAction
static getCurrentAction()
Definição
miolo.class:1086
MIOLO\getInstance
static getInstance()
Definição
miolo.class:134
MStepByStepForm
Definição
mstepbystepform.class:34
MStepByStepForm\setAllStepData
setAllStepData($stepData)
Definição
mstepbystepform.class:347
MStepByStepForm\cancelButton_click
cancelButton_click($args)
Definição
mstepbystepform.class:544
MStepByStepForm\setStepData
setStepData($data, $step=null)
Definição
mstepbystepform.class:243
MStepByStepForm\lastStepButtons
lastStepButtons()
Definição
mstepbystepform.class:645
MStepByStepForm\setCurrentStep
static setCurrentStep($step)
Definição
mstepbystepform.class:377
MStepByStepForm\isLastStep
isLastStep()
Definição
mstepbystepform.class:511
MStepByStepForm\objectToArray
objectToArray($object)
Definição
mstepbystepform.class:204
MStepByStepForm\buttonsDiv
buttonsDiv($buttons)
Definição
mstepbystepform.class:654
MStepByStepForm\nextStepButton_click
nextStepButton_click()
Definição
mstepbystepform.class:152
MStepByStepForm\redirect
redirect($module, $action, $args=NULL)
Definição
mstepbystepform.class:571
MStepByStepForm\gotoStep
gotoStep($step)
Definição
mstepbystepform.class:192
MStepByStepForm\finalizeButton_click
finalizeButton_click($args)
Definição
mstepbystepform.class:554
MStepByStepForm\setDefaultButtons
static setDefaultButtons($defaultButtons)
Definição
mstepbystepform.class:463
MStepByStepForm\setStepName
setStepName($stepName)
Definição
mstepbystepform.class:232
MStepByStepForm\cleanStepData
cleanStepData($step=null)
Definição
mstepbystepform.class:299
MStepByStepForm\$data
$data
Definição
mstepbystepform.class:40
MStepByStepForm\finalizeButton
finalizeButton()
Definição
mstepbystepform.class:617
MStepByStepForm\getAllStepData
getAllStepData()
Definição
mstepbystepform.class:359
MStepByStepForm\cancelButton
cancelButton()
Definição
mstepbystepform.class:581
MStepByStepForm\isFirstAccess
isFirstAccess($step=NULL)
Definição
mstepbystepform.class:523
MStepByStepForm\setShowImageOnButtons
static setShowImageOnButtons($showImageOnButtons)
Definição
mstepbystepform.class:393
MStepByStepForm\BUTTONS_DIV_ID
const BUTTONS_DIV_ID
Definição
mstepbystepform.class:44
MStepByStepForm\$step
$step
Definição
mstepbystepform.class:36
MStepByStepForm\previousStepButton_click
previousStepButton_click()
Definição
mstepbystepform.class:169
MStepByStepForm\prepareData
prepareData($data=null, $step=null)
Definição
mstepbystepform.class:320
MStepByStepForm\innerStepButtons
innerStepButtons()
Definição
mstepbystepform.class:637
MStepByStepForm\$nextStep
$nextStep
Definição
mstepbystepform.class:37
MStepByStepForm\firstStepButtons
firstStepButtons()
Definição
mstepbystepform.class:629
MStepByStepForm\isFirstStep
isFirstStep()
Definição
mstepbystepform.class:496
MStepByStepForm\__construct
__construct($title, $steps=NULL, $step=NULL, $nextStep=NULL)
Definição
mstepbystepform.class:56
MStepByStepForm\getShowImageOnButtons
static getShowImageOnButtons()
Definição
mstepbystepform.class:385
MStepByStepForm\getDefaultButtons
static getDefaultButtons()
Definição
mstepbystepform.class:471
MStepByStepForm\BUTTONS_DIV_IMG_STYLE
const BUTTONS_DIV_IMG_STYLE
Definição
mstepbystepform.class:46
MStepByStepForm\BUTTONS_DIV_STYLE
const BUTTONS_DIV_STYLE
Definição
mstepbystepform.class:45
MStepByStepForm\nextStepButton
nextStepButton()
Definição
mstepbystepform.class:593
MStepByStepForm\getStepName
getStepName()
Definição
mstepbystepform.class:224
MStepByStepForm\$stepName
$stepName
Definição
mstepbystepform.class:38
MStepByStepForm\finalizeStepByStep
finalizeStepByStep($buttons=NULL)
Definição
mstepbystepform.class:427
MStepByStepForm\previousStepButton
previousStepButton()
Definição
mstepbystepform.class:605
MStepByStepForm\createFields
createFields()
Definição
mstepbystepform.class:71
MStepByStepForm\getCurrentStep
static getCurrentStep()
Definição
mstepbystepform.class:369
MStepByStepForm\$steps
$steps
Definição
mstepbystepform.class:35
MStepByStepForm\getStepData
getStepData($step=null, $returnAsObject=true)
Definição
mstepbystepform.class:256
MStepByStepForm\onLoad
onLoad()
Definição
mstepbystepform.class:480
MStepByStepForm\$prevStep
$prevStep
Definição
mstepbystepform.class:39
MStepByStepForm\getButtons
getButtons()
Definição
mstepbystepform.class:403
MStep
Definição
mstep.class:35
MStep\TYPE_NEXT
const TYPE_NEXT
Definição
mstep.class:38
MStep\PREVIOUS_ICON_STYLE
const PREVIOUS_ICON_STYLE
Definição
mstep.class:43
MStep\TYPE_CURRENT
const TYPE_CURRENT
Definição
mstep.class:37
MStep\TYPE_PREVIOUS
const TYPE_PREVIOUS
Definição
mstep.class:36
MStep\HIDE_STYLE
const HIDE_STYLE
Definição
mstep.class:52
$MIOLO
$MIOLO
Definição
mdatetimefield.class:25
$url
$url
Definição
base.php:2
classes
ui
controls
mstepbystepform.class
Gerado por
1.10.0