Created
June 27, 2015 15:45
-
-
Save raoul2000/8b0c7ef567a50f14ea64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WizflowController extends \yii\web\Controller | |
{ | |
public function beforeAction($action) | |
{ | |
if (parent::beforeAction($action)) { | |
Yii::setAlias('@workflowDefinitionNamespace','app\\models\\wizflow'); | |
Yii::$app->set('workflowSource',[ | |
'class' => '\raoul2000\workflow\source\file\WorkflowFileSource' | |
]); | |
} | |
return true; | |
} | |
/** | |
* | |
* @param string $nav | |
* @throws Exception | |
* @return Ambigous <string, string> | |
*/ | |
public function actionIndex($nav = 'next') | |
{ | |
$wizard = new WizflowManager([ | |
'workflowSource' => Yii::$app->get('workflowSource') | |
]); | |
if( $nav == 'prev') { | |
$model = $wizard->getPreviousStep(); | |
if( $model == null) { | |
$this->redirect(['index','nav'=>'start']); | |
} | |
}elseif($nav == 'start') { | |
$model = $wizard->start(); | |
}else { | |
$model = $wizard->getCurrentStep(); | |
if( $model->load(Yii::$app->request->post()) && $model->validate()) { | |
$wizard->updateCurrentStep($model); | |
// current step has been completed : save it and get next step | |
$model = $wizard->getNextStep(); | |
if( $model == null) { | |
//we reached the last step | |
$wizard->save(); | |
$this->redirect(['finish']); | |
} | |
} | |
} | |
$viewname = $model->getWorkflowStatus()->getMetadata('view'); | |
$wizard->save(); | |
return $this->render($viewname,[ | |
'model' => $model, | |
'path' => $wizard->getPath() | |
]); | |
} | |
/** | |
* | |
* @return Ambigous <string, string> | |
*/ | |
public function actionFinish() | |
{ | |
$wizard = new WizflowManager([ | |
'workflowSource' => Yii::$app->get('workflowSource') | |
]); | |
return $this->render('finish',[ | |
'path' => $wizard->getPath() | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment