getSteps() as $step) { if ($step['name'] === $name) { return Qs_Array::get($step, $field, $default); } } return $default; } public function getCurrentStep($field = null, $default = null) { return $this->getStep($this->step, $field, $default); } protected function getSteps() { if (null === $this->steps) { $this->steps = $this->getConfigArray('steps', []); $completed = true; $last = count($this->steps) - 1; foreach ($this->steps as $index => &$step) { $step['number'] = $index + 1; $step['enabled'] = true; $step['current'] = $step['name'] == $this->step; if ($step['current']) { $completed = false; } $step['completed'] = $completed; $step['url'] = self::getStepUrl($step['name']); } } return $this->steps; } protected function isPreviousStepCompleted() { if (false === ($previousStep = $this->getPreviousStepName())) { return true; } $data = $this->getStepData($previousStep); return !empty($data); } protected function redirectToStep($step) { $this->redirect(self::getStepUrl($step)); return $this; } private function getSession() { if (null === $this->session) { $this->session = new Qs_Session_Namespace(__CLASS__); } return $this->session; } protected function getStepData($step = null, $field = null, $default = null) { if (null === $step) { $step = $this->step; } $session = $this->getSession(); $data = []; if (isset($session->$step)) { $data = $session->$step; if (array_key_exists('__idItem', $data)) { unset($data['__idItem']); } } return Qs_Array::get($data, $field, $default); } protected function setStepData($step = null, $field, $value) { if (null === $step) { $step = $this->step; } $data = $this->getStepData($step); Qs_Array::set($data, $field, $value); $this->saveStepData($step, $data); return $this; } public function saveStepData($step, array $data) { $session = $this->getSession(); unset($data['__idItem']); $session->{$step} = $data; return $this; } protected function clearStepData($step) { $steps = (array) $step; $session = $this->getSession(); foreach ($steps as $step) { unset($session->{$step}); } return $this; } public function clearSession() { $session = $this->getSession(); $session->unsetAll(); return $this; } protected function getSessionData() { $session = $this->getSession(); return (array) $session->getIterator(); } protected function getPreviousStepName($step = null) { if ($step === null) { $step = $this->step; } $steps = array_column($this->getSteps(), 'name'); if (false !== ($index = array_search($step, $steps)) && array_key_exists($index - 1, $steps)) { return $steps[$index - 1]; } return false; } protected function getNextStepName() { $steps = array_column($this->getSteps(), 'name'); if (false !== ($index = array_search($this->step, $steps)) && array_key_exists($index + 1, $steps)) { return $steps[$index + 1]; } return false; } protected function renderProgressBar() { $item = [ 'currentStep' => $this->getCurrentStep(), 'steps' => $this->getSteps(), 'tpl' => $this->getTemplate('steps.tpl'), ]; return $this->_doc->fetchItem($item); } }