ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once './Services/WorkflowEngine/classes/nodes/class.ilBaseNode.php';
6
30{
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 {
78 $detector->onActivate();
79 }
80 $this->onActivate();
81 $this->attemptTransition();
82 }
83
87 public function deactivate()
88 {
89 $this->active = false;
90 foreach($this->detectors as $detector)
91 {
92 $detector->onDeactivate();
93 }
94 $this->onDeactivate();
95 }
96
107 {
108 $eval_function = create_function('$detectors', $this->evaluation_expression);
109
110 if ($eval_function($this->detectors) === null)
111 {
112 return false;
113 }
114
115 if ($eval_function($this->detectors) === true)
116 {
117 return true;
118 }
119 else
120 {
121 return true;
122 }
123 }
124
133 public function attemptTransition()
134 {
135 $eval_function = create_function('$detectors', $this->evaluation_expression);
136
137 if ($eval_function($this->detectors) === null)
138 {
139 return false;
140 }
141
142 if ($eval_function($this->detectors) === true)
143 {
144 $this->executeTransition();
145 return true;
146 }
147 else
148 {
149 $this->executeElseTransition();
150 return true;
151 }
152 }
153
157 private function executeActivities()
158 {
159 if (count($this->activities) != 0)
160 {
161 foreach ($this->activities as $activity)
162 {
163 $activity->execute();
164 }
165 }
166 }
167
171 private function executeElseActivities()
172 {
173 if (count($this->else_activities) != 0)
174 {
175 foreach ($this->else_activities as $activity)
176 {
177 $activity->execute();
178 }
179 }
180 }
181
185 private function executeEmitters()
186 {
187 if (count($this->emitters) != 0)
188 {
189 foreach ($this->emitters as $emitter)
190 {
191 $emitter->emit();
192 }
193 }
194 }
195
199 private function executeElseEmitters()
200 {
201 if (count($this->else_emitters) != 0)
202 {
203 foreach ($this->else_emitters as $emitter)
204 {
205 $emitter->emit();
206 }
207 }
208 }
209
213 public function executeTransition()
214 {
215 $this->deactivate();
216 $this->executeActivities();
217 $this->executeEmitters();
218 }
219
223 public function executeElseTransition()
224 {
225 $this->deactivate();
226 $this->executeElseActivities();
227 $this->executeElseEmitters();
228 }
229
236 public function addEmitter(ilEmitter $emitter, $else_emitter = false)
237 {
238 if (!$else_emitter)
239 {
240 $this->emitters[] = $emitter;
241 }
242 else
243 {
244 $this->else_emitters[] = $emitter;
245 }
246 }
247
254 public function addActivity(ilActivity $activity, $else_activity = false)
255 {
256 if (!$else_activity)
257 {
258 $this->activities[] = $activity;
259 }
260 else
261 {
262 $this->else_activities[] = $activity;
263 }
264 }
265
302 public function setEvaluationExpression($a_expression)
303 {
304 $this->evaluation_expression = $a_expression;
305 }
306
314 public function notifyDetectorSatisfaction(ilDetector $detector)
315 {
316 if ($this->isActive())
317 {
318 $this->attemptTransition();
319 }
320 }
321
329 public function getActivities($else = false)
330 {
331 if ($else)
332 {
334 }
335
336 return $this->activities;
337 }
338
346 public function getEmitters($else = false)
347 {
348 if ($else)
349 {
351 }
352
353 return $this->emitters;
354 }
355}
An exception for terminatinating execution or to throw for unit testing.
@noinspection PhpIncludeInspection
onDeactivate()
Method calles on deactivation of the node.
isActive()
Returns the activation status of the node.
onActivate()
Method called on activation of the node.
@noinspection PhpIncludeInspection
activate()
Activates the node.
executeElseActivities()
Exectes all 'else'-activities attached to the node.
addActivity(ilActivity $activity, $else_activity=false)
Adds an activity to one of the lists attached to the node.
executeEmitters()
Executes all 'then'-emitters attached to the node.
setEvaluationExpression($a_expression)
attemptTransition()
Attempts to transit the node.
getEmitters($else=false)
Returns all currently set emitters.
addEmitter(ilEmitter $emitter, $else_emitter=false)
Adds an emitter to one of the lists attached to the node.
executeElseTransition()
Executes the 'else'-transition of the node.
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
getActivities($else=false)
Returns all currently set activites.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
__construct(ilWorkflow $a_context)
Default constructor.
executeTransition()
Executes the 'then'-transition of the node.
deactivate()
Deactivates the node.
executeElseEmitters()
Executes all 'else'-emitters attached to the node.
executeActivities()
Executes all 'then'-activities attached to the node.
ilActivity Interface is part of the petri net based workflow engine.
Definition: ilActivity.php:16
ilDetector Interface is part of the petri net based workflow engine.
Definition: ilDetector.php:17
ilEmitter Interface is part of the petri net based workflow engine.
Definition: ilEmitter.php:17
@noinspection PhpIncludeInspection
Definition: ilWorkflow.php:24