PHP Class raoul2000\workflow\helpers\WorkflowHelper

Exibir arquivo Open project: raoul2000/yii2-workflow Class Usage Examples

Public Methods

Method Description
getAllStatusListData ( string $workflowId, IWorkflowSource $workflowSource ) : array Returns an associative array containing all statuses that belong to a workflow.
getNextStatus ( BaseActiveRecord | SimpleWorkflowBehavior $model ) : string Returns the status string of the next valid status from the list of transitions
getNextStatusListData ( BaseActiveRecord $model, boolean $validate = false, boolean $beforeEvents = false, boolean $includeCurrent = false ) : array Returns an associative array containing all statuses that can be reached by model.
getStatusDropDownData ( BaseActiveRecord | SimpleWorkflowBehavior $model ) : array Returns the items and options for a dropDownList All status options are in the list, but invalid transitions are disabled
isValidNextStatus ( BaseActiveRecord | SimpleWorkflowBehavior $model, string $status_id ) : boolean Checks if a given status is a valid transition from the current status
renderLabel ( BaseActiveRecord $model ) : string | null Displays the status for the model passed as argument.

Method Details

getAllStatusListData() public static method

The array returned is suitable to be used as list data value in (for instance) a dropdown list control. Usage example : assuming model Post has a SimpleWorkflowBehavior the following code displays a dropdown list containing all statuses defined in $post current the workflow :
echo Html::dropDownList(
		'status',
		null,
		WorkflowHelper::getAllStatusListData(
			$post->getWorkflow()->getId(),
			$post->getWorkflowSource()
		)
)
public static getAllStatusListData ( string $workflowId, IWorkflowSource $workflowSource ) : array
$workflowId string
$workflowSource IWorkflowSource
return array

getNextStatus() public static method

Returns the status string of the next valid status from the list of transitions
public static getNextStatus ( BaseActiveRecord | SimpleWorkflowBehavior $model ) : string
$model yii\db\BaseActiveRecord | raoul2000\workflow\base\SimpleWorkflowBehavior
return string

getNextStatusListData() public static method

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
return array

getStatusDropDownData() public static method

Example:
$statusDropDownData = WorkflowHelper::getStatusDropDownData($model);
Html
echo Html::dropDownList('status', $model->status, $statusDropdown['items'], ['options' => $statusDropdown['options']]);
ActiveForm
echo $form->field($model, 'status')->dropDownList($statusDropDownData['items'], ['options' => $statusDropDownData['options']]);
public static getStatusDropDownData ( BaseActiveRecord | SimpleWorkflowBehavior $model ) : array
$model yii\db\BaseActiveRecord | raoul2000\workflow\base\SimpleWorkflowBehavior
return array

isValidNextStatus() public static method

Checks if a given status is a valid transition from the current status
public static isValidNextStatus ( BaseActiveRecord | SimpleWorkflowBehavior $model, string $status_id ) : boolean
$model yii\db\BaseActiveRecord | raoul2000\workflow\base\SimpleWorkflowBehavior
$status_id string
return boolean

renderLabel() public static method

This method assumes that the status includes a metadata value called 'labelTemplate' that contains the HTML template of the rendering status. In this template the string '{label}' will be replaced by the status label. Example :
	'status' => [
		'draft' => [
			'label' => 'Draft',
			'transition' => ['ready' ],
			'metadata' => [
				'labelTemplate' => '{label}'
			]
		],
public static renderLabel ( BaseActiveRecord $model ) : string | null
$model yii\db\BaseActiveRecord
return string | null the HTML rendered status or null if not labelTemplate is found