ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilWorkflowScaffold.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14 #region Requires / File inclusion
15
17 public $requires = array();
18
21
24
27
30
34 public function registerRequire($require)
35 {
36 if (!in_array($require, $this->requires)) {
37 $this->requires[] = $require;
38 }
39 }
40
44 public function getRequires()
45 {
46 $requires = '';
47 foreach ($this->requires as $required_file) {
48 $requires .= "require_once '" . $required_file . "';\n";
49 }
50 return $requires;
51 }
52
53 #endregion
54
55 #region StartEvent Message Registration and Handling
56
59
63 public function registerStartEventRef($start_event_ref)
64 {
65 $this->start_event_refs[] = array('type' => 'message', 'ref' => $start_event_ref);
66 }
67
71 public function registerStartSignalRef($start_event_ref)
72 {
73 $this->start_event_refs[] = array('type' => 'signal', 'ref' => $start_event_ref);
74 }
75
79 public function registerStartTimerRef($start_event_ref)
80 {
81 $this->start_event_refs[] = array('type' => 'timeDate', 'ref' => $start_event_ref);
82 }
83
87 public function getStartEventInfo()
88 {
89 $event_definitions = array();
90 foreach ((array) $this->start_event_refs as $start_event_ref) {
91 $event_definition = array();
92 switch ($start_event_ref['type']) {
93 case 'message':
95 $start_event_ref['ref'],
96 'message',
97 $this->bpmn2_array
98 );
99 break;
100 case 'signal':
102 $start_event_ref['ref'],
103 'signal',
104 $this->bpmn2_array
105 );
106 break;
107 case 'timeDate':
108 $event_definition = $this->getTimeDateEventDefinition($start_event_ref['ref']);
109 break;
110 }
111 $event_definitions[] = $event_definition;
112 }
113
114 if (count($event_definitions)) {
115 $code = '
116 public static $startEventRequired = true;
117 ' . "
118 public static function getStartEventInfo()
119 {";
120 foreach ($event_definitions as $event_definition) {
121 $code .= '
122 $events[] = ' . "array(
123 'type' => '" . $event_definition['type'] . "',
124 'content' => '" . $event_definition['content'] . "',
125 'subject_type' => '" . $event_definition['subject_type'] . "',
126 'subject_id' => '" . $event_definition['subject_id'] . "',
127 'context_type' => '" . $event_definition['context_type'] . "',
128 'context_id' => '" . $event_definition['context_id'] . "',
129 );
130 ";
131 }
132 $code .= '
133 return $events;
134 }
135 ';
136 return $code;
137 } else {
138 return '
139 public static $startEventRequired = false;
140 ';
141 }
142 }
143
144 #endregion
145
150 {
151 $this->workflow_name = $workflow_name;
152 }
153
157 public function addAuxilliaryMethod($auxilliary_method)
158 {
159 $this->auxilliary_methods[] = $auxilliary_method;
160 }
161
162 public function __construct($bpmn2_array)
163 {
164 $this->registerRequire('./Services/WorkflowEngine/classes/workflows/class.ilBaseWorkflow.php');
165 $this->bpmn2_array = $bpmn2_array;
166 $this->auxilliary_methods = array();
167 }
168
173 {
175 }
176
181 {
182 $this->constructor_method_content = $constructor_method_content;
183 }
184
188 public function getPHP()
189 {
190 $pre_constructor_content = $this->getRequires();
191 $pre_constructor_content .= "
192 class " . $this->workflow_name . " extends ilBaseWorkflow
193 {
194 " . $this->getStartEventInfo() . "
195 public function __construct()
196 {
197 ";
198
199 $post_constructor_content = "
200 }";
201 foreach ($this->auxilliary_methods as $auxilliary_method) {
202 $post_constructor_content .= "
203
204 " . $auxilliary_method . "
205 ";
206 }
207 $post_constructor_content .= "
208 }
209 ";
210
211 return $pre_constructor_content . $this->constructor_method_content . $post_constructor_content;
212 }
213
219 public function getTimeDateEventDefinition($start_event_ref)
220 {
221 $content = '';
222 foreach ((array) $this->bpmn2_array['children'] as $elements) {
223 foreach ((array) $elements['children'] as $element) {
224 if ($element['name'] == 'startEvent' && @$element['children'][0]['name'] == 'timerEventDefinition') {
225 $timer_element = $element['children'][0];
226 $content = $timer_element['children'][0]['content'];
227 }
228 }
229 }
230
231 $start = date('U', strtotime($content));
232 $end = 0;
233
234 return array(
235 'type' => 'time_passed',
236 'content' => 'time_passed',
237 'subject_type' => 'none',
238 'subject_id' => 0,
239 'context_type' => 'none',
240 'context_id' => 0,
241 'listening_start' => $start,
242 'listening_end' => $end
243 );
244 }
245}
An exception for terminatinating execution or to throw for unit testing.
static extractILIASEventDefinitionFromProcess($start_event_ref, $type, $bpmn2_array)
Class ilWorkflowScaffold.
registerStartEventRef($start_event_ref)
addAuxilliaryMethod($auxilliary_method)
registerStartSignalRef($start_event_ref)
setConstructorMethodContent($constructor_method_content)
getTimeDateEventDefinition($start_event_ref)
registerStartTimerRef($start_event_ref)