ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  $tmp = array_keys($node->getNameSpaces(false));
44  $r['namespace'] = $tmp[0];
45  $r['namespaces'] = $namespaces;
46  }
47  if ($namespace) {
48  $r['namespace'] = $namespace;
49  }
50  if ($content) {
51  $r['content'] = $content;
52  }
53 
54  foreach ($namespaces as $pre => $ns) {
55  foreach ($node->children($ns) as $k => $v) {
56  $this->add_node($v, $r['children'], $pre, true);
57  }
58  foreach ($node->attributes($ns) as $k => $v) {
59  $r['attributes'][$k] = "$pre:$v";
60  }
61  }
62 
63  foreach ($node->children() as $k => $v) {
64  $this->add_node($v, $r['children'], '', true);
65  }
66 
67  foreach ($node->attributes() as $k => $v) {
68  $r['attributes'][$k] = "$v";
69  }
70 
71  $parent[] = &$r;
72 
73  return $parent[0];
74  }
75 
76  #endregion
77 
83  public static function xsIDToPHPVarname($xsID)
84  {
85  /*
86  * The type xsd:ID is used for an attribute that uniquely identifies an element in an XML document. An xsd:ID
87  * value must be an NCName. This means that it must start with a letter or underscore, and can only contain
88  * letters, digits, underscores, hyphens, and periods.
89  *
90  * xsd:ID carries several additional constraints:
91  *
92  * * Their values must be unique within an XML instance, regardless of the attribute's name or
93  * its element name.
94  * * A complex type cannot include more than one attribute of type xsd:ID, or any type derived from xsd:ID.
95  * * xsd:ID attributes cannot have default or fixed values specified.
96  *
97  * This differs from PHP variable name rules.
98  * To overcome this, we need to address possible hyphens and periods in xsIDs, here they are replaced.
99  */
100  $xsID_converted = str_replace('.', '__period__', $xsID);
101  $xsID_converted = str_replace('-', '__hyphen__', $xsID_converted);
102  return $xsID_converted;
103  }
104 
112  public static function extractILIASEventDefinitionFromProcess($start_event_ref, $type, $bpmn2_array)
113  {
114  $descriptor_extension = array();
115  $subject_extension = array();
116  $context_extension = array();
117  $timeframe_extension = array();
118 
119  foreach ($bpmn2_array['children'] as $element) {
120  if ($element['name'] == $type && $element['attributes']['id'] == $start_event_ref) {
121  $bpmn_extension_elements = $element['children'][0];
122  $extension_elements = $bpmn_extension_elements['children'][0]['children'];
123 
124  foreach ($extension_elements as $child) {
125  $prefix = 'ilias:';
126  if ($child['namespace'] == 'ilias') {
127  $prefix = '';
128  }
129  if ($child['name'] == $prefix . 'eventDescriptor') {
130  $descriptor_extension = $child;
131  }
132  if ($child['name'] == $prefix . 'eventSubject') {
133  $subject_extension = $child;
134  }
135 
136  if ($child['name'] == $prefix . 'eventContext') {
137  $context_extension = $child;
138  }
139 
140  if ($child['name'] == $prefix . 'eventTimeframe') {
141  $timeframe_extension = $child;
142  }
143  }
144  }
145  }
146 
147  $event_definition = array(
148  'type' => $descriptor_extension['attributes']['type'],
149  'content' => $descriptor_extension['attributes']['name'],
150  'subject_type' => $subject_extension['attributes']['type'],
151  'subject_id' => $subject_extension['attributes']['id'],
152  'context_type' => $context_extension['attributes']['type'],
153  'context_id' => $context_extension['attributes']['id'],
154  'listening_start' => $timeframe_extension['attributes']['start'],
155  'listening_end' => $timeframe_extension['attributes']['end']
156  );
157 
158  return $event_definition;
159  }
160 
168  public static function extractTimeDateEventDefinitionFromElement($start_event_ref, $type, $bpmn2_array)
169  {
170  $content = '';
171  foreach ($bpmn2_array['children'] as $elements) {
172  foreach ($elements['children'] as $element) {
173  if ($element['name'] == $type) {
174  foreach ((array) $element['children'] as $event_child) {
175  if ($event_child['name'] == 'timerEventDefinition') {
176  if ($event_child['children'][0]['name'] == 'timeDate') {
177  $content = $event_child['children'][0]['content'];
178  $start = date('U', strtotime($content));
179  $end = 0;
180 
181  return array(
182  'type' => 'time_passed',
183  'content' => 'time_passed',
184  'subject_type' => 'none',
185  'subject_id' => 0,
186  'context_type' => 'none',
187  'context_id' => 0,
188  'listening_start' => $start,
189  'listening_end' => $end
190  );
191  }
192 
193  if ($event_child['children'][0]['name'] == 'timeDuration') {
194  $content = $event_child['children'][0]['content'];
195  $interval = new \DateInterval(strtotime($content));
196  $duration = ($interval->d * 24 * 60 * 60) + ($interval->h * 60 * 60) +
197  ($interval->i * 60) + $interval->s;
198 
199  return array(
200  'type' => 'time_passed',
201  'content' => 'time_passed',
202  'subject_type' => 'none',
203  'subject_id' => 0,
204  'context_type' => 'none',
205  'context_id' => 0,
206  'listening_relative' => 1,
207  'listening_interval' => $duration
208  );
209  }
210  }
211  }
212  }
213  }
214  }
215  }
216 
222  public static function extractILIASLibraryCallDefinitionFromElement($element)
223  {
224  $library_call = array();
225  foreach ($element['children'] as $child) {
226  if ($child['name'] == 'extensionElements') {
227  foreach ($child['children'] as $extension) {
228  $prefix = 'ilias:';
229  if ($extension['namespace'] == 'ilias') {
230  $prefix = '';
231  }
232  if ($extension['name'] == $prefix . 'properties') {
233  if ($extension['children'][0]['name'] == $prefix . 'libraryCall') {
234  $library_call = $extension['children'][0]['attributes'];
235  break;
236  }
237  }
238  }
239  }
240  }
241 
242  // TODO: This must consult Service Disco for details!
243 
244  return array(
245  'include_filename' => $library_call['location'],
246  'class_and_method' => $library_call['api'] . '::' . $library_call['method']
247  );
248  }
249 
255  public static function extractScriptDefinitionFromElement($element)
256  {
257  $code = '';
258  foreach ($element['children'] as $child) {
259  if ($child['name'] == 'script') {
260  $code = $child['content'];
261  }
262  }
263  return $code;
264  }
265 
271  public static function extractDataNamingFromElement($element)
272  {
273  if (!isset($element['children'])) {
274  return null;
275  }
276 
277  foreach ($element['children'] as $child) {
278  if ($child['name'] == 'extensionElements') {
279  foreach ($child['children'] as $extension) {
280  $prefix = 'ilias:';
281  if ($extension['children'][0]['namespace'] == 'ilias') {
282  $prefix = '';
283  }
284  if ($extension['name'] == $prefix . 'properties') {
285  if ($extension['children'][0]['name'] == $prefix . 'property') {
286  $attributes = $extension['children'][0]['attributes'];
287  return $attributes['value'];
288  break;
289  }
290  }
291  }
292  }
293  }
294 
295  return null;
296  }
297 
303  public static function extractILIASInputPropertiesFromElement($element)
304  {
305  if (!isset($element['children'])) {
306  return null;
307  }
308 
309  $retval = null;
310  foreach ((array) $element['children'] as $child) {
311  if ($child['name'] == 'extensionElements') {
312  foreach ($child['children'] as $extension) {
313  $prefix = 'ilias:';
314  if ($extension['children'][0]['namespace'] == 'ilias') {
315  $prefix = '';
316  }
317  if ($extension['name'] == $prefix . 'properties') {
318  foreach ((array) $extension['children'] as $child) {
319  if ($child['name'] == 'inputproperty') {
320  $retval[$child['attributes']['name']] = $child['attributes']['value'];
321  }
322  }
323  }
324  }
325  }
326  }
327  return $retval;
328  }
329 
335  public static function extractILIASDataObjectDefinitionFromElement($element)
336  {
337  if (!isset($element['children'])) {
338  return null;
339  }
340 
341  $retval = null;
342  foreach ((array) $element['children'] as $child) {
343  if ($child['name'] == 'extensionElements') {
344  foreach ($child['children'] as $extension) {
345  $prefix = 'ilias:';
346  if ($extension['children'][0]['namespace'] == 'ilias') {
347  $prefix = '';
348  }
349  if ($extension['name'] == $prefix . 'properties') {
350  foreach ((array) $extension['children'] as $child) {
351  if ($child['name'] == 'dataobject') {
352  $retval['role'] = $child['attributes']['role'];
353  $retval['type'] = $child['attributes']['type'];
354  }
355  }
356  }
357  }
358  }
359  }
360  return $retval;
361  }
362 
368  public static function extractILIASMessageDefinitionFromElement($element)
369  {
370  if (!isset($element['children'])) {
371  return null;
372  }
373 
374  $retval = null;
375  foreach ((array) $element['children'] as $child) {
376  if ($child['name'] == 'extensionElements') {
377  foreach ($child['children'] as $extension) {
378  $prefix = 'ilias:';
379  if ($extension['children'][0]['namespace'] == 'ilias') {
380  $prefix = '';
381  }
382  if ($extension['name'] == $prefix . 'properties') {
383  foreach ((array) $extension['children'] as $child) {
384  if ($child['attributes']['name'] == 'mailtext') {
385  $retval['mailtext'] = base64_encode($child['content']);
386  }
387  }
388  }
389  }
390  }
391  }
392 
393  return $retval;
394  }
395 }
static extractILIASMessageDefinitionFromElement($element)
if($err=$client->getError()) $namespace
static extractDataNamingFromElement($element)
static extractILIASEventDefinitionFromProcess($start_event_ref, $type, $bpmn2_array)
$type
$code
Definition: example_050.php:99
static extractScriptDefinitionFromElement($element)
Class ilBPMN2ParserUtils.
$start
Definition: bench.php:8
static extractILIASLibraryCallDefinitionFromElement($element)
$r
Definition: example_031.php:79
static extractILIASInputPropertiesFromElement($element)
add_node($node, &$parent=null, $namespace='', $recursive=false)
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
static extractILIASDataObjectDefinitionFromElement($element)
static extractTimeDateEventDefinitionFromElement($start_event_ref, $type, $bpmn2_array)