A simple workflow behavior for Yii ActiveRecord
 All Data Structures Files Functions Variables Pages
SWValidator Class Reference
Inheritance diagram for SWValidator:

Data Fields

 $enableSwValidation =false
 
 $match =false
 
const SW_SCENARIO_STATUS_SEPARATOR ='-'
 
const SW_SCENARIO_PREFIX ='sw:'
 

Protected Member Functions

 validateAttribute ($model, $attribute)
 

Detailed Description

This validator should be used to validate the 'status' attribute for an active record object before it is saved. It tests if the transition that is about to occur is valid.
Moreover, if $enableSwValidation is set to true, this validator applies all validators that may have been defined by the model for the scenario associated to the transition being done.
Scenario names associated with a transition, have the following format :

 sw:[currentStatus]-[nextStatus]
 

For instance, if the model being validated is currently in status 'A' and it is sent in status 'B', the corresponding scenario name is 'sw:A-B'. Note that if the destination status doesn't belong to the same workflow as the current status, [nextStatus] must be in the form 'workflowId/statusId' (e.g 'sw:A-workflow/B'). Eventually, when the model enters in a workflow, the scenario name is '-[nextStatus]' where 'nextStatus' includes the workflow Id (e.g 'sw:-workflowIs/statusId').

If this validator is initialized with parameter match set to TRUE, then transitions scenario defined for validators are assumed to be regular expressions. If the current transition matches, then the associated validator is executed.
For instance, if validator 'required' for attribute A applies to scenarion 'sw:/S1_.?/' then each time the model leaves status S1, then the required validator will be applied.

Member Function Documentation

validateAttribute (   $model,
  $attribute 
)
protected

Validate status change and applies all validators defined by the model for the current transition scenario if enableSwValidation is TRUE. If validator parameter 'match' is true, the transition scenario is matched against validator scenario (which are assumed to be regular expressions).

See Also
validators/CValidator::validateAttribute()
Parameters
CModel$modelthe model to validate
string$attributethe model attribute to validate

Field Documentation

$enableSwValidation =false
$match =false
const SW_SCENARIO_PREFIX ='sw:'
const SW_SCENARIO_STATUS_SEPARATOR ='-'

The documentation for this class was generated from the following file: