Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezwizardbase.php
Go to the documentation of this file.
1 <?php
17 class eZWizardBase
18 {
22 public $TPL;
23 const STAGE_PRE = 0;
24 const STAGE_POST = 1;
25
33 public function __construct( $tpl, &$module, $storageName = false )
34 {
35 if ( $storageName )
36 {
37 $this->StorageName = $storageName;
38 }
39
40 $this->TPL = $tpl;
41 $this->Module = $module;
42 $this->HTTP = eZHTTPTool::instance();
43 $this->VariableList = $this->HTTP->sessionVariable( $this->StorageName . $this->VariableListName );
44 $this->MetaData = $this->HTTP->sessionVariable( $this->StorageName . $this->MetaDataName );
45
46 $this->initialize();
47 }
48
52 function initialize()
53 {
54 if ( !$this->hasMetaData( 'current_step' ) )
55 {
56 $this->setMetaData( 'current_step', 0 );
57 }
58
59 if ( !$this->hasMetaData( 'current_stage' ) )
60 {
61 $this->setMetaData( 'current_stage', eZWizardBase::STAGE_PRE );
62 }
63 }
64
65 function attributes()
66 {
67 return array( 'error_count',
68 'error_list',
69 'warning_count',
70 'warning_list',
71 'step_template',
72 'variable_list',
73 'url' );
74 }
75
76 function hasAttribute( $attr )
77 {
78 return in_array( $attr, $this->attributes() );
79 }
80
81 function attribute( $attr )
82 {
83 switch( $attr )
84 {
85 case 'error_count':
86 {
87 return count( $this->ErrorList );
88 } break;
89
90 case 'error_list':
91 {
92 return $this->ErrorList;
93 } break;
94
95 case 'warning_count':
96 {
97 return count( $this->WarningList );
98 } break;
99
100 case 'warning_list':
101 {
102 return $this->WarningList;
103 } break;
104
105 case 'step_template':
106 {
107 return $this->stepTemplate();
108 } break;
109
110 case 'variable_list':
111 {
112 return $this->variableList();
113 } break;
114
115 case 'url':
116 {
117 return $this->WizardURL;
118 } break;
119
120 default:
121 {
122 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
123 return null;
124 }
125 break;
126 }
127 }
128
135 function run()
136 {
137 if ( $this->HTTP->hasPostVariable( 'PreviousButton' ) )
138 {
139 return $this->previousStep();
140 }
141
142 switch( $this->metaData( 'current_stage' ) )
143 {
144 case eZWizardBase::STAGE_PRE:
145 {
146 $this->preCheck();
147 $this->nextStep();
148 if ( $this->skip() )
149 {
150 return $this->nextStep();
151 }
152 return $this->process();
153 } break;
154
155 case eZWizardBase::STAGE_POST:
156 {
157 if ( $this->postCheck() )
158 {
159 return $this->nextStep();
160 }
161 else
162 {
163 return $this->process();
164 }
165 } break;
166 }
167 }
168
178 function preCheck()
179 {
180 return true;
181 }
182
192 function postCheck()
193 {
194 if ( $this->HTTP->hasPostVariable( 'NextButton' ) )
195 {
196 return true;
197 }
198
199 return false;
200 }
201
211 function skip()
212 {
213 return false;
214 }
215
222 function process()
223 {
224 }
225
232 function setMetaData( $key, $value )
233 {
234 $this->MetaData[$key] = $value;
235 eZDebug::writeNotice( 'Set MetaData : [' . $key . '] = ' . $value, __METHOD__ );
236 $this->savePersistentData();
237 }
238
243 function metaData( $key )
244 {
245 return $this->MetaData[$key];
246 }
247
251 function hasMetaData( $key )
252 {
253 return isset( $this->MetaData[$key] );
254 }
255
262 function setVariable( $key, $value )
263 {
264 $this->VariableList[$key] = $value;
265 $this->savePersistentData();
266 }
267
275 function &variable( $key )
276 {
277 if ( isset( $this->VariableList[$key] ) )
278 $retValue = $this->VariableList[$key];
279 else
280 $retValue = false;
281 return $retValue;
282 }
283
291 function hasVariable( $key )
292 {
293 return isset( $this->VariableList[$key] );
294 }
295
301 function variableList()
302 {
303 return $this->VariableList;
304 }
305
312 function stepTemplate()
313 {
314 return $this->StepTemplateBase . '_' . ( $this->metaData( 'current_step' ) + 1 ) . '.tpl';
315 }
316
320 function cleanup()
321 {
322 $this->HTTP->removeSessionVariable( $this->StorageName . $this->MetaDataName );
323 $this->HTTP->removeSessionVariable( $this->StorageName . $this->VariableListName );
324 $this->MetaData = array();
325 $this->VariableList = array();
326 }
327
331 function previousStep()
332 {
333 $this->setMetaData( 'current_stage', eZWizardBase::STAGE_PRE );
334 $this->setMetaData( 'current_step', $this->metaData( 'current_step' ) - 1 );
335 $this->savePersistentData();
336
337 return $this->Module->redirectTo( $this->WizardURL );
338 }
339
343 function nextStep()
344 {
345 if ( $this->metaData( 'current_stage' ) == eZWizardBase::STAGE_PRE )
346 {
347 $this->setMetaData( 'current_stage', eZWizardBase::STAGE_POST );
348 }
349 else
350 {
351 $this->setMetaData( 'current_stage', eZWizardBase::STAGE_PRE );
352 $this->setMetaData( 'current_step', $this->metaData( 'current_step' ) + 1 );
353
354 return $this->Module->redirectTo( $this->WizardURL );
355 }
356
357 $this->savePersistentData();
358 }
359
363 function savePersistentData()
364 {
365 $this->HTTP->setSessionVariable( $this->StorageName . $this->MetaDataName, $this->MetaData );
366 $this->HTTP->setSessionVariable( $this->StorageName . $this->VariableListName, $this->VariableList );
367 }
368
369 /* Private messages */
370 public $ErrorList = array();
371 public $WarningList = array();
372
373 /* Step list, used to determine wizard steps */
374 public $StepList = array();
375
376 public $HTTP;
377 public $Tpl;
378 public $Module;
379 public $WizardURL = ''; /* url to wizard */
380
381 /* Array used to store wizzard values */
382 public $VariableList = array();
383 public $MetaData = array();
384 public $StorageName = 'eZWizard';
385 public $MetaDataName = '_meta';
386 public $VariableListName = '_data';
387
388 /* Step templates */
389 public $StepTemplateBase = 'design:wizard/step';
390
391 /* Array containing the wizard steps */
392 public $StepArray = array();
393 }
394
395 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZHTTPTool\instance
static instance()
Definition: ezhttptool.php:189
eZWizardBase
The class eZWizardBase does.
Definition: ezwizardbase.php:18
eZWizardBase\$MetaData
$MetaData
Definition: ezwizardbase.php:383
eZWizardBase\$MetaDataName
$MetaDataName
Definition: ezwizardbase.php:385
eZWizardBase\$VariableList
$VariableList
Definition: ezwizardbase.php:382
eZWizardBase\$HTTP
$HTTP
Definition: ezwizardbase.php:376
eZWizardBase\$Module
$Module
Definition: ezwizardbase.php:378
eZWizardBase\savePersistentData
savePersistentData()
Definition: ezwizardbase.php:363
eZWizardBase\$VariableListName
$VariableListName
Definition: ezwizardbase.php:386
eZWizardBase\preCheck
preCheck()
Definition: ezwizardbase.php:178
eZWizardBase\variableList
variableList()
Definition: ezwizardbase.php:301
eZWizardBase\__construct
__construct( $tpl, &$module, $storageName=false)
Definition: ezwizardbase.php:33
eZWizardBase\$StepList
$StepList
Definition: ezwizardbase.php:374
eZWizardBase\skip
skip()
Definition: ezwizardbase.php:211
eZWizardBase\process
process()
Definition: ezwizardbase.php:222
eZWizardBase\$WarningList
$WarningList
Definition: ezwizardbase.php:371
eZWizardBase\metaData
metaData( $key)
Definition: ezwizardbase.php:243
eZWizardBase\$StepArray
$StepArray
Definition: ezwizardbase.php:392
eZWizardBase\initialize
initialize()
Definition: ezwizardbase.php:52
eZWizardBase\run
run()
Definition: ezwizardbase.php:135
eZWizardBase\stepTemplate
stepTemplate()
Definition: ezwizardbase.php:312
eZWizardBase\STAGE_PRE
const STAGE_PRE
Definition: ezwizardbase.php:23
eZWizardBase\previousStep
previousStep()
Definition: ezwizardbase.php:331
eZWizardBase\attributes
attributes()
Definition: ezwizardbase.php:65
eZWizardBase\hasMetaData
hasMetaData( $key)
Definition: ezwizardbase.php:251
eZWizardBase\hasVariable
hasVariable( $key)
Definition: ezwizardbase.php:291
eZWizardBase\cleanup
cleanup()
Definition: ezwizardbase.php:320
eZWizardBase\setVariable
setVariable( $key, $value)
Definition: ezwizardbase.php:262
eZWizardBase\$StorageName
$StorageName
Definition: ezwizardbase.php:384
eZWizardBase\variable
& variable( $key)
Definition: ezwizardbase.php:275
eZWizardBase\hasAttribute
hasAttribute( $attr)
Definition: ezwizardbase.php:76
eZWizardBase\postCheck
postCheck()
Definition: ezwizardbase.php:192
eZWizardBase\$WizardURL
$WizardURL
Definition: ezwizardbase.php:379
eZWizardBase\setMetaData
setMetaData( $key, $value)
Definition: ezwizardbase.php:232
eZWizardBase\STAGE_POST
const STAGE_POST
Definition: ezwizardbase.php:24
eZWizardBase\nextStep
nextStep()
Definition: ezwizardbase.php:343
eZWizardBase\attribute
attribute( $attr)
Definition: ezwizardbase.php:81
eZWizardBase\$ErrorList
$ErrorList
Definition: ezwizardbase.php:370
eZWizardBase\$StepTemplateBase
$StepTemplateBase
Definition: ezwizardbase.php:389
eZWizardBase\$TPL
$TPL
Definition: ezwizardbase.php:22
eZWizardBase\$Tpl
$Tpl
Definition: ezwizardbase.php:377
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.