Class SWValidator
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 <strong>$enableSwValidation</strong> 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
<em>required</em> validator will be applied.
- CValidator
- SWValidator
Methods summary
protected
|
#
validateAttribute( CModel $model, string $attribute )
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). |
Magic methods summary
Constants summary
string |
SW_SCENARIO_STATUS_SEPARATOR
|
'-' |
|
string |
SW_SCENARIO_PREFIX
|
'sw:' |
Properties summary
public
boolean
|
$enableSwValidation |
#
(default FALSE) Enables simpleWorkflow Validation. When TRUE, the SWValidator not only validates status change for the model, but also applies all validators that may have been created and which are associated with the scenario for the transition being done. Such scenario names are based on both the current and the next status name. |
public
boolean
|
$match |
#
(default FALSE) When true, the scenario name is evaluated as a regular expression that must match the transition name being done. |