yii2-workflow Class Reference
  • Namespace
  • Class

Namespaces

  • raoul2000
    • workflow
      • actions
      • base
      • events
      • helpers
      • source
        • file
      • validation

Classes

  • WorkflowHelper

Class WorkflowHelper

Helper class for yii2-workflow.

Namespace: raoul2000\workflow\helpers
Located at helpers/WorkflowHelper.php

Methods summary

public static array
# getNextStatusListData( yii\db\BaseActiveRecord $model, boolean $validate = false, boolean $beforeEvents = false, boolean $includeCurrent = false )

Returns an associative array containing all statuses that can be reached by model.

Returns an associative array containing all statuses that can be reached by model.

Parameters

$model
$validate

when TRUE only those status with successfull attribute validation are included. When FALSE (default) Attribute validation is done performed.

$beforeEvents

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

when TRUE the current model status is added to the returned array. When FALSE (default) only next statuses are included

Returns

array

Throws

raoul2000\workflow\base\WorkflowException
public static array
# getAllStatusListData( string $workflowId, IWorkflowSource $workflowSource )

Returns an associative array containing all statuses that belong to a workflow. The array returned is suitable to be used as list data value in (for instance) a dropdown list control.

Returns an associative array containing all statuses that belong to a workflow. 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()
        )
)

Parameters

$workflowId
$workflowSource

Returns

array
public static string|null
# renderLabel( yii\db\BaseActiveRecord $model )

Displays the status for the model passed as argument.

Displays the status for the model passed as argument.

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' => '<span class="label label-default">{label}</span>'
            ]
        ],

Parameters

$model

Returns

string|null
the HTML rendered status or null if not labelTemplate is found
public static array
# getStatusDropDownData( yii\db\BaseActiveRecord|raoul2000\workflow\base\SimpleWorkflowBehavior $model, boolean $beforeEvents = false )

Returns the items and options for a dropDownList All status options are in the list, but invalid transitions are disabled

Returns the items and options for a dropDownList All status options are in the list, but invalid transitions are disabled

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']]);

Parameters

$model
$beforeEvents

Returns

array
public static string
# getNextStatus( yii\db\BaseActiveRecord|raoul2000\workflow\base\SimpleWorkflowBehavior $model )

Returns the status string of the next valid status from the list of transitions

Returns the status string of the next valid status from the list of transitions

Parameters

$model

Returns

string
public static boolean
# isValidNextStatus( yii\db\BaseActiveRecord|raoul2000\workflow\base\SimpleWorkflowBehavior $model, string $status_id )

Checks if a given status is a valid transition from the current status

Checks if a given status is a valid transition from the current status

Parameters

$model
$status_id

Returns

boolean
yii2-workflow Class Reference API documentation generated by ApiGen