ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBasicNode.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 require_once './Services/WorkflowEngine/classes/nodes/class.ilBaseNode.php';
6 
15 class ilBasicNode extends ilBaseNode
16 {
29 
32 
34  public $ident;
35 
41  public function __construct(ilWorkflow $context)
42  {
43  $this->context = $context;
44  $this->detectors = array();
45  $this->emitters = array();
46  $this->activities = array();
47  $this->active = false;
48  $this->is_forward_condition_node = false;
49  $this->is_forward_condition_event = false;
50  $this->ident = strtoupper(substr(md5(spl_object_hash($this)), 0, 6));
51  }
52 
56  public function activate()
57  {
58  if ($this->isActive()) {
59  return;
60  }
61 
62  $this->active = true;
63 
64  foreach ($this->detectors as $detector) {
65  $detector->onActivate();
66  }
67  $this->onActivate();
68  $this->attemptTransition();
69  }
70 
74  public function deactivate()
75  {
76  $this->active = false;
77  foreach ($this->detectors as $detector) {
78  $detector->onDeactivate();
79  }
80  $this->onDeactivate();
81  }
82 
88  public function checkTransitionPreconditions()
89  {
90  // queries the $detectors if their conditions are met.
91  $isPreconditionMet = true;
92  foreach ($this->detectors as $detector) {
93  if ($isPreconditionMet == true) {
94  $isPreconditionMet = $detector->getDetectorState();
95  }
96  }
97  return $isPreconditionMet;
98  }
99 
108  public function attemptTransition()
109  {
110  if ($this->checkTransitionPreconditions() == true) {
111  $this->executeTransition();
112  return true;
113  } else {
114  return false;
115  }
116  }
117 
121  private function executeActivities()
122  {
123  if (count($this->activities) != 0) {
124  foreach ($this->activities as $activity) {
125  $activity->execute();
126  }
127  }
128  }
129 
133  private function executeEmitters()
134  {
135  if (count($this->emitters) != 0) {
136  foreach ($this->emitters as $emitter) {
137  $emitter->emit();
138  }
139  }
140  }
141 
145  public function executeTransition()
146  {
147  $this->deactivate();
148  $this->executeActivities();
149  $this->pingbackToPredecessorNodes();
150  $this->executeEmitters();
151  }
152 
160  public function notifyDetectorSatisfaction(ilDetector $detector)
161  {
162  if ($this->isActive()) {
163  $this->attemptTransition();
164  }
165  }
166 
170  public function isForwardConditionNode()
171  {
173  }
174 
179  {
180  $this->is_forward_condition_node = $is_forward_condition_node;
181  }
182 
190  public function deactivateForwardConditionNodes(ilNode $activated_node)
191  {
192  if ($this->is_forward_condition_node) {
193  foreach ($this->emitters as $emitter) {
195  $target_detector = $emitter->getTargetDetector();
196 
198  $target_node = $target_detector->getContext();
199 
200  if ($target_node === $activated_node) {
201  continue;
202  }
203  $target_node->deactivate();
204  }
205  }
206  }
207 
208  public function pingbackToPredecessorNodes()
209  {
211  foreach ($this->detectors as $detector) {
213  $source_node = $detector->getSourceNode();
214  if ($source_node && $source_node->is_forward_condition_node) {
215  $source_node->deactivateForwardConditionNodes($this);
216  }
217  }
218  }
219 }
executeTransition()
Executes the transition, calls all activities and emitters to execute.
isActive()
Returns the activation status of the node.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
deactivate()
Deactivates the node.
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
__construct(ilWorkflow $context)
Default constructor.
onActivate()
Method called on activation of the node.
PhpIncludeInspection
PhpIncludeInspection
Definition: ilNode.php:25
onDeactivate()
Method calles on deactivation of the node.
executeEmitters()
Executes all attached emitters.
Create styles array
The data for the language used.
executeActivities()
Executes all attached activities.
attemptTransition()
Attempts to transit the node.
PhpIncludeInspection
Definition: ilWorkflow.php:23
PhpIncludeInspection
ilDetector Interface is part of the petri net based workflow engine.
Definition: ilDetector.php:16
setIsForwardConditionNode($is_forward_condition_node)
activate()
Activates the node.