/** * Get step model * * @param string $step * @return \Core\View\Model\WizardStep */ protected function getStep($step) { $store = $this->getStore(); $formSrv = $this->getServiceLocator()->get('Form'); if ($step == $this->startStep) { $form = $formSrv->get('Grid\\Paragraph\\CreateWizard\\Start'); $model = new StartStep(array('textDomain' => 'paragraph')); } else { $store['type'] = $step; $form = new Form(); $create = $formSrv->get('Grid\\Paragraph\\Meta\\Create'); $model = new WizardStep(array('textDomain' => 'paragraph'), array('finish' => true, 'next' => 'finish')); if ($create->has($step)) { foreach ($create->get($step) as $element) { $form->add($element); } } else { $edit = $formSrv->get('Grid\\Paragraph\\Meta\\Edit'); if ($edit->has($step)) { foreach ($edit->get($step) as $element) { $form->add($element); } } else { $model->setOption('skip', true); } } } return $model->setStepForm($form); }
/** * Get step model * * @param string $step * @return \Core\View\Model\WizardStep */ protected function getStep($step) { $model = new WizardStep(array('textDomain' => 'central')); switch ($step) { case $this->startStep: $auth = $this->getAuthenticationService(); $model->setOptions(array('finish' => false, 'next' => $auth->hasIdentity() ? 'layout' : 'user')); break; case 'user': $model->setOptions(array('finish' => false, 'next' => 'layout')); break; case 'layout': $settings = $this->getStepStore('settings'); if (empty($settings)) { $start = $this->getStepStore($this->startStep); $this->setStepStore('settings', array('headTitle' => $start['subdomain'], 'keywords' => $start['subdomain'], 'description' => $start['subdomain'])); } $model->setOptions(array('finish' => false, 'next' => 'content')); break; case 'content': $model->setOptions(array('finish' => true, 'next' => 'settings')); break; case 'settings': $auth = $this->getAuthenticationService(); $model->setOptions(array('finish' => true, 'next' => $auth->hasIdentity() ? 'check' : 'finish')); break; case 'check': $expired = false; $hash = $this->params()->fromQuery('hash'); if (!empty($hash)) { $data = $this->getServiceLocator()->get('Grid\\MultisiteCentral\\Model\\SiteWizardData'); if ($data->has($hash)) { $this->unsetStepStack(); foreach ($data->get($hash) as $stepName => $values) { $this->pushStepStack($stepName); $this->setStepStore($stepName, $values); } // $data->delete( $hash ); } else { $expired = true; } } if ($expired) { $model->setDescriptionPartial('grid/multisite-central/site-wizard/expired')->setOptions(array('finish' => false, 'next' => $this->startStep)); } else { $postfix = $this->getServiceLocator()->get('Config')['modules']['Grid\\MultisiteCentral']['domainPostfix']; $model->setVariable('stores', $this->getStepStores(false))->setVariable('domainPostfix', $postfix)->setDescriptionPartial('grid/multisite-central/site-wizard/check')->setOptions(array('finish' => true, 'next' => 'finish')); } break; default: throw new RuntimeException('Step: ' . $step . ' is not supported'); } if ($step == 'check') { $model->setStepForm(new Form()); } else { $model->setDescriptionPartial('grid/multisite-central/site-wizard/description')->setStepForm($this->getServiceLocator()->get('Form')->get('Grid\\MultisiteCentral\\SiteWizard\\' . ucfirst($step))); } return $model; }
/** * Get next step * * @return string|null */ public function getNextStep() { $next = parent::getNextStep(); if (empty($next)) { $form = $this->getStepForm(); if (!empty($form)) { $type = $form->get('type'); if (!empty($type)) { $next = $type->getValue(); } } } return $next; }
/** * Test methods */ public function testMethods() { $form = new Form(); $step = new WizardStep(); $step->setStepForm($form); $this->assertSame($form, $step->getStepForm()); $step->setTextDomain('exampleTextDomain'); $this->assertSame('exampleTextDomain', $step->getTextDomain()); $step->setDescriptionPartial('exampleDescriptionPartial'); $this->assertSame('exampleDescriptionPartial', $step->getDescriptionPartial()); $this->assertFalse($step->canFinishWizard()); $this->assertTrue($step->canCancelWizard()); $this->assertFalse($step->canSkip()); $step->setOption('finish', true); $step->setOption('cancel', false); $step->setOption('skip', true); $this->assertTrue($step->canFinishWizard()); $this->assertFalse($step->canCancelWizard()); $this->assertTrue($step->canSkip()); $this->assertFalse($step->hasPreviousStep()); $step->setPreviousStep('examplePreviousStep'); $this->assertSame('examplePreviousStep', $step->getPreviousStep()); $this->assertTrue($step->hasPreviousStep()); $this->assertFalse($step->hasNextStep()); $step->setNextStep('exampleNextStep'); $this->assertSame('exampleNextStep', $step->getNextStep()); $this->assertTrue($step->hasNextStep()); }
/** * Run a single step (which is not finish or cancel) * * @param string $step * @param WizardStep $model * @return string|null the step to redirect to */ protected function runStep($step, WizardStep $model = null) { $request = $this->getRequest(); $isValid = false; $isPost = $request->isPost(); $isCancel = $isPost && $request->getPost('cancel'); $isPrevious = $isPost && $request->getPost('previous'); $isNext = $isPost && $request->getPost('next'); $isFinish = $isPost && $request->getPost('finish'); $jumpTo = $request->getQuery('jump'); $values = $this->getStepStore($step); $form = $model ? $model->getStepForm() : null; $redirect = null; if (!empty($model) && $model->canSkip()) { $this->setStepStore($step, array()); $this->pushStepStack($step); $redirect = $model->getNextStep(); } else { if (empty($model) || empty($form)) { $redirect = $this->startStep; } else { if (!empty($values)) { $form->setData($values); } if ($isPost && ($isNext || $isFinish)) { $form->setData($request->getPost()); $isValid = $form->isValid(); } if ($isNext && $isValid && ($redirect = $model->getNextStep())) { $this->setStepStore($step, $form->getData()); $this->pushStepStack($step); } else { if ($isPrevious && ($redirect = $model->getPreviousStep())) { $top = $this->topStepStack(); if ($redirect == $top) { $this->popStepStack(); } } else { if ($jumpTo) { $store = $this->getStore(); while (!empty($store['stack']) && $jumpTo != $this->popStepStack()) { } $redirect = empty($store['stack']) ? $this->startStep : $jumpTo; } else { if ($isFinish && $isValid && $model->canFinishWizard()) { $this->setStepStore($step, $form->getData()); $this->pushStepStack($step); $redirect = self::STEP_FINISH; } else { if ($isCancel && $model->canCancelWizard()) { $redirect = self::STEP_CANCEL; } } } } } } } /* if ( $redirect && $redirect != $step ) { if ( ! $this->stepping( $step, $redirect ) ) { $redirect = null; } } */ return $redirect; }