ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilPluginNode.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
19{
27
35
42 private $evaluation_expression = "return null;";
43
50 {
51 $this->context = $context;
52 $this->detectors = array();
53 $this->emitters = array();
54 $this->else_emitters = array();
55 $this->activities = array();
56 $this->else_activities = array();
57 }
58
62 public function activate()
63 {
64 $this->active = true;
65 foreach($this->detectors as $detector)
66 {
67 $detector->onActivate();
68 }
69 $this->onActivate();
70 $this->attemptTransition();
71 }
72
76 public function deactivate()
77 {
78 $this->active = false;
79 foreach($this->detectors as $detector)
80 {
81 $detector->onDeactivate();
82 }
83 $this->onDeactivate();
84 }
85
93 public function trigger($a_type, $a_params = null)
94 {
95 if ($this->active == true && count($this->detectors) != 0)
96 {
97 foreach($this->detectors as $detector)
98 {
99 if (get_class($detector) == $a_type)
100 {
101 $detector->trigger($a_params);
102 }
103 }
104 }
105 $this->attemptTransition();
106 }
107
118 {
119 // TODO Call Plugin here.
120 $eval_function = create_function('$detectors', $this->evaluation_expression);
121
122 if ($eval_function($this->detectors) === null)
123 {
124 return false;
125 }
126
127 if ($eval_function($this->detectors) === true)
128 {
129 return true;
130 }
131 else
132 {
133 return true;
134 }
135 }
136
145 public function attemptTransition()
146 {
147 // TODO Call Plugin here.
148 $eval_function = create_function('$detectors', $this->evaluation_expression);
149
150 if ($eval_function($this->detectors) === null)
151 {
152 return false;
153 }
154
155 if ($eval_function($this->detectors) === true)
156 {
157 $this->executeTransition();
158 return true;
159 }
160 else
161 {
162 $this->executeElseTransition();
163 return true;
164 }
165 }
166
170 private function executeActivities()
171 {
172 if (count($this->activities) != 0)
173 {
174 foreach ($this->activities as $activity)
175 {
176 $activity->execute();
177 }
178 }
179 }
180
184 private function executeEmitters()
185 {
186 if (count($this->emitters) != 0)
187 {
188 foreach ($this->emitters as $emitter)
189 {
190 $emitter->emit();
191 }
192 }
193 }
194
198 public function executeTransition()
199 {
200 $this->deactivate();
201 $this->executeActivities();
202 $this->executeEmitters();
203 }
204
211 public function addEmitter(ilEmitter $emitter, $else_emitter = false)
212 {
213 if (!$else_emitter)
214 {
215 $this->emitters[] = $emitter;
216 }
217 else
218 {
219 $this->else_emitters[] = $emitter;
220 }
221 }
222
229 public function addActivity(ilActivity $activity, $else_activity = false)
230 {
231 if (!$else_activity)
232 {
233 $this->activities[] = $activity;
234 }
235 else
236 {
237 $this->else_activities[] = $activity;
238 }
239 }
240
277 public function setEvaluationExpression($a_expression)
278 {
279 // TODO Rework to use a Plugin here.
280 $this->evaluation_expression = $a_expression;
281 }
282
290 public function notifyDetectorSatisfaction(ilDetector $detector)
291 {
292 if ($this->isActive())
293 {
294 $this->attemptTransition();
295 }
296 }
297
305 public function getActivities($else = false)
306 {
307 if ($else)
308 {
310 }
311 return $this->activities;
312 }
313
321 public function getEmitters($else = false)
322 {
323 if ($else)
324 {
326 }
327 return $this->emitters;
328 }
329}
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
executeActivities()
Executes all 'then'-activities attached to the node.
attemptTransition()
Attempts to transit the node.
activate()
Activates the node.
__construct(ilWorkflow $context)
Default constructor.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
trigger($a_type, $a_params=null)
Passes a trigger to attached detectors.
executeEmitters()
Executes all 'then'-emitters attached to the node.
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
addActivity(ilActivity $activity, $else_activity=false)
Adds an activity to one of the lists attached to the node.
executeTransition()
Executes the 'then'-transition of the node.
getActivities($else=false)
Returns all currently set activites.
deactivate()
Deactivates the node.
setEvaluationExpression($a_expression)
addEmitter(ilEmitter $emitter, $else_emitter=false)
Adds an emitter to one of the lists attached to the node.
getEmitters($else=false)
Returns all currently set emitters.
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
$a_type
Definition: workflow.php:93