[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZWizardBase class 4 // 5 // Created on: <12-Nov-2004 16:24:31 kk> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezwizardbase.php 30 */ 31 32 /*! 33 \class eZWizardBase ezwizardbase.php 34 \brief The class eZWizardBase does 35 36 */ 37 38 define( 'EZ_WIZARD_STAGE_PRE', 0 ); 39 define( 'EZ_WIZARD_STAGE_POST', 1 ); 40 41 class eZWizardBase 42 { 43 /*! 44 Constructor 45 46 \param Template class 47 \param Module 48 \param Storage Name, optional. 49 */ 50 function eZWizardBase( &$tpl, &$module, $storageName = false ) 51 { 52 if ( $storageName ) 53 { 54 $this->StorageName = $storageName; 55 } 56 57 $this->TPL =& $tpl; 58 $this->Module =& $module; 59 $this->HTTP =& eZHTTPTool::instance(); 60 $this->VariableList = $this->HTTP->sessionVariable( $this->StorageName . $this->VariableListName ); 61 $this->MetaData = $this->HTTP->sessionVariable( $this->StorageName . $this->MetaDataName ); 62 63 $this->initialize(); 64 } 65 66 /*! 67 Set needed variables. 68 */ 69 function initialize() 70 { 71 if ( !$this->hasMetaData( 'current_step' ) ) 72 { 73 $this->setMetaData( 'current_step', 0 ); 74 } 75 76 if ( !$this->hasMetaData( 'current_stage' ) ) 77 { 78 $this->setMetaData( 'current_stage', EZ_WIZARD_STAGE_PRE ); 79 } 80 } 81 82 /*! 83 \reimp 84 */ 85 function attributes() 86 { 87 return array( 'error_count', 88 'error_list', 89 'warning_count', 90 'warning_list', 91 'step_template', 92 'variable_list', 93 'url' ); 94 } 95 96 /*! 97 \reimp 98 */ 99 function hasAttribute( $attr ) 100 { 101 return in_array( $attr, $this->attributes() ); 102 } 103 104 /*! 105 \reimp 106 */ 107 function &attribute( $attr ) 108 { 109 switch( $attr ) 110 { 111 case 'error_count': 112 { 113 $retValue = count( $this->ErrorList ); 114 } break; 115 116 case 'error_list': 117 { 118 $retValue = $this->ErrorList; 119 } break; 120 121 case 'warning_count': 122 { 123 $retValue = count( $this->WarningList ); 124 } break; 125 126 case 'warning_list': 127 { 128 $retValue = $this->WarningList; 129 } break; 130 131 case 'step_template': 132 { 133 $retValue = $this->stepTemplate(); 134 } break; 135 136 case 'variable_list': 137 { 138 $retValue = $this->variableList(); 139 } break; 140 141 case 'url': 142 { 143 $retValue = $this->WizardURL; 144 } break; 145 146 default: 147 { 148 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZWizardBase::attribute' ); 149 $retValue = null; 150 } 151 break; 152 } 153 return $retValue; 154 } 155 156 /*! 157 Will run the wizard, and continue from the current step. 158 This method will run postCheck, redirect to next, etc. depending on the current state. 159 160 return Module Result or module redirect. 161 */ 162 function run() 163 { 164 if ( $this->HTTP->hasPostVariable( 'PreviousButton' ) ) 165 { 166 return $this->previousStep(); 167 } 168 169 switch( $this->metaData( 'current_stage' ) ) 170 { 171 case EZ_WIZARD_STAGE_PRE: 172 { 173 $this->preCheck(); 174 $this->nextStep(); 175 if ( $this->skip() ) 176 { 177 return $this->nextStep(); 178 } 179 return $this->process(); 180 } break; 181 182 case EZ_WIZARD_STAGE_POST: 183 { 184 if ( $this->postCheck() ) 185 { 186 return $this->nextStep(); 187 } 188 else 189 { 190 return $this->process(); 191 } 192 } break; 193 } 194 } 195 196 /*! 197 \private 198 \virtual 199 Pre check current step to check that it's safe to execute current step. 200 Return false if current step should not be processed, and set warning message 201 202 \return true if everything ok 203 false if not 204 */ 205 function preCheck() 206 { 207 return true; 208 } 209 210 /*! 211 \private 212 \virtual 213 Post check current step to check that it's safe to continue to next step. 214 Return false if current step should be processed once again, and set warning message 215 216 \return true if everything ok 217 false if not 218 */ 219 function postCheck() 220 { 221 if ( $this->HTTP->hasPostVariable( 'NextButton' ) ) 222 { 223 return true; 224 } 225 226 return false; 227 } 228 229 /*! 230 \private 231 \virtual 232 Return true to skip current step. 233 Current step will not be processed. 234 235 \return true skip current step. 236 false - perform current step. 237 */ 238 function skip() 239 { 240 return false; 241 } 242 243 /*! 244 \virtual 245 Process the current step, and present the HTML. 246 247 \return Module Result 248 */ 249 function process() 250 { 251 } 252 253 /*! 254 Store meta data. 255 256 \param key 257 \param value 258 */ 259 function setMetaData( $key, $value ) 260 { 261 $this->MetaData[$key] = $value; 262 eZDebug::writeNotice( 'Set MetaData : [' . $key . '] = ' . $value, 263 'eZWizardBase::setMetaData()' ); 264 $this->savePersistentData(); 265 } 266 267 /*! 268 Get metadata 269 270 */ 271 function metaData( $key ) 272 { 273 return $this->MetaData[$key]; 274 } 275 276 /*! 277 Check if has metadata value 278 */ 279 function hasMetaData( $key ) 280 { 281 return isset( $this->MetaData[$key] ); 282 } 283 284 /*! 285 Store variable. Variable/value will be available in current and next wizard steps. 286 287 \param key 288 \param value 289 */ 290 function setVariable( $key, $value ) 291 { 292 $this->VariableList[$key] = $value; 293 $this->savePersistentData(); 294 } 295 296 /*! 297 Get stored wizard values. 298 299 \param key 300 301 \return value 302 */ 303 function &variable( $key ) 304 { 305 if ( isset( $this->VariableList[$key] ) ) 306 $retValue = $this->VariableList[$key]; 307 else 308 $retValue = false; 309 return $retValue; 310 } 311 312 /*! 313 Check if wizard variable exists 314 315 \param variable key 316 317 \return variable value 318 */ 319 function hasVariable( $key ) 320 { 321 return isset( $this->VariableList[$key] ); 322 } 323 324 /*! 325 Return variable list. 326 327 \return variable list 328 */ 329 function variableList() 330 { 331 return $this->VariableList; 332 } 333 334 /*! 335 \private 336 Get Step template name. 337 338 \return current step template 339 */ 340 function stepTemplate() 341 { 342 return $this->StepTemplateBase . '_' . ( $this->metaData( 'current_step' ) + 1 ) . '.tpl'; 343 } 344 345 /*! 346 Cleanup variables used during wizard 347 */ 348 function cleanup() 349 { 350 $this->HTTP->removeSessionVariable( $this->StorageName . $this->MetaDataName ); 351 $this->HTTP->removeSessionVariable( $this->StorageName . $this->VariableListName ); 352 $this->MetaData = array(); 353 $this->VariableList = array(); 354 } 355 356 /*! 357 Go back to previous step 358 */ 359 function previousStep() 360 { 361 $this->setMetaData( 'current_stage', EZ_WIZARD_STAGE_PRE ); 362 $this->setMetaData( 'current_step', $this->metaData( 'current_step' ) - 1 ); 363 $this->savePersistentData(); 364 365 return $this->Module->redirectTo( $this->WizardURL ); 366 } 367 368 /*! 369 Increate Step counter 370 */ 371 function nextStep() 372 { 373 if ( $this->metaData( 'current_stage' ) == EZ_WIZARD_STAGE_PRE ) 374 { 375 $this->setMetaData( 'current_stage', EZ_WIZARD_STAGE_POST ); 376 } 377 else 378 { 379 $this->setMetaData( 'current_stage', EZ_WIZARD_STAGE_PRE ); 380 $this->setMetaData( 'current_step', $this->metaData( 'current_step' ) + 1 ); 381 382 return $this->Module->redirectTo( $this->WizardURL ); 383 } 384 385 $this->savePersistentData(); 386 } 387 388 /*! 389 Save persistent data 390 */ 391 function savePersistentData() 392 { 393 $this->HTTP->setSessionVariable( $this->StorageName . $this->MetaDataName, $this->MetaData ); 394 $this->HTTP->setSessionVariable( $this->StorageName . $this->VariableListName, $this->VariableList ); 395 } 396 397 /* Private messages */ 398 var $ErrorList = array(); 399 var $WarningList = array(); 400 401 /* Step list, used to determine wizard steps */ 402 var $StepList = array(); 403 404 var $HTTP; 405 var $Tpl; 406 var $Module; 407 var $WizardURL = ''; /* url to wizard */ 408 409 /* Array used to store wizzard values */ 410 var $VariableList = array(); 411 var $MetaData = array(); 412 var $StorageName = 'eZWizard'; 413 var $MetaDataName = '_meta'; 414 var $VariableListName = '_data'; 415 416 /* Step templates */ 417 var $StepTemplateBase = 'design:wizard/step'; 418 419 /* Array containing the wizard steps */ 420 var $StepArray = array(); 421 } 422 423 class eZWizardBaseClassLoader 424 { 425 /*! 426 \static 427 Create new specified class 428 */ 429 function createClass( &$tpl, 430 &$module, 431 $stepArray, 432 $basePath, 433 $storageName = false, 434 $metaData = false ) 435 { 436 if ( !$storageName ) 437 { 438 $storageName = 'eZWizard'; 439 } 440 441 if ( !$metaData ) 442 { 443 $http =& eZHTTPTool::instance(); 444 $metaData = $http->sessionVariable( $storageName . '_meta' ); 445 } 446 447 if ( !isset( $metaData['current_step'] ) || 448 $metaData['current_step'] < 0 ) 449 { 450 $metaData['current_step'] = 0; 451 eZDebug::writeNotice( 'Setting wizard step to : ' . $metaData['current_step'], 452 'eZWizardBaseClassLoader::createClass()' ); 453 } 454 $currentStep = $metaData['current_step']; 455 456 if ( count( $stepArray ) <= $currentStep ) 457 { 458 eZDebug::writeError( 'Invalid wizard step count: ' . $currentStep, 459 'eZWizardBaseClassLoader::createClass()' ); 460 return false; 461 } 462 463 $filePath = $basePath . $stepArray[$currentStep]['file']; 464 if ( !file_exists( $filePath ) ) 465 { 466 eZDebug::writeError( 'Wizard file not found : ' . $filePath, 467 'eZWizardBaseClassLoader::createClass()' ); 468 return false; 469 } 470 471 include_once( $filePath ); 472 473 $className = $stepArray[$currentStep]['class']; 474 eZDebug::writeNotice( 'Creating class : ' . $className, 475 'eZWizardBaseClassLoader::createClass()' ); 476 $returnClass = new $className( $tpl, $module, $storageName ); 477 478 if ( isset( $stepArray[$currentStep]['operation'] ) ) 479 { 480 $operation = $stepArray[$currentStep]['operation']; 481 return $returnClass->$operation(); 482 eZDebug::writeNotice( 'Running : "' . $className . '->' . $operation . '()". Specified in StepArray', 483 'eZWizardBaseClassLoader::createClass()' ); 484 } 485 486 if ( isset( $metaData['current_stage'] ) ) 487 { 488 $returnClass->setMetaData( 'current_stage', $metaData['current_stage'] ); 489 eZDebug::writeNotice( 'Setting wizard stage to : ' . $metaData['current_stage'], 490 'eZWizardBaseClassLoader::createClass()' ); 491 } 492 493 return $returnClass; 494 } 495 } 496 497 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |