A simple workflow behavior for Yii ActiveRecord
|
Public Member Functions | |
swGetWorkflowSource () | |
swGetStatus () | |
swIsEventEnabled () | |
swIsStatus ($status) | |
swStatusEquals ($status=null) | |
swHasStatus () | |
swGetWorkflowId () | |
attach ($owner) | |
swGetDefaultWorkflowId () | |
swInsertToWorkflow ($workflowId=null) | |
swRemoveFromWorkflow () | |
swGetNextStatus () | |
swGetAllStatus () | |
swIsNextStatus ($nextStatus) | |
swCreateNode ($str) | |
swIsFinalStatus ($status=null) | |
swIsInitialStatus ($status=null) | |
swValidate ($attribute, $value) | |
swNextStatus ($nextStatus, $params=null) | |
swSetStatus ($nextStatus, $params=null) | |
events () | |
beforeSave ($event) | |
afterSave ($event) | |
afterFind ($event) | |
enterWorkflow ($event) | |
onEnterWorkflow ($event) | |
leaveWorkflow ($event) | |
onLeaveWorkflow ($event) | |
beforeTransition ($event) | |
onBeforeTransition ($event) | |
processTransition ($event) | |
onProcessTransition ($event) | |
afterTransition ($event) | |
onAfterTransition ($event) | |
finalStatus ($event) | |
onFinalStatus ($event) | |
Data Fields | |
$statusAttribute = 'status' | |
$defaultWorkflow =null | |
$autoInsert =true | |
$workflowSourceComponent ='swSource' | |
$enableEvent =true | |
$transitionBeforeSave =true | |
const | SW_LOG_CATEGORY ='application.simpleWorkflow' |
const | SW_I8N_CATEGORY ='simpleworkflow' |
Protected Member Functions | |
canFireEvent ($owner, $className) | |
Protected Attributes | |
$eventClassName ='SWActiveRecord' | |
This class implements all the logic for the simpleWorkflow extension. Following attributes can be initialized when this behavior is attached to the owner component :
task/pending postWorkflow/to_reviewDefault : 'status'
afterFind | ( | $event) |
Responds to CActiveRecord::onAfterFind event. This method is called when a CActiveRecord instance is created from DB access (model read from DB). At this time, the worklow behavior must be initialized.
CEvent | event parameter |
afterSave | ( | $event) |
When option transitionBeforeSave is false, if a task is associated with the transition that was performed, it is executed now, that it after the activeRecord owner component has been saved. The onAfterTransition is also raised.
SWEvent | $event |
afterTransition | ( | $event) |
Default implementation for the onAfterTransition event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
attach | ( | $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:
beforeSave | ( | $event) |
Depending on the value of the owner status attribute, and the current status, this method performs an actual transition.
Event | $event |
beforeTransition | ( | $event) |
Default implementation for the onBeforeTransition event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
|
protected |
Checks that the owner component is able to handle workflow events that could be fired by this behavior
CComponent | $owner | the owner component attaching this behavior |
string | $className |
enterWorkflow | ( | $event) |
Default implementation for the onEnterWorkflow event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
string name of the class the owner should inherit from in order for SW events | ( | ) |
Attach event handlers. The behavior registers its own mandatory event handlers in case the owner model is a CActiveRecord instance.
Additionnally, the behavior will fire custom events on various steps of the owner model life-cycle within its workflow :
to be enabled.
finalStatus | ( | $event) |
Default implementation for the onFinalStatus event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
leaveWorkflow | ( | $event) |
Default implementation for the onEnterWorkflow event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
onAfterTransition | ( | $event) |
This event is raised after the onProcessTransition is fired. It is the last event fired during a non-final transition.
Again, in the case of an AR being saved, this event may be fired before or after the record is actually save, depending on the 'transitionBeforeSave' initialization parameters.
SWEvent | the event parameter |
onBeforeTransition | ( | $event) |
This event is raised before a workflow transition is applied to the owner instance.
SWEvent | the event parameter |
onEnterWorkflow | ( | $event) |
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).
SWEvent | the event parameter |
onFinalStatus | ( | $event) |
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).
SWEvent | the event parameter |
onLeaveWorkflow | ( | $event) |
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()
SWEvent | the event parameter |
onProcessTransition | ( | $event) |
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.
Depending on the 'transitionBeforeSave' initialization parameters, this event could be fired before or after the owner model is actually saved to the database. Of course this only applies when status change is initiated when saving the record. A call to swNextStatus() is not affected by the 'transitionBeforeSave' option.
SWEvent | the event parameter |
processTransition | ( | $event) |
Default implementation for the onProcessTransition event.
This method is dedicated to be overloaded by custom event handler.
SWEvent | the event parameter |
swCreateNode | ( | $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
string | $str | string status name |
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.
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 :
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.
swGetStatus | ( | ) |
swGetWorkflowId | ( | ) |
Returns the current workflow Id the owner component is inserted in, or NULL if the owner component is not inserted into a workflow.
string | current workflow Id or NULL |
swGetWorkflowSource | ( | ) |
swHasStatus | ( | ) |
Test if the owner component is currently inserted in a workflow. This method is equivalent to swGetStatus()!=null.
swInsertToWorkflow | ( | $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.
string | $workflowId | workflow Id or NULL. If NULL the default workflow Id is used |
SWException | the owner model is already in a workflow |
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). SWActiveRecordBehavior::attach
swIsFinalStatus | ( | $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.
status | status to test, or null (will test current status) |
swIsInitialStatus | ( | $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.
mixed | $status | string or SWNode instance |
SWException |
swIsNextStatus | ( | $nextStatus) |
Checks if the status passed as argument can be reached from the current status. This occurs when
Note that if the owner component is not in a workflow, this method returns true if argument $nextStatus is the initial status for the workflow associated with the owner model. In other words the initial status for a given workflow is considered as the 'next' status, for all component associated to this workflow but not inserted in it. Of course, if a constraint is associated with the initial status, it must be evaluated to true.
mixed | nextStatus String or SWNode object for the next status |
swIsStatus | ( | $status) |
Test if the owner component is currently in the status passed as argument.
mixed | $status | name or SWNode instance of the status to test |
swNextStatus | ( | $nextStatus, | |
$params = null |
|||
) |
This is an alias for methode SWActiveRecordBehavior::swSetStatus() and should not be used anymore
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).
see SWActiveRecordBehavior::swIsFinalStatus()
SWException |
swSetStatus | ( | $nextStatus, | |
$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 workflowId/nodeId. This method is responsible for firing SWEvents and executing workflow tasks if defined for the given transition.
mixed | $nextStatus | string or array. If array, it must contains a key equals to the name of the status attribute, and its value is the one of the destination node (e.g. $arr['status']). This is mainly useful when processing _POST array. If a string is provided, it must contain the fullname of the target node (e.g. workfowId/nodeId) |
swStatusEquals | ( | $status = null ) |
Test if the current status is the same as the one passed as argument. A call to swStatusEquals(null) returns TRUE only if the owner component is not in a workflow.
mixed | $status | string or SWNode instance. |
swValidate | ( | $attribute, | |
$value | |||
) |
Validates the status attribute stored in the owner model. This attribute is valid if :
string | $attribute | status attribute name (by default 'status') |
mixed | $value | current value of the status attribute provided as a string or a SWNode object |
$autoInsert =true |
$defaultWorkflow =null |
$enableEvent =true |
|
protected |
$statusAttribute = 'status' |
$transitionBeforeSave =true |
$workflowSourceComponent ='swSource' |
const SW_I8N_CATEGORY ='simpleworkflow' |
const SW_LOG_CATEGORY ='application.simpleWorkflow' |