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 
5 require_once './Services/WorkflowEngine/classes/nodes/class.ilBaseNode.php';
6 
18 class ilPluginNode extends ilBaseNode
19 {
26  private $else_emitters;
27 
35 
42  private $evaluation_expression = "return null;";
43 
49  public function __construct(ilWorkflow $context)
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  {
309  return $this->else_activities;
310  }
311  return $this->activities;
312  }
313 
321  public function getEmitters($else = false)
322  {
323  if ($else)
324  {
325  return $this->else_emitters;
326  }
327  return $this->emitters;
328  }
329 }
deactivate()
Deactivates the node.
__construct(ilWorkflow $context)
Default constructor.
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
trigger($a_type, $a_params=null)
Passes a trigger to attached detectors.
attemptTransition()
Attempts to transit the node.
setEvaluationExpression($a_expression)
isActive()
Returns the activation status of the node.
$a_type
Definition: workflow.php:93
getEmitters($else=false)
Returns all currently set emitters.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
onActivate()
Method called on activation of the node.
getActivities($else=false)
Returns all currently set activites.
onDeactivate()
Method calles on deactivation of the node.
Create styles array
The data for the language used.
executeActivities()
Executes all &#39;then&#39;-activities attached to the node.
executeTransition()
Executes the &#39;then&#39;-transition of the node.
executeEmitters()
Executes all &#39;then&#39;-emitters attached to the node.
PhpIncludeInspection
PhpIncludeInspection
Definition: ilWorkflow.php:23
PhpIncludeInspection
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
addEmitter(ilEmitter $emitter, $else_emitter=false)
Adds an emitter to one of the lists attached to the node.
addActivity(ilActivity $activity, $else_activity=false)
Adds an activity to one of the lists attached to the node.
ilEmitter Interface is part of the petri net based workflow engine.
Definition: ilEmitter.php:16
activate()
Activates the node.