PHP Класс raoul2000\workflow\helpers\WorkflowHelper

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Описание методов

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

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
Результат array

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

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
Результат string

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

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

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
Результат array

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

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
Результат boolean

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

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
Результат string | null the HTML rendered status or null if not labelTemplate is found