raoul2000\workflow\base\SimpleWorkflowBehavior::getNextStatuses PHP Метод

getNextStatuses() публичный Метод

The list of reachable statuses is returned as an array where keys are status ids and value is an associative array that contains at least the status instance. By default, no validation is performed and no event is fired by this method, however you may use $validate and $beforeEvents argument to enable them. When $validate is true, the model is validated for each scenario and for each possible transition. When $beforeEvents is true, all "before" events are fired and if a handler is attached it is executed. Each entry of the returned array has the following structure :
[
    targetStatusId => [
        'status' => the status instance
the 'validation' key is present only if $validate is true
    	'validation' => [
            0 => [
                 'scenario' => scenario name
                'success' => true (validation success) | false (validation failure) | null (no validation for this scenario)
            ],
		    1 => [ ... ]
	     ],
the 'event' key is present only if $beforeEvent is TRUE
	     'event' => [
		    0 => [
			    'name' => event name
			    'success' => true (event handler success) | false (event handler failed : the event has been invalidated) | null (no event handler)
		    ]
		    1 => [...]
	    ],
if $validate is true or if $beforeEvent is TRUE
	   'isValid' => true   (being given the verifications that were done, the target status can be reached)
		  | false (being given the verifications that were done, the target status cannot be reached)
    ],
     anotherStatusID => [ ...]
]
If the owner model is not currently in a workflow, this method returns the initial status of its default workflow for the model.
public getNextStatuses ( $validate = false, $beforeEvents = false ) : array
Результат array list of status
    public function getNextStatuses($validate = false, $beforeEvents = false)
    {
        $nextStatus = [];
        if (!$this->hasWorkflowStatus()) {
            $workflow = $this->_wfSource->getWorkflow($this->getDefaultWorkflowId());
            if ($workflow === null) {
                throw new WorkflowException("Failed to load default workflow ID = " . $this->getDefaultWorkflowId());
            }
            $initialStatus = $this->_wfSource->getStatus($workflow->getInitialStatusId(), $this->selectDefaultWorkflowId());
            $nextStatus[$initialStatus->getId()] = ['status' => $initialStatus];
        } else {
            $transitions = $this->_wfSource->getTransitions($this->getWorkflowStatus()->getId(), $this->selectDefaultWorkflowId());
            foreach ($transitions as $transition) {
                $nextStatus[$transition->getEndStatus()->getId()] = ['status' => $transition->getEndStatus()];
            }
        }
        if (count($nextStatus)) {
            if ($beforeEvents) {
                // fire before events
                foreach (array_keys($nextStatus) as $endStatusId) {
                    $transitionIsValid = true;
                    $eventSequence = $this->getEventSequence($endStatusId);
                    foreach ($eventSequence['before'] as $beforeEvent) {
                        $eventResult = [];
                        $beforeEventName = $beforeEvent->name;
                        $eventResult['name'] = $beforeEventName;
                        if ($this->owner->hasEventHandlers($beforeEventName)) {
                            $this->owner->trigger($beforeEventName, $beforeEvent);
                            $eventResult['success'] = $beforeEvent->isValid;
                            $eventResult['messages'] = $beforeEvent->getErrors();
                            if ($beforeEvent->isValid === false) {
                                $transitionIsValid = false;
                            }
                        } else {
                            $eventResult['success'] = null;
                        }
                        $nextStatus[$endStatusId]['event'][] = $eventResult;
                    }
                    $nextStatus[$endStatusId]['isValid'] = $transitionIsValid;
                }
            }
            if ($validate) {
                // save scenario name and errors
                $saveScenario = $this->owner->getScenario();
                $saveErrors = $this->owner->getErrors();
                // validate
                $modelScenarios = array_keys($this->owner->scenarios());
                foreach (array_keys($nextStatus) as $endStatusId) {
                    $transitionIsValid = true;
                    $scenarioSequence = $this->getScenarioSequence($endStatusId);
                    foreach ($scenarioSequence as $scenario) {
                        $validationResult = [];
                        // perform validation only if $scenario is registered for the owner model
                        if (in_array($scenario, $modelScenarios)) {
                            $this->owner->clearErrors();
                            $this->owner->setScenario($scenario);
                            $validationResult['scenario'] = $scenario;
                            if ($this->owner->validate() == true) {
                                $validationResult['success'] = true;
                            } else {
                                $validationResult['success'] = false;
                                $validationResult['errors'] = $this->owner->getErrors();
                                $transitionIsValid = false;
                            }
                        } else {
                            $validationResult['scenario'] = $scenario;
                            $validationResult['success'] = null;
                        }
                        $nextStatus[$endStatusId]['validation'][] = $validationResult;
                    }
                    if (isset($nextStatus[$endStatusId]['isValid'])) {
                        $nextStatus[$endStatusId]['isValid'] = $nextStatus[$endStatusId]['isValid'] && $transitionIsValid;
                    } else {
                        $nextStatus[$endStatusId]['isValid'] = $transitionIsValid;
                    }
                }
                // restore scenario name and errors
                $this->owner->setScenario($saveScenario);
                $this->owner->clearErrors();
                $this->owner->addErrors($saveErrors);
            }
        }
        return $nextStatus;
    }