ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBPMN2ParserUtils.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14 #region XML to Array conversion
15 // as per http://php.net/manual/en/simplexmlelement.children.php#100603
16
22 public function load_string ($xml_string)
23 {
24 $node=@simplexml_load_string($xml_string);
25 return $this->add_node($node);
26 }
27
36 private function add_node ($node, &$parent=null, $namespace='', $recursive=false)
37 {
38 $namespaces = $node->getNameSpaces(true);
39 $content="$node";
40
41 $r['name']=$node->getName();
42 if (!$recursive)
43 {
44 $tmp=array_keys($node->getNameSpaces(false));
45 $r['namespace']=$tmp[0];
46 $r['namespaces']=$namespaces;
47 }
48 if ($namespace) $r['namespace']=$namespace;
49 if ($content) $r['content']=$content;
50
51 foreach ($namespaces as $pre=>$ns)
52 {
53 foreach ($node->children($ns) as $k=>$v)
54 {
55 $this->add_node($v, $r['children'], $pre, true);
56 }
57 foreach ($node->attributes($ns) as $k=>$v)
58 {
59 $r['attributes'][$k]="$pre:$v";
60 }
61 }
62
63 foreach ($node->children() as $k=>$v)
64 {
65 $this->add_node($v, $r['children'], '', true);
66 }
67
68 foreach ($node->attributes() as $k=>$v)
69 {
70 $r['attributes'][$k]="$v";
71 }
72
73 $parent[]=&$r;
74
75 return $parent[0];
76 }
77
78 #endregion
79
85 public static function xsIDToPHPVarname($xsID)
86 {
87 /*
88 * The type xsd:ID is used for an attribute that uniquely identifies an element in an XML document. An xsd:ID
89 * value must be an NCName. This means that it must start with a letter or underscore, and can only contain
90 * letters, digits, underscores, hyphens, and periods.
91 *
92 * xsd:ID carries several additional constraints:
93 *
94 * * Their values must be unique within an XML instance, regardless of the attribute's name or
95 * its element name.
96 * * A complex type cannot include more than one attribute of type xsd:ID, or any type derived from xsd:ID.
97 * * xsd:ID attributes cannot have default or fixed values specified.
98 *
99 * This differs from PHP variable name rules.
100 * To overcome this, we need to address possible hyphens and periods in xsIDs, here they are replaced.
101 */
102 $xsID_converted = str_replace('.','__period__',$xsID);
103 $xsID_converted = str_replace('-','__hyphen__',$xsID_converted);
104 return $xsID_converted;
105 }
106
114 public static function extractILIASEventDefinitionFromProcess($start_event_ref, $type, $bpmn2_array)
115 {
116 $descriptor_extension = array();
117 $subject_extension = array();
118 $context_extension = array();
119 $timeframe_extension = array();
120
121 foreach ($bpmn2_array['children'] as $element)
122 {
123 if ($element['name'] == $type && $element['attributes']['id'] == $start_event_ref)
124 {
125 $bpmn_extension_elements = $element['children'][0];
126 $extension_elements = $bpmn_extension_elements['children'][0]['children'];
127
128 foreach ($extension_elements as $child)
129 {
130 $prefix = 'ilias:';
131 if($child['namespace'] == 'ilias')
132 {
133 $prefix = '';
134 }
135 if ($child['name'] == $prefix.'eventDescriptor')
136 {
137 $descriptor_extension = $child;
138 }
139 if ($child['name'] == $prefix.'eventSubject')
140 {
141 $subject_extension = $child;
142 }
143
144 if ($child['name'] == $prefix.'eventContext')
145 {
146 $context_extension = $child;
147 }
148
149 if ($child['name'] == $prefix.'eventTimeframe')
150 {
151 $timeframe_extension = $child;
152 }
153 }
154 }
155 }
156
157 $event_definition = array(
158 'type' => $descriptor_extension['attributes']['type'],
159 'content' => $descriptor_extension['attributes']['name'],
160 'subject_type' => $subject_extension['attributes']['type'],
161 'subject_id' => $subject_extension['attributes']['id'],
162 'context_type' => $context_extension['attributes']['type'],
163 'context_id' => $context_extension['attributes']['id'],
164 'listening_start' => $timeframe_extension['attributes']['start'],
165 'listening_end' => $timeframe_extension['attributes']['end']
166 );
167
168 return $event_definition;
169 }
170
178 public static function extractTimeDateEventDefinitionFromElement($start_event_ref, $type, $bpmn2_array)
179 {
180 $content = '';
181 foreach($bpmn2_array['children'] as $elements)
182 {
183 foreach($elements['children'] as $element)
184 {
185 if ($element['name'] == $type)
186 {
187 foreach((array)$element['children'] as $event_child)
188 {
189 if($event_child['name'] == 'timerEventDefinition')
190 {
191 if($event_child['children'][0]['name'] == 'timeDate')
192 {
193 $content = $event_child['children'][0]['content'];
194 $start = date('U',strtotime($content));
195 $end = 0;
196
197 return array(
198 'type' => 'time_passed',
199 'content' => 'time_passed',
200 'subject_type' => 'none',
201 'subject_id' => 0,
202 'context_type' => 'none',
203 'context_id' => 0,
204 'listening_start' => $start,
205 'listening_end' => $end
206 );
207 }
208
209 if($event_child['children'][0]['name'] == 'timeDuration')
210 {
211 $content = $event_child['children'][0]['content'];
212 $interval = new \DateInterval(strtotime($content));
213 $duration = ($interval->d * 24 * 60 * 60) + ($interval->h * 60 * 60) +
214 ($interval->i * 60) + $interval->s;
215
216 return array(
217 'type' => 'time_passed',
218 'content' => 'time_passed',
219 'subject_type' => 'none',
220 'subject_id' => 0,
221 'context_type' => 'none',
222 'context_id' => 0,
223 'listening_relative'=> 1,
224 'listening_interval'=> $duration
225 );
226 }
227 }
228 }
229 }
230 }
231 }
232
233 }
234
240 public static function extractILIASLibraryCallDefinitionFromElement($element)
241 {
242 $library_call = array();
243 foreach($element['children'] as $child)
244 {
245 if($child['name'] == 'extensionElements')
246 {
247 foreach($child['children'] as $extension)
248 {
249 $prefix = 'ilias:';
250 if($extension['namespace'] == 'ilias')
251 {
252 $prefix = '';
253 }
254 if($extension['name'] == $prefix.'properties')
255 {
256 if($extension['children'][0]['name'] == $prefix.'libraryCall')
257 {
258 $library_call = $extension['children'][0]['attributes'];
259 break;
260 }
261 }
262 }
263 }
264 }
265
266 // TODO: This must consult Service Disco for details!
267
268 return array(
269 'include_filename' => $library_call['location'],
270 'class_and_method' => $library_call['api'] .'::' . $library_call['method']
271 );
272 }
273
279 public static function extractScriptDefinitionFromElement($element)
280 {
281 $code = '';
282 foreach($element['children'] as $child)
283 {
284 if($child['name'] == 'script')
285 {
286 $code = $child['content'];
287 }
288 }
289 return $code;
290 }
291
297 public static function extractDataNamingFromElement($element)
298 {
299 if(!isset($element['children']))
300 {
301 return null;
302 }
303
304 foreach($element['children'] as $child)
305 {
306 if($child['name'] == 'extensionElements')
307 {
308 foreach($child['children'] as $extension)
309 {
310 $prefix = 'ilias:';
311 if($extension['children'][0]['namespace'] == 'ilias')
312 {
313 $prefix = '';
314 }
315 if($extension['name'] == $prefix.'properties')
316 {
317 if($extension['children'][0]['name'] == $prefix.'property')
318 {
319 $attributes = $extension['children'][0]['attributes'];
320 return $attributes['value'];
321 break;
322 }
323 }
324 }
325 }
326 }
327
328 return null;
329 }
330
336 public static function extractILIASInputPropertiesFromElement($element)
337 {
338 if(!isset($element['children']))
339 {
340 return null;
341 }
342
343 $retval = null;
344 foreach((array)$element['children'] as $child)
345 {
346 if($child['name'] == 'extensionElements')
347 {
348 foreach($child['children'] as $extension)
349 {
350 $prefix = 'ilias:';
351 if($extension['children'][0]['namespace'] == 'ilias')
352 {
353 $prefix = '';
354 }
355 if($extension['name'] == $prefix.'properties')
356 {
357 foreach((array)$extension['children'] as $child)
358 {
359 if($child['name'] == 'inputproperty')
360 {
361 $retval[$child['attributes']['name']] = $child['attributes']['value'];
362 }
363 }
364 }
365 }
366 }
367 }
368 return $retval;
369 }
370
376 public static function extractILIASDataObjectDefinitionFromElement($element)
377 {
378 if(!isset($element['children']))
379 {
380 return null;
381 }
382
383 $retval = null;
384 foreach((array)$element['children'] as $child)
385 {
386 if($child['name'] == 'extensionElements')
387 {
388 foreach($child['children'] as $extension)
389 {
390 $prefix = 'ilias:';
391 if($extension['children'][0]['namespace'] == 'ilias')
392 {
393 $prefix = '';
394 }
395 if($extension['name'] == $prefix.'properties')
396 {
397 foreach((array)$extension['children'] as $child)
398 {
399 if($child['name'] == 'dataobject')
400 {
401 $retval['role'] = $child['attributes']['role'];
402 $retval['type'] = $child['attributes']['type'];
403 }
404 }
405 }
406 }
407 }
408 }
409 return $retval;
410 }
411
417 public static function extractILIASMessageDefinitionFromElement($element)
418 {
419 if(!isset($element['children']))
420 {
421 return null;
422 }
423
424 $retval = null;
425 foreach((array)$element['children'] as $child)
426 {
427 if($child['name'] == 'extensionElements')
428 {
429 foreach($child['children'] as $extension)
430 {
431 $prefix = 'ilias:';
432 if($extension['children'][0]['namespace'] == 'ilias')
433 {
434 $prefix = '';
435 }
436 if($extension['name'] == $prefix.'properties')
437 {
438 foreach((array)$extension['children'] as $child)
439 {
440 if($child['attributes']['name'] == 'mailtext')
441 {
442 $retval['mailtext'] = base64_encode($child['content']);
443 }
444 }
445 }
446 }
447 }
448 }
449
450 return $retval;
451 }
452}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Class ilBPMN2ParserUtils.
add_node($node, &$parent=null, $namespace='', $recursive=false)
static extractILIASLibraryCallDefinitionFromElement($element)
static extractDataNamingFromElement($element)
static extractILIASDataObjectDefinitionFromElement($element)
static extractScriptDefinitionFromElement($element)
static extractILIASEventDefinitionFromProcess($start_event_ref, $type, $bpmn2_array)
static extractILIASInputPropertiesFromElement($element)
static extractILIASMessageDefinitionFromElement($element)
static extractTimeDateEventDefinitionFromElement($start_event_ref, $type, $bpmn2_array)
if($err=$client->getError()) $namespace
$r
Definition: example_031.php:79
$code
Definition: example_050.php:99