Returns an associative array containing all statuses that can be reached by model.
public static getNextStatusListData ( |
||
$model | ||
$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 |
return | array |
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))); }
/** * Returns the status string of the next valid status from the list of transitions * * @param BaseActiveRecord|SimpleWorkflowBehavior $model * @return string */ public static function getNextStatus($model) { $currentStatus = $model->getAttribute('status'); $statusList = $model->getWorkflowSource()->getAllStatuses($model->getWorkflow()->getId()); $transitions = array_keys(WorkflowHelper::getNextStatusListData($this->owner)); $started = false; foreach ($statusList as $status) { $status_id = $status->getId(); if ($started) { if (in_array($status_id, $transitions) && static::isValidNextStatus($model, $status_id)) { return $status_id; } } if ($status_id == $currentStatus) { $started = true; } } return $currentStatus; }