Views: 7809
Last Modified: 16.09.2014

Composite activities are inherited from the abstract class CBPCompositeActivity which, in its turn, is inherited from the class CBPActivity. The class CBPCompositeActivity provides for support of the option to include subordinate activities inside the activity. For example, the standard activity CBPParallelActivity (execution in parallel) which contains subordinate activities corresponding to threads of parallel execution constitutes a composite activity.

The class CBPCompositeActivity contains the member arActivities which can be used to access subordinate activities.

For example, if the first subordinate activity must be started and terminated when launching an activity, the following code can be used:

class CBPMyActivity
	extends CBPCompositeActivity    // inherited, because it is a composite activity
	implements IBPEventActivity	// processing the event of termination of a subordinate //activity
{
	// Exacutable method of the activity
	public function Execute()
	{
		// We take the first subordinate activity
		$activity = $this->arActivities[0];
		// and subscribe to the event of subordinate activity status change
 		//  (termination)
		$activity->AddStatusChangeHandler(self::ClosedEvent, $this);
		// Submit the subordinate activity to the executing environment for execution
		$this->workflow->ExecuteActivity($activity);
		// Return the instruction to the executing environment that the activity is still being executed
		return CBPActivityExecutionStatus::Executing;
	}

	// Interface status change event handler IBPEventActivity
	// The parameter transmits the activity that has changed the status
	protected function OnEvent(CBPActivity $sender)
	{
		// Unsubscribe from the event of subordinate activity status change
 		// (termination)
		$sender->RemoveStatusChangeHandler(self::ClosedEvent, $this);
		// Subordinate activity is terminated, we execute other code we need
		//  we execute other code we need
		$this->workflow->CloseActivity($this);
	}
}



Courses developed by Bitrix24