ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCaseNode.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 require_once './Services/WorkflowEngine/classes/nodes/class.ilBaseNode.php';
6 
18 class ilCaseNode extends ilBaseNode
19 {
22 
25 
28 
30  public $is_exclusive;
31 
37  public function __construct(ilWorkflow $context)
38  {
39  $this->context = $context;
40  $this->detectors = array();
41  $this->emitters = array();
42  $this->else_emitters = array();
43  $this->activities = array();
44  $this->is_exclusive = false;
45  }
46 
51  {
52  $this->is_exclusive_join = $is_exclusive;
53  }
54 
59  {
60  $this->is_exclusive_fork = $is_exclusive;
61  }
62 
66  public function activate()
67  {
68  $this->active = true;
69  foreach ($this->detectors as $detector) {
70  $detector->onActivate();
71  }
72  $this->onActivate();
73  $this->attemptTransition();
74  }
75 
79  public function deactivate()
80  {
81  $this->active = false;
82  foreach ($this->detectors as $detector) {
83  $detector->onDeactivate();
84  }
85  $this->onDeactivate();
86  }
87 
97  public function checkTransitionPreconditions()
98  {
99  // queries the $detectors if their conditions are met.
100  $isPreconditionMet = true;
101  foreach ($this->detectors as $detector) {
102  if ($isPreconditionMet == true) {
103  $isPreconditionMet = $detector->getDetectorState();
104  if ($isPreconditionMet && ($this->is_exclusive_join || $this->is_exclusive_fork || $this->is_exclusive)) {
105  break;
106  }
107  }
108  }
109  return $isPreconditionMet;
110  }
111 
120  public function attemptTransition()
121  {
122  if ($this->checkTransitionPreconditions() == true) {
123  $this->executeTransition();
124  return true;
125  } else {
126  return false;
127  }
128  }
129 
133  public function executeTransition()
134  {
135  $this->deactivate();
136  if (count($this->activities) != 0) {
137  foreach ($this->activities as $activity) {
138  $activity->execute();
139  }
140  }
141 
142  foreach ((array) $this->condition_emitter_pairs as $pair) {
143  $eval_function = function ($that) use ($pair) {
144  return eval($pair['expression']);
145  };
146 
147  if ($eval_function($this->detectors) === true) {
148  $emitter = $pair['emitter'];
149  $emitter->emit();
150  if ($this->is_exclusive_fork || $this->is_exclusive_join) {
151  return;
152  }
153  }
154  }
155  }
156 
163  public function addEmitter(ilEmitter $emitter, $expression = 'return true;')
164  {
165  $this->condition_emitter_pairs[] = array(
166  'emitter' => $emitter,
167  'expression' => $expression
168  );
169  }
170 
178  public function notifyDetectorSatisfaction(ilDetector $detector)
179  {
180  if ($this->isActive()) {
181  $this->attemptTransition();
182  }
183  }
184 }
attemptTransition()
Attempts to transit the node.
checkTransitionPreconditions()
Checks, if the preconditions of the node to transit are met.
notifyDetectorSatisfaction(ilDetector $detector)
This method is called by detectors, that just switched to being satisfied.
setIsExclusiveFork($is_exclusive)
activate()
Activates the node.
isActive()
Returns the activation status of the node.
PhpIncludeInspection
addEmitter(ilEmitter $emitter, $expression='return true;')
Adds an emitter to one of the lists attached to the node.
deactivate()
Deactivates the node.
onActivate()
Method called on activation of the node.
onDeactivate()
Method calles on deactivation of the node.
executeTransition()
Executes the &#39;then&#39;-transition of the node.
PhpIncludeInspection
Definition: ilWorkflow.php:23
__construct(ilWorkflow $context)
Default constructor.
PhpIncludeInspection
ilDetector Interface is part of the petri net based workflow engine.
Definition: ilDetector.php:16
ilEmitter Interface is part of the petri net based workflow engine.
Definition: ilEmitter.php:16
setIsExclusiveJoin($is_exclusive)