Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes

SWActiveRecordBehavior Class Reference

Public Member Functions

 swGetStatus ()
 swIsEventEnabled ()
 swHasStatus ()
 swGetWorkflowId ()
 attach ($owner)
 swGetDefaultWorkflowId ()
 swInsertToWorkflow ($workflow=null)
 swGetNextStatus ()
 swGetAllStatus ()
 swIsNextStatus ($nextStatus)
 swCreateNode ($str)
 swIsFinalStatus ($status=null)
 swIsInitialStatus ($status=null)
 swValidate ($attribute, $value)
 swNextStatus ($nextStatus=null)
 events ()
 beforeSave ($event)
 afterSave ($event)
 afterFind ($event)
 enterWorkflow ($event)
 onEnterWorkflow ($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)
 initialize ()

Protected Attributes

 $eventClassName = 'SWActiveRecord'

Detailed Description

This class implements all the logic for the simpleWorkflow extension. It must be attached to an object that inherits from the CActiveRecord class. It can be initialized with following parameters :

Author:
Raoul

Definition at line 32 of file SWActiveRecordBehavior.php.


Member Function Documentation

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.

Parameters:
CEvent event parameter

Definition at line 709 of file SWActiveRecordBehavior.php.

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.

Parameters:
SWEvent $event

Definition at line 688 of file SWActiveRecordBehavior.php.

afterTransition ( event  ) 

Default implementation for the onAfterTransition event.
This method is dedicated to be overloaded by custom event handler.

Parameters:
SWEvent the event parameter

Definition at line 839 of file SWActiveRecordBehavior.php.

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:

  • Is there a default workflow associated with the owner component ? : if not, and if the behavior is initialized with autoInsert set to TRUE, an exception is thrown as it will not be possible to insert the component into a workflow.
  • If a default workflow is available for the owner component, and if autoInsert is set to TRUE, the component is inserted in the initial status of its default workflow.
  • Check whether or not, workflow events should be enabled, by testing if the owner component class inherits from the 'SWComponent' class.
See also:
base/CBehaviorattach()

Definition at line 190 of file SWActiveRecordBehavior.php.

beforeSave ( event  ) 

Responds to CActiveRecord::onBeforeSave event.

Overrides this method if you want to handle the corresponding event of the owner. You may set CModelEvent::isValid to be false to quit the saving process.

Parameters:
CModelEvent event parameter

Definition at line 655 of file SWActiveRecordBehavior.php.

beforeTransition ( event  ) 

Default implementation for the onBeforeTransition event.
This method is dedicated to be overloaded by custom event handler.

Parameters:
SWEvent the event parameter

Definition at line 795 of file SWActiveRecordBehavior.php.

canFireEvent ( owner,
className 
) [protected]

Checks that the owner component is able to handle workflow events that could be fired by this behavior

Parameters:
CComponent $owner the owner component attaching this behavior
string $className
Returns:
bool TRUE if workflow events are fired, FALSE if not.

Definition at line 106 of file SWActiveRecordBehavior.php.

enterWorkflow ( event  ) 

Default implementation for the onEnterWorkflow event.
This method is dedicated to be overloaded by custom event handler.

Parameters:
SWEvent the event parameter

Definition at line 774 of file SWActiveRecordBehavior.php.

string name of the class the owner should inherit from in order for SW events (  ) 
See also:
base/CBehaviorevents()

to be enabled.

Definition at line 612 of file SWActiveRecordBehavior.php.

finalStatus ( event  ) 

Default implementation for the onEnterWorkflow event.
This method is dedicated to be overloaded by custom event handler.

Parameters:
SWEvent the event parameter

Definition at line 863 of file SWActiveRecordBehavior.php.

initialize (  )  [protected]

This method is called to initialize the current owner status. If a default workflow can be found and if 'autoInsert' is set to TRUE, the owner component is inserted in the worflow now, by calling swInsertToWorkflow().

Exceptions:
SWException 

Definition at line 218 of file SWActiveRecordBehavior.php.

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.

Parameters:
SWEvent the event parameter

Definition at line 850 of file SWActiveRecordBehavior.php.

onBeforeTransition ( event  ) 

This event is raised before a workflow transition is applied to the owner instance.

Parameters:
SWEvent the event parameter

Definition at line 803 of file SWActiveRecordBehavior.php.

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).

Parameters:
SWEvent the event parameter

Definition at line 786 of file SWActiveRecordBehavior.php.

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).

Parameters:
SWEvent the event parameter

Definition at line 873 of file SWActiveRecordBehavior.php.

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.

Parameters:
SWEvent the event parameter

Definition at line 825 of file SWActiveRecordBehavior.php.

processTransition ( event  ) 

Default implementation for the onProcessTransition event.
This method is dedicated to be overloaded by custom event handler.

Parameters:
SWEvent the event parameter

Definition at line 812 of file SWActiveRecordBehavior.php.

swCreateNode ( str  ) 

Creates a 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.

Parameters:
string $str string status name
Returns:
SWNode the node

Definition at line 424 of file SWActiveRecordBehavior.php.

swGetAllStatus (  ) 

Returns all statuses belonging to the workflow the owner component is inserted in. If the owner component is not inserted in a workflow, an empty array is returned.

Returns:
array list of SWNode objects.

Definition at line 355 of file SWActiveRecordBehavior.php.

swGetDefaultWorkflowId (  ) 

Finds out what should be the default workflow to use with the owner model. A default workflow id in several ways which are explored by this method, in the following order:

  • behavior initialization parameter defaultWorkflow
  • owner component method workflow : if the owner component is able to provide the complete workflow, this method will invoke SWWorkflowSource.addWorkflow
  • created based on the configured prefix followed by the model class name
Returns:
string workflow id to use with the owner component or NULL if now workflow was found

Definition at line 246 of file SWActiveRecordBehavior.php.

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.

Returns:
array SWNode object array for all nodes thats can be reached from the current node.

Definition at line 332 of file SWActiveRecordBehavior.php.

swGetStatus (  ) 

If the owner component is inserted into a workflow, this method returns the SWNode object that represent this status, otherwise NULL is returned.

Returns:
SWNode the current status or NULL if no status is set

Definition at line 115 of file SWActiveRecordBehavior.php.

swGetWorkflowId (  ) 

Returns the current workflow Id the owner component is inserted in, or NULL if the owner component is not inserted into a workflow.

Parameters:
string current workflow Id or NULL

Definition at line 170 of file SWActiveRecordBehavior.php.

swHasStatus (  ) 

Use this method to find out if the owner component is currently inserted into a workflow. This method is equivalent to swGetStatus()!=null.

Returns:
boolean true if the owner model is in a workflow, FALSE otherwise

Definition at line 130 of file SWActiveRecordBehavior.php.

swInsertToWorkflow ( workflow = 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.

Parameters:
string workflow Id or NULL.
Exceptions:
SWException the owner model is already in a workflow

Definition at line 302 of file SWActiveRecordBehavior.php.

swIsEventEnabled (  ) 
Returns:
bool TRUE if workflow events are fire by this behavior, FALSE if not.

Definition at line 121 of file SWActiveRecordBehavior.php.

swIsFinalStatus ( status = null  ) 

Test if the status passed as argument a final status. If null is passed as argument tests if the current status of the owner component is a final status. By definition a final status as no outgoing transition to other status.

Parameters:
status status to test, or null (will test current status)
Returns:
boolean TRUE when the owner component is in a final status, FALSE otherwise

Definition at line 462 of file SWActiveRecordBehavior.php.

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.

Parameters:
mixed $status
Returns:
boolean TRUE if the owner component is in an initial status or if $status is the initial status for the owner component default workflow.
Exceptions:
SWException 

Definition at line 485 of file SWActiveRecordBehavior.php.

swIsNextStatus ( nextStatus  ) 

Checks if the status passed as argument can be reached from the current status. This occurs when

  • a transition has be defined in the workflow between those 2 status
  • the destination status has a constraint that is evaluated to true in the context of the owner model

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.

Parameters:
mixed nextStatus String or SWNode object for the next status
Returns:
boolean TRUE if the status passed as argument can be reached from the current status, FALSE otherwise.

Definition at line 379 of file SWActiveRecordBehavior.php.

swNextStatus ( nextStatus = null  ) 
Parameters:
mixed $nextStatus
Returns:
boolean

Definition at line 543 of file SWActiveRecordBehavior.php.

swValidate ( attribute,
value 
)

Validate the status attribute stored in the owner model. This attribute is valid if :

  • it is not empty
  • it contains a valid status name
  • this status can be reached from the current status
  • or it is equal to the current status (no status change)
Parameters:
string $attribute status attribute name (by default 'status')
mixed $value current value of the status attribute provided as a string or a SWNode object
Returns:
boolean TRUE if the status attribute contains a valid value, FALSE otherwise

Definition at line 517 of file SWActiveRecordBehavior.php.


Field Documentation

$autoInsert = true

Definition at line 51 of file SWActiveRecordBehavior.php.

$defaultWorkflow = null

Definition at line 45 of file SWActiveRecordBehavior.php.

$enableEvent = true

Definition at line 63 of file SWActiveRecordBehavior.php.

$eventClassName = 'SWActiveRecord' [protected]

Definition at line 87 of file SWActiveRecordBehavior.php.

$statusAttribute = 'status'

Definition at line 38 of file SWActiveRecordBehavior.php.

$transitionBeforeSave = true

Definition at line 69 of file SWActiveRecordBehavior.php.

$workflowSourceComponent = 'swSource'

Definition at line 56 of file SWActiveRecordBehavior.php.

const SW_I8N_CATEGORY = 'simpleworkflow'

Definition at line 90 of file SWActiveRecordBehavior.php.

const SW_LOG_CATEGORY = 'application.simpleWorkflow'

Definition at line 89 of file SWActiveRecordBehavior.php.


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