ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilConditionalNode.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 
30 {
37  private $else_emitters;
38 
46 
53  private $evaluation_expression = "return true;";
54 
60  public function __construct(ilWorkflow $a_context)
61  {
62  $this->context = $a_context;
63  $this->detectors = array();
64  $this->emitters = array();
65  $this->else_emitters = array();
66  $this->activities = array();
67  $this->else_activities = array();
68  }
69 
73  public function activate()
74  {
75  $this->active = true;
76  foreach ($this->detectors as $detector) {
77  $detector->onActivate();
78  }
79  $this->onActivate();
80  $this->attemptTransition();
81  }
82 
86  public function deactivate()
87  {
88  $this->active = false;
89  foreach ($this->detectors as $detector) {
90  $detector->onDeactivate();
91  }
92  $this->onDeactivate();
93  }
94 
105  {
106  $eval_function = function ($detectors) {
107  return eval($this->evaluation_expression);
108  };
109 
110  if ($eval_function($this->detectors) === null) {
111  return false;
112  }
113 
114  if ($eval_function($this->detectors) === true) {
115  return true;
116  } else {
117  return true;
118  }
119  }
120 
129  public function attemptTransition()
130  {
131  $eval_function = function ($detectors) {
132  return eval($this->evaluation_expression);
133  };
134 
135  if ($eval_function($this->detectors) === null) {
136  return false;
137  }
138 
139  if ($eval_function($this->detectors) === true) {
140  $this->executeTransition();
141  return true;
142  } else {
143  $this->executeElseTransition();
144  return true;
145  }
146  }
147 
151  private function executeActivities()
152  {
153  if (count($this->activities) != 0) {
154  foreach ($this->activities as $activity) {
155  $activity->execute();
156  }
157  }
158  }
159 
163  private function executeElseActivities()
164  {
165  if (count($this->else_activities) != 0) {
166  foreach ($this->else_activities as $activity) {
167  $activity->execute();
168  }
169  }
170  }
171 
175  private function executeEmitters()
176  {
177  if (count($this->emitters) != 0) {
178  foreach ($this->emitters as $emitter) {
179  $emitter->emit();
180  }
181  }
182  }
183 
187  private function executeElseEmitters()
188  {
189  if (count($this->else_emitters) != 0) {
190  foreach ($this->else_emitters as $emitter) {
191  $emitter->emit();
192  }
193  }
194  }
195 
199  public function executeTransition()
200  {
201  $this->deactivate();
202  $this->executeActivities();
203  $this->executeEmitters();
204  }
205 
209  public function executeElseTransition()
210  {
211  $this->deactivate();
212  $this->executeElseActivities();
213  $this->executeElseEmitters();
214  }
215 
222  public function addEmitter(ilEmitter $emitter, $else_emitter = false)
223  {
224  if (!$else_emitter) {
225  $this->emitters[] = $emitter;
226  } else {
227  $this->else_emitters[] = $emitter;
228  }
229  }
230 
237  public function addActivity(ilActivity $activity, $else_activity = false)
238  {
239  if (!$else_activity) {
240  $this->activities[] = $activity;
241  } else {
242  $this->else_activities[] = $activity;
243  }
244  }
245 
282  public function setEvaluationExpression($a_expression)
283  {
284  $this->evaluation_expression = $a_expression;
285  }
286 
294  public function notifyDetectorSatisfaction(ilDetector $detector)
295  {
296  if ($this->isActive()) {
297  $this->attemptTransition();
298  }
299  }
300 
308  public function getActivities($else = false)
309  {
310  if ($else) {
311  return $this->else_activities;
312  }
313 
314  return $this->activities;
315  }
316 
324  public function getEmitters($else = false)
325  {
326  if ($else) {
327  return $this->else_emitters;
328  }
329 
330  return $this->emitters;
331  }
332 }
attemptTransition()
Attempts to transit the node.
getEmitters($else=false)
Returns all currently set emitters.
getActivities($else=false)
Returns all currently set activites.
addActivity(ilActivity $activity, $else_activity=false)
Adds an activity to one of the lists attached to the node.
executeTransition()
Executes the &#39;then&#39;-transition of the node.
setEvaluationExpression($a_expression)
isActive()
Returns the activation status of the node.
executeActivities()
Executes all &#39;then&#39;-activities attached to the node.
executeElseTransition()
Executes the &#39;else&#39;-transition of the node.
addEmitter(ilEmitter $emitter, $else_emitter=false)
Adds an emitter to one of the lists attached to the node.
onActivate()
Method called on activation of the node.
onDeactivate()
Method calles on deactivation of the node.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
Create styles array
The data for the language used.
__construct(ilWorkflow $a_context)
Default constructor.
PhpIncludeInspection
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
PhpIncludeInspection
Definition: ilWorkflow.php:23
PhpIncludeInspection
deactivate()
Deactivates the node.
activate()
Activates the node.
executeElseActivities()
Exectes all &#39;else&#39;-activities attached to the node.
ilDetector Interface is part of the petri net based workflow engine.
Definition: ilDetector.php:16
ilActivity Interface is part of the petri net based workflow engine.
Definition: ilActivity.php:15
executeElseEmitters()
Executes all &#39;else&#39;-emitters attached to the node.
ilEmitter Interface is part of the petri net based workflow engine.
Definition: ilEmitter.php:16
executeEmitters()
Executes all &#39;then&#39;-emitters attached to the node.