raoul2000\workflow\helpers\WorkflowHelper::getNextStatusListData PHP Метод

getNextStatusListData() публичный статический Метод

Returns an associative array containing all statuses that can be reached by model.
public static getNextStatusListData ( BaseActiveRecord $model, boolean $validate = false, boolean $beforeEvents = false, boolean $includeCurrent = false ) : array
$model yii\db\BaseActiveRecord
$validate boolean when TRUE only those status with successfull attribute validation are included. When FALSE (default) Attribute validation is done performed.
$beforeEvents boolean when TRUE all configured *before* events are fired : only the status that don't invalidate the workflow event are included in the returned array, otherwise no event is fired and all next status are included
$includeCurrent boolean when TRUE the current model status is added to the returned array. When FALSE (default) only next statuses are included
Результат array
    public static function getNextStatusListData($model, $validate = false, $beforeEvents = false, $includeCurrent = false)
    {
        if (!SimpleWorkflowBehavior::isAttachedTo($model)) {
            throw new WorkflowException('The model does not have a SimpleWorkflowBehavior behavior');
        }
        $listData = [];
        if ($includeCurrent) {
            $currentStatus = $model->getWorkflowStatus();
            $listData[$currentStatus->getId()] = $currentStatus->getLabel();
        }
        $report = $model->getNextStatuses($validate, $beforeEvents);
        foreach ($report as $endStatusId => $info) {
            if (!isset($info['isValid']) || $info['isValid'] === true) {
                $listData[$endStatusId] = $info['status']->getLabel();
            }
        }
        return $listData;
    }

Usage Example

 public function testGetNextStatusListData()
 {
     $model = new Item04();
     $model->enterWorkflow();
     $ar = WorkflowHelper::getNextStatusListData($model);
     $expected = ['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published'];
     $this->assertEquals(2, count($ar));
     $this->assertEquals(2, count(array_intersect_assoc($expected, $ar)));
     $model->sendTostatus('B');
     $ar = WorkflowHelper::getNextStatusListData($model, false, false, true);
     $this->assertEquals(3, count($ar));
     $this->assertEquals(3, count(array_intersect_assoc(['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published', 'Item04Workflow/C' => 'node C'], $ar)));
 }
All Usage Examples Of raoul2000\workflow\helpers\WorkflowHelper::getNextStatusListData