Documentation

CBPActivity

Everything that happens within a workflow mdash is deemed as activities. The workflow itself is a sequence of composite activities, which helps to determine descendant activities within itself. The activity within a workflow has a name, unique for this workflow.

Activity — is a class that is inherited from abstract CBPActivity class or its descendants. Name of a class must start from substring "CBP" and can have several Latin letters and digits.

<?
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

class CBPMyActivity1
extends CBPActivity
{
. . .
}
?>

The activities that cannot be contained inside other activities are inherited directly from abstract class CBPActivity. This class determines the set of basic methods that are required for any activity. Some methods, defined in the CBPActivity class can, and must be re-defined in the descendant class.

Composite activities are inherited from the abstract CBPCompositeActivity class, that, in turn, is inherited from the CBPActivity class. CBPCompositeActivity class supports the option to include descendant activities. For example, composite activity is the standard activity of CBPParallelActivity (parallel execution), which contains descendant activities, corresponding to parallel execution branches.

CBPCompositeActivity class contains a arActivities member, that can be used to apply the descendant activities.

CBPActivity class contains the following members that must be used in the descendant activities:

  • workflow – contains a wrapper object of CBPWorkflow type for this workflow,
  • parent – contains parent activity,
  • executionStatus – activity execution status,
  • executionResult – result of executed activity.

Class methods

MethodDescriptionAvailable from version
ExecuteThis method is called by the runtime during execution of an activity. It directly realizes the behaviour of activity and shall be re-defined for each activity.
InitializeThis method is called by the runtime to initialize an activity, which occurs prior to workflow launch. The majority of activities do not re-define this method.
HandleFaultThis method is called by the runtime when an error occurs during execution of an error. The method can be re-defined, if during an activity error any code must be executed.
AddStatusChangeHandlerThis method adds new event handler for activity status modification.
GetNameThis method returns an activity name. Activity name is unique within a workflow.
GetRootActivityThis method adds a root activity for workflow. Root activity realizes the IBPRootActivity interface.
GetWorkflowInstanceIdThis method returns workflow ID code.
RemoveStatusChangeHandlerThis method deletes an event handler for activity status modification.
WriteToTrackingServiceThis method records a random message into log. Additionally, information about the message's author can be recorded as welll.

Example

<?
// Class code for activity that creates file with a name, specified in the activity properties
class CBPMyActivity
extends CBPActivity
{
public function __construct($name)
{
parent::__construct($name);
// Define FileName property, which will contain the filename
$this->arProperties = array("Title" => "", "FileName" => "");
}

// Executed activity method
public function Execute()
{
// If the property with filename is specified, record into it
// Please note, the required safety checks to simplify the code
// were not added here
if (strlen($this->FileName) > 0)
{
$f = fopen($this->FileName, "w");
fwrite($f, "Some text");
fclose($f);
}

// Return the call to runtime, prohibiting an activity
return CBPActivityExecutionStatus::Closed;
}
}
?>


© «Bitrix24», 2001-2024