/** * Main Component method. * * @param string $step Name of step associated in $this->steps to be processed. * * @throws NotImplementedException * @return bool|\CakeResponse * @access public */ public function process($step) { if (isset($this->controller->request->data['Cancel'])) { if (method_exists($this->controller, 'beforeCancel')) { $this->controller->beforeCancel($this->_getExpectedStep()); } $this->reset(); return $this->controller->redirect($this->cancelUrl); } if (isset($this->controller->request->data['Draft'])) { if (method_exists($this->controller, 'saveDraft')) { $draft = array('_draft' => array('current' => array('step' => $step, 'data' => $this->controller->request->data))); $this->controller->saveDraft(array_merge_recursive((array) $this->read(), $draft)); } $this->reset(); return $this->controller->redirect($this->draftUrl); } if (empty($step)) { if ($this->controller->Session->check('Wizard.complete')) { if (method_exists($this->controller, 'afterComplete')) { $this->controller->afterComplete(); } $this->reset(); return $this->controller->redirect($this->completeUrl); } $this->autoReset = false; } elseif ($step == 'reset') { if (!$this->lockdown) { $this->reset(); } } else { if ($this->_validStep($step)) { $this->_setCurrentStep($step); if (!empty($this->controller->request->data) && !isset($this->controller->request->data['Previous'])) { $processCallback = Inflector::variable('process_' . $this->_currentStep); if (method_exists($this->controller, $processCallback)) { $proceed = $this->controller->{$processCallback}(); } elseif ($this->autoValidate) { $proceed = $this->_validateData(); } else { throw new NotImplementedException(sprintf(__('Process Callback not found. Please create Controller::%s', $processCallback))); } if ($proceed) { $this->save(); if (isset($this->controller->request->data['SaveAndBack']) && prev($this->steps)) { return $this->redirect(current($this->steps)); } if (next($this->steps)) { if ($this->autoAdvance) { return $this->redirect(); } return $this->redirect(current($this->steps)); } else { $this->controller->Session->write('Wizard.complete', $this->read()); $this->reset(); return $this->controller->redirect(array('action' => $this->action)); } } } elseif (isset($this->controller->request->data['Previous']) && prev($this->steps)) { return $this->redirect(current($this->steps)); } elseif ($this->controller->Session->check("{$this->_sessionKey}._draft.current")) { $this->controller->request->data = $this->read('_draft.current.data'); $this->controller->Session->delete("{$this->_sessionKey}._draft.current"); } elseif ($this->controller->Session->check("{$this->_sessionKey}.{$this->_currentStep}")) { $this->controller->request->data = $this->read($this->_currentStep); } $prepareCallback = Inflector::variable('prepare_' . $this->_currentStep); if (method_exists($this->controller, $prepareCallback)) { $this->controller->{$prepareCallback}(); } $this->config('activeStep', $this->_currentStep); if ($this->nestedViews) { $this->controller->viewPath .= '/' . $this->action; } if ($this->controller->autoRender) { return $this->controller->render($this->_currentStep); } return true; } else { return $this->redirect(); } } if ($step != 'reset' && $this->autoReset) { $this->reset(); } return $this->redirect(); }