Class SWActiveRecordBehavior
- statusAttribute (string) : This is the column name where status is
stored
If this attribute doesn't exist for a model, the Workflow behavior is automatically disabled and a warning is logged.
In the database, this attribute must be defined as a VARCHAR() whose length should be large enough to contains a complete status name with format workflowId/nodeId.
example :task/pending postWorkflow/to_review
Default : 'status' - defaultWorkflow (string) : workflow name that should be used by
default for the owner model
If this parameter is not set, then it is automatically created based on the name of the owner model, prefixed with 'workflowNamePrefix' defined by the workflow source component. By default this value is set to 'sw' and so, for example 'Model1' is associated by default with workflow 'swModel1'.
Default : SWWorkflowSource->workflowNamePrefix . ModelName - autoInsert (boolean) :
If TRUE, the model is automatically inserted in the workflow (if not already done) when it is saved. If FALSE, it is developer responsability to insert the model in the workflow.
Default : true - workflowSourceComponent (string) :
Name of the workflow source component to use with this behavior.
By ddefault this parameter is set to <em>swSource</em> (seeSWPhpWorkflowSource
) - enableEvent (boolean) :
If TRUE, this behavior will fire SWEvents. Note that even if it is true, this doesn't garantee that SW events will be fired as another condition is that the owner component provides SWEvent handlers.
Default : true - transitionBeforeSave (boolean) :
If TRUE, SWEvents are fired and possible transitions tasks are executed before the owner model is actually saved. If FALSE, events and task transitions are processed after save.
It has no effect if the transition is done programatically by a call to swNextStatus(), but only if it is done when the owner model is saved.
Default : true
- CBehavior
-
SWActiveRecordBehavior
Methods summary
public
reference
|
|
protected
boolean
|
#
canFireEvent( CComponent $owner, string $className )
Checks that the owner component is able to handle workflow events that could be fired by this behavior |
public
|
#
swGetStatus( )
If the owner component is inserted into a workflow, this method returns the SWNode object that represent this status, otherwise NULL is returned. |
public
boolean
|
#
swIsEventEnabled( )
Event may be enabled by configuration (when the behavior is attached to the
owner component) but it can be automatically disabled if the owner component
does not define handlers for all SWEvents (i.e events fired when the owner
component evolves in the workflow). |
public
|
#
swIsStatus( mixed $status )
Test if the owner component is currently in the status passed as argument. |
public
boolean
|
#
swStatusEquals( mixed $status = null )
Test if the current status is the same as the one passed as argument. A call to swStatusEquals(<em>null</em>) returns TRUE only if the owner component is not in a workflow. |
public
boolean
|
#
swHasStatus( )
Test if the owner component is currently inserted in a workflow. This method is equivalent to swGetStatus()!=null. |
public
|
#
swGetWorkflowId( )
Returns the current workflow Id the owner component is inserted in, or NULL if the owner component is not inserted into a workflow. |
public
|
#
attach( mixed $owner )
Overloads parent attach method so at the time the behavior is about to be
attached to the owner component, the behavior is initialized.
During the initialisation, following actions are performed:
|
public
string
|
#
swGetDefaultWorkflowId( )
Finds out what should be the default workflow to use with the owner model. To
find out what is the default workflow, this method perform following tests :
|
public
boolean
|
#
swInsertToWorkflow( string $workflowId = null )
Insert the owner component into the workflow whose id is passed as argument. If NULL is passed as argument, the default workflow is used. If no error occurs, when this method ends, the owner component's status is the initial node of the selected workflow. |
public
|
#
swRemoveFromWorkflow( )
Removes the owner component from its current workflow. An exception is thrown if the owner model is not in a final status (i.e a status with no outgoing transition). |
public
array
|
#
swGetNextStatus( )
This method returns a list of nodes that can be actually reached at the time the method is called. To be reachable, a transition must exist between the current status and the next status, AND if a constraint is defined, it must be evaluated to true. |
public
array
|
#
swGetAllStatus( )
Returns all statuses belonging to the workflow the owner component is inserted in or is related to. If the owner component is not inserted in a workflow or related to no workflow, an empty array is returned. |
public
boolean
|
#
swIsNextStatus( mixed $nextStatus )
Checks if the status passed as argument can be reached from the current status.
This occurs when
|
public
|
#
swCreateNode( string $str )
Creates a new node from the string passed as argument. If $str doesn't contain a workflow Id, this method uses the workflowId associated with the owner model. The node created here doesn't have to exist within a workflow. This method is mainly used by the SWValidator |
public
boolean
|
#
swIsFinalStatus( status $status = null )
Checks if the status passed as argument, or the current status (if NULL is passed) is a final status of the corresponding workflow. By definition a final status as no outgoing transition to other status. |
public
boolean
|
#
swIsInitialStatus( mixed $status = null )
Checks if the status passed as argument, or the current status (if NULL is passed) is the initial status of the corresponding workflow. An exception is raised if the owner model is not in a workflow and if $status is null. |
public
boolean
|
#
swValidate( string $attribute, mixed $value )
Validates the status attribute stored in the owner model. This attribute is
valid if :
|
public
boolean
|
#
swSetStatus( mixed $nextStatus, mixed $params = null )
Set the owner component into the status passed as argument. If a transition could be performed, the owner status attribute is updated with the new status value in the form <em>workflowId/nodeId</em>. This method is responsible for firing SWEvents and executing workflow tasks if defined for the given transition. |
public
|
#
events( )
Attach event handlers. The behavior registers its own mandatory event handlers
in case the owner model is a CActiveRecord instance.
|
public
boolean
|
#
beforeSave( Event $event )
Depending on the value of the owner status attribute, and the current status, this method performs an actual transition. |
public
|
|
public
|
|
public
|
#
enterWorkflow(
Default implementation for the onEnterWorkflow event. |
public
|
#
onEnterWorkflow(
This event is raised after the record instance is inserted into a workflow. This may occur at construction time (new) if the behavior is initialized with autoInsert set to TRUE and in this case, the 'onEnterWorkflow' event is always fired. Consequently, when a model instance is created from database (find), the onEnterWorkflow is fired even if the record has already be inserted in a workflow (e.g contains a valid status). |
public
|
#
leaveWorkflow(
Default implementation for the onEnterWorkflow event. |
public
|
#
onLeaveWorkflow(
This event is raised after the record instance is removed from a workflow. This occures when the owner status attribut is set to NULL, for instance by calling $c->swNextStatus() |
public
|
#
beforeTransition(
Default implementation for the onBeforeTransition event. |
public
|
#
onBeforeTransition(
This event is raised before a workflow transition is applied to the owner instance. |
public
|
#
processTransition(
Default implementation for the onProcessTransition event. |
public
|
#
onProcessTransition(
This event is raised when a workflow transition is in progress. In such case,
the user may define a handler for this event in order to run specific
process. |
public
|
#
afterTransition(
Default implementation for the onAfterTransition event. |
public
|
#
onAfterTransition(
This event is raised after the onProcessTransition is fired. It is the last
event fired during a non-final transition. |
public
|
#
finalStatus(
Default implementation for the onFinalStatus event. |
public
|
#
onFinalStatus(
This event is raised at the end of a transition, when the destination status is a final status (i.e the owner model has reached a status from where it will not be able to move). |
Magic methods summary
Constants summary
string |
SW_LOG_CATEGORY
|
'application.simpleWorkflow' |
|
string |
SW_I8N_CATEGORY
|
'simpleworkflow' |
Properties summary
public
string
|
$statusAttribute |
#
This is the column name where status is stored. |
public
string
|
$defaultWorkflow |
#
workflow name that should be used by default for the owner model. |
public
boolean
|
$autoInsert | |
public
string
|
$workflowSourceComponent |
#
name of the workflow source component |
public
boolean
|
$enableEvent | |
public
boolean
|
$transitionBeforeSave | |
protected
string
|
$eventClassName |
#
name of the class the owner should inherit from in order for SW events to be enabled. |