ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $detector->onActivate();
67  }
68  $this->onActivate();
69  $this->attemptTransition();
70  }
71 
75  public function deactivate()
76  {
77  $this->active = false;
78  foreach ($this->detectors as $detector) {
79  $detector->onDeactivate();
80  }
81  $this->onDeactivate();
82  }
83 
91  public function trigger($a_type, $a_params = null)
92  {
93  if ($this->active == true && count($this->detectors) != 0) {
94  foreach ($this->detectors as $detector) {
95  if (get_class($detector) == $a_type) {
96  $detector->trigger($a_params);
97  }
98  }
99  }
100  $this->attemptTransition();
101  }
102 
113  {
114  // TODO Call Plugin here.
115  $eval_function = function ($detectors) {
116  return eval($this->evaluation_expression);
117  };
118 
119  if ($eval_function($this->detectors) === null) {
120  return false;
121  }
122 
123  if ($eval_function($this->detectors) === true) {
124  return true;
125  } else {
126  return true;
127  }
128  }
129 
138  public function attemptTransition()
139  {
140  // TODO Call Plugin here.
141  $eval_function = function ($detectors) {
142  return eval($this->evaluation_expression);
143  };
144 
145  if ($eval_function($this->detectors) === null) {
146  return false;
147  }
148 
149  if ($eval_function($this->detectors) === true) {
150  $this->executeTransition();
151  return true;
152  } else {
153  $this->executeElseTransition();
154  return true;
155  }
156  }
157 
161  private function executeActivities()
162  {
163  if (count($this->activities) != 0) {
164  foreach ($this->activities as $activity) {
165  $activity->execute();
166  }
167  }
168  }
169 
173  private function executeEmitters()
174  {
175  if (count($this->emitters) != 0) {
176  foreach ($this->emitters as $emitter) {
177  $emitter->emit();
178  }
179  }
180  }
181 
185  public function executeTransition()
186  {
187  $this->deactivate();
188  $this->executeActivities();
189  $this->executeEmitters();
190  }
191 
198  public function addEmitter(ilEmitter $emitter, $else_emitter = false)
199  {
200  if (!$else_emitter) {
201  $this->emitters[] = $emitter;
202  } else {
203  $this->else_emitters[] = $emitter;
204  }
205  }
206 
213  public function addActivity(ilActivity $activity, $else_activity = false)
214  {
215  if (!$else_activity) {
216  $this->activities[] = $activity;
217  } else {
218  $this->else_activities[] = $activity;
219  }
220  }
221 
258  public function setEvaluationExpression($a_expression)
259  {
260  // TODO Rework to use a Plugin here.
261  $this->evaluation_expression = $a_expression;
262  }
263 
271  public function notifyDetectorSatisfaction(ilDetector $detector)
272  {
273  if ($this->isActive()) {
274  $this->attemptTransition();
275  }
276  }
277 
285  public function getActivities($else = false)
286  {
287  if ($else) {
288  return $this->else_activities;
289  }
290  return $this->activities;
291  }
292 
300  public function getEmitters($else = false)
301  {
302  if ($else) {
303  return $this->else_emitters;
304  }
305  return $this->emitters;
306  }
307 }
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:92
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.