ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
SeqTreeBuilder.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 /*
24  PHP port of several ADL-sources
25  @author Hendrik Holtmann <holtmann@mac.com>
26 
27  This .php file is GPL licensed (see above) but based on
28  Sourcecode by ADL Co-Lab, which is licensed as:
29 
30  Advanced Distributed Learning Co-Laboratory (ADL Co-Lab) Hub grants you
31  ("Licensee") a non-exclusive, royalty free, license to use, modify and
32  redistribute this software in source and binary code form, provided that
33  i) this copyright notice and license appear on all copies of the software;
34  and ii) Licensee does not utilize the software in a manner which is
35  disparaging to ADL Co-Lab Hub.
36 
37  This software is provided "AS IS," without a warranty of any kind. ALL
38  EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
39  ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
40  OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ADL Co-Lab Hub AND ITS LICENSORS
41  SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
42  USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO
43  EVENT WILL ADL Co-Lab Hub OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
44  PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
45  INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
46  THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
47  SOFTWARE, EVEN IF ADL Co-Lab Hub HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
48  DAMAGES.
49 */
50 
51  require_once("SeqActivity.php");
52 
53  require_once("SeqRule.php");
54  require_once("SeqRuleset.php");
55 
56  require_once("SeqCondition.php");
57  require_once("SeqConditionSet.php");
58 
59  require_once("SeqObjective.php");
60  require_once("SeqObjectiveMap.php");
61 
62  require_once("SeqRollupRule.php");
63  require_once("SeqRollupRuleset.php");
64 
65  require_once("ADLAuxiliaryResource.php");
66 
68 
69  public function buildNodeSeqTree($file){
70 
71  $doc = new DomDocument();
72  $doc->load($file);
73  $organizations = $doc->getElementsByTagName("organizations");
74 
75  //lookup default organization id
76  $default=$organizations->item(0)->getAttribute("default");
77 
78  //get all organization nodes
79  $organization = $doc->getElementsByTagName("organization");
80 
81  //lookup the default organization
82  foreach ($organization as $element) {
83  if ($element->getAttribute("identifier")==$default) {
84  $default_organization = $element;
85  }
86  }
87 
88  //read seqCollection
89  $seqCollection = $doc->getElementsByTagName("sequencingCollection")->item(0);
90 
91  $root = $this->buildNode($default_organization,$seqCollection,$doc);
92 
93  //return no data please check
94  $objectivesGlobalToSystem = $default_organization->getAttributeNS("http://www.adlnet.org/xsd/adlseq_v1p3","objectivesGlobalToSystem");
95 
96  $org = $default_organization->getAttribute("identifier");
97 
98  //default true
99  $globaltosystem = 1;
100 
101  if ($objectivesGlobalToSystem=="false") {
102  $globaltosystem = 0;
103  }
104 
105  //assign SeqActivity to top node
106  $c_root['_SeqActivity']=$root;
107 
108  $ret['global'] = $globaltosystem;
109  $ret['tree'] = $c_root;
110 
111  return $ret;
112 
113  }
114 
115 
116 
117  private function buildNode($node,$seq,$doc) {
118 
119  //create a new activity object
120  $act = new SeqActivity();
121 
122 
123  //set various attributes, if existent
124  $act->setID($node->getAttribute("identifier"));
125 
126  $tempVal = $node->getAttribute("identifierref");
127  if ($tempVal){
128  $act->setResourceID($tempVal);
129  }
130 
131  $tempVal = $node->getAttribute("isvisible");
132 
133 
134  if ($tempVal){
135  $act->setIsVisible(self::convert_to_bool($tempVal));
136  }
137 
138 
139  //Proceed nested items
140  $children = $node->childNodes;
141 
142  for ($i = 0; $i < $children->length; $i++ ) {
143 
144  $curNode=$children->item($i);
145  //elements only
146 
147  if ($curNode->nodeType == XML_ELEMENT_NODE) {
148  //only items are nested
149  if ($curNode->localName == "item") {
150  //init;
151  $c_nestedAct=null;
152  $nestedAct = new SeqActivity();
153  $nestedAct = $this->buildNode($curNode,$seq,$doc);
154  if ($nestedAct != null ) {
155  $act->AddChild($nestedAct);
156  }
157  }
158  else if ($curNode->localName == "title") {
159  $act->setTitle($this->lookupElement($curNode,null));
160  }
161  else if ($curNode->localName == "sequencing") {
162  $seqInfo = $curNode;
163  //get IDRef
164  $tempVal = $curNode->getAttribute("IDRef");
165  //only execute for referenced sequencing parts
166  if ($tempVal) {
167  //init seqGlobal
168  $seqGlobal = null;
169 
170  //get all sequencing nodes in collections
171  $sequencing = $seq->getElementsByTagName("sequencing");
172 
173  //lookup the matching sequencing element
174  foreach ($sequencing as $element) {
175  if ($element->getAttribute("ID")==$tempVal) {
176  $seqGlobal = $element;
177  }
178  }
179 
180  //clone the global node
181  $seqInfo = $seqGlobal->cloneNode(TRUE);
182 
183  //back to the local node
184  $seqChildren = $curNode->childNodes;
185  for ($j = 0; $j < $seqChildren->length; $j++ ) {
186  //process local nodes
187  $curChild = $seqChildren->item($j);
188  if ( $curChild->nodeType == XML_ELEMENT_NODE ) {
189  //echo "\nFound Sequencing Element Node".$curChild->localName;
190  //add local to global sequencing info
191  $seqInfo->appendChild($curChild);
192 
193  }
194  }
195  }
196  //extract the sequencing info, if we have one
197  //avoid working with
198  $act=$this->extractSeqInfo($seqInfo, $act);
199 
200  }
201  }
202 
203 
204 
205  $item=$children->item($i)->nodeValue;
206  }
207  //add class
208  //$c_act['_SeqActivity']=$act;
209  return $act;
210 
211  }
212 
213 
214  private function extractSeqInfo($iNode, $ioAct) {
215  //set sequencing information
216  $children = $iNode->childNodes;
217  for ( $i = 0; $i < $children->length; $i++ ) {
218  $curNode = $children->item($i);
219  if ( $curNode->nodeType == XML_ELEMENT_NODE ) {
220  if ($curNode->localName == "controlMode") {
221  //look for choice
222  $tempVal=$curNode->getAttribute("choice");
223  if ($tempVal) {
224  $ioAct->setControlModeChoice(self::convert_to_bool($tempVal));
225  }
226  //look for choiceExit
227  $tempVal=$curNode->getAttribute("choiceExit");
228  if ($tempVal) {
229  $ioAct->setControlModeChoiceExit(self::convert_to_bool($tempVal));
230  }
231 
232  //look for flow
233  $tempVal=$curNode->getAttribute("flow");
234  if ($tempVal) {
235  $ioAct->setControlModeFlow(self::convert_to_bool($tempVal));
236  }
237 
238  // Look for 'forwardOnly'
239  $tempVal=$curNode->getAttribute("forwardOnly");
240  if ($tempVal) {
241  $ioAct->setControlForwardOnly(self::convert_to_bool($tempVal));
242  }
243 
244  // Look for 'useCurrentAttemptObjectiveInfo'
245  $tempVal=$curNode->getAttribute("useCurrentAttemptObjectiveInfo");
246  if ($tempVal) {
247  $ioAct->setUseCurObjective(self::convert_to_bool($tempVal));
248  }
249 
250  // Look for 'useCurrentAttemptProgressInfo'
251  $tempVal=$curNode->getAttribute("useCurrentAttemptProgressInfo");
252  if ($tempVal) {
253  $ioAct->setUseCurProgress(self::convert_to_bool($tempVal));
254  }
255 
256  }
257 
258  else if ($curNode->localName == "sequencingRules") {
259  $ioAct = $this->getSequencingRules($curNode,$ioAct);
260 
261  }
262 
263  else if ($curNode->localName == "limitConditions") {
264  // Look for 'useCurrentAttemptObjectiveInfo'
265  $tempVal=$curNode->getAttribute("attemptLimit");
266  if ($tempVal) {
267  $ioAct->setAttemptLimit($tempVal);
268  }
269 
270  // Look for 'attemptAbsoluteDurationLimit'
271  $tempVal=$curNode->getAttribute("attemptAbsoluteDurationLimit");
272  if ($tempVal) {
273  $ioAct->setAttemptAbDur($tempVal);
274  }
275 
276  // Look for 'attemptExperiencedDurationLimit'
277  $tempVal=$curNode->getAttribute("attemptExperiencedDurationLimit");
278  if ($tempVal) {
279  $ioAct->setAttemptExDur($tempVal);
280  }
281 
282  // Look for 'activityAbsoluteDurationLimit'
283  $tempVal=$curNode->getAttribute("activityAbsoluteDurationLimit");
284  if ($tempVal) {
285  $ioAct->setActivityAbDur($tempVal);
286  }
287 
288  // Look for 'activityExperiencedDurationLimit'
289  $tempVal=$curNode->getAttribute("activityExperiencedDurationLimit");
290  if ($tempVal) {
291  $ioAct->setActivityExDur($tempVal);
292  }
293 
294  // Look for 'beginTimeLimit'
295  $tempVal=$curNode->getAttribute("beginTimeLimit");
296  if ($tempVal) {
297  $ioAct->setBeginTimeLimit($tempVal);
298  }
299 
300  // Look for 'endTimeLimit'
301  $tempVal=$curNode->getAttribute("endTimeLimit");
302  if ($tempVal) {
303  $ioAct->setEndTimeLimit($tempVal);
304  }
305  }
306  else if ($curNode->localName == "auxiliaryResources") {
307  $ioAct = self::getAuxResources($curNode, $ioAct);
308  }
309 
310  else if ($curNode->localName == "rollupRules") {
311  $ioAct = self::getRollupRules($curNode, $ioAct);
312  }
313 
314  else if ($curNode->localName == "objectives") {
315  $ioAct = self::getObjectives($curNode,$ioAct);
316  }
317 
318  else if ($curNode->localName == "randomizationControls") {
319 
320  // Look for 'randomizationTiming'
321  $tempVal=$curNode->getAttribute("randomizationTiming");
322  if ($tempVal) {
323  $ioAct->setRandomTiming($tempVal);
324  }
325 
326  // Look for 'selectCount'
327  $tempVal=$curNode->getAttribute("selectCount");
328  if ($tempVal) {
329  $ioAct->setSelectCount($tempVal);
330  }
331 
332  // Look for 'reorderChildren'
333  $tempVal=$curNode->getAttribute("reorderChildren");
334  if ($tempVal) {
335  $ioAct->setReorderChildren(self::convert_to_bool($tempVal));
336  }
337 
338  // Look for 'selectionTiming'
339  $tempVal=$curNode->getAttribute("selectionTiming");
340  if ($tempVal) {
341  $ioAct->setSelectionTiming($tempVal);
342  }
343  }
344  else if ($curNode->localName == "deliveryControls") {
345 
346  // Look for 'tracked'
347  $tempVal=$curNode->getAttribute("tracked");
348  if ($tempVal) {
349  $ioAct->setIsTracked(self::convert_to_bool($tempVal));
350  }
351 
352  // Look for 'completionSetByContent'
353  $tempVal=$curNode->getAttribute("completionSetByContent");
354  if ($tempVal) {
355  $ioAct->setSetCompletion(self::convert_to_bool($tempVal));
356  }
357 
358  // Look for 'objectiveSetByContent'
359  $tempVal=$curNode->getAttribute("objectiveSetByContent");
360  if ($tempVal) {
361  $ioAct->setSetObjective(self::convert_to_bool($tempVal));
362  }
363  }
364  else if ($curNode->localName == "constrainedChoiceConsiderations") {
365 
366  // Look for 'preventActivation'
367  $tempVal=$curNode->getAttribute("preventActivation");
368  if ($tempVal) {
369  $ioAct->setPreventActivation(self::convert_to_bool($tempVal));
370  }
371 
372  // Look for 'constrainChoice'
373  $tempVal=$curNode->getAttribute("constrainChoice");
374  if ($tempVal) {
375  $ioAct->setConstrainChoice(self::convert_to_bool($tempVal));
376  }
377  }
378  else if ($curNode->localName == "rollupConsiderations") {
379 
380  // Look for 'requiredForSatisfied'
381  $tempVal=$curNode->getAttribute("requiredForSatisfied");
382  if ($tempVal) {
383  $ioAct->setRequiredForSatisfied($tempVal);
384  }
385 
386  // Look for 'requiredForNotSatisfied'
387  $tempVal=$curNode->getAttribute("requiredForNotSatisfied");
388  if ($tempVal) {
389  $ioAct->setRequiredForNotSatisfied($tempVal);
390  }
391 
392  // Look for 'requiredForCompleted'
393  $tempVal=$curNode->getAttribute("requiredForCompleted");
394  if ($tempVal) {
395  $ioAct->setRequiredForCompleted($tempVal);
396  }
397 
398  // Look for 'requiredForIncomplete'
399  $tempVal=$curNode->getAttribute("requiredForIncomplete");
400  if ($tempVal) {
401  $ioAct->setRequiredForIncomplete($tempVal);
402  }
403 
404  // Look for 'measureSatisfactionIfActive'
405  $tempVal=$curNode->getAttribute("measureSatisfactionIfActive");
406  if ($tempVal) {
407  $ioAct->setSatisfactionIfActive(self::convert_to_bool($tempVal));
408  }
409  }
410 
411 
412 
413  } //end note-type check
414 
415  } //end for-loop
416 
417  return $ioAct;
418  }
419 
420 
421  public static function getObjectives ($iNode,$ioAct) {
422  $ok = true;
423  $tempVal = null;
424  $objectives = array();
425  $children = $iNode->childNodes;
426  for ($i = 0; $i < $children->length; $i++ ) {
427  $curNode=$children->item($i);
428  if ($curNode->nodeType == XML_ELEMENT_NODE) {
429  if ($curNode->localName == "primaryObjective" || $curNode->localName == "objective" ) {
430 
431  $obj = new SeqObjective();
432  if ($curNode->localName == "primaryObjective") {
433  $obj->mContributesToRollup = true;
434  }
435 
436  // Look for 'objectiveID'
437  $tempVal = $curNode->getAttribute("objectiveID");
438  if($tempVal) {
439  $obj->mObjID = $tempVal;
440  }
441 
442  // Look for 'satisfiedByMeasure'
443  $tempVal = $curNode->getAttribute("satisfiedByMeasure");
444  if($tempVal) {
445  $obj->mSatisfiedByMeasure = self::convert_to_bool($tempVal);
446  }
447  // Look for 'minNormalizedMeasure'
448  $tempVal=self::lookupElement($curNode,"minNormalizedMeasure");
449  if($tempVal) {
450  $obj->mMinMeasure = $tempVal;
451  }
452 
453  //get ObjectiveMaps
454  $maps = self::getObjectiveMaps($curNode);
455  if ( $maps != null ){
456  $obj->mMaps = $maps;
457  }
458  //$obj->mContributesToRollup = true;
459  //add class
460  $c_obj['_SeqObjective'] = $obj;
461  array_push($objectives,$c_obj);
462  }
463  }
464  }
465  $ioAct->setObjectives($objectives);
466  return $ioAct;
467  }
468 
469 
470  public static function getObjectiveMaps($iNode) {
471  $tempVal = null;
472  $maps = array();
473  $children = $iNode->childNodes;
474  for ($i = 0; $i < $children->length; $i++ ) {
475  $curNode=$children->item($i);
476  if ($curNode->nodeType == XML_ELEMENT_NODE) {
477  if ($curNode->localName == "mapInfo") {
478  $map = new SeqObjectiveMap();
479 
480  // Look for 'targetObjectiveID'
481  $tempVal = $curNode->getAttribute("targetObjectiveID");
482  if($tempVal) {
483  $map->mGlobalObjID = $tempVal;
484  }
485 
486  // Look for 'readSatisfiedStatus'
487  $tempVal = $curNode->getAttribute("readSatisfiedStatus");
488  if($tempVal) {
489  $map->mReadStatus = self::convert_to_bool($tempVal);
490  }
491 
492  // Look for 'readNormalizedMeasure'
493  $tempVal = $curNode->getAttribute("readNormalizedMeasure");
494  if($tempVal) {
495  $map->mReadMeasure = self::convert_to_bool($tempVal);
496  }
497 
498  // Look for 'writeSatisfiedStatus'
499  $tempVal = $curNode->getAttribute("writeSatisfiedStatus");
500  if($tempVal) {
501  $map->mWriteStatus = self::convert_to_bool($tempVal);
502  }
503 
504  // Look for 'writeNormalizedMeasure'
505  $tempVal = $curNode->getAttribute("writeNormalizedMeasure");
506  if($tempVal) {
507  $map->mWriteMeasure = self::convert_to_bool($tempVal);
508  }
509  //add class
510  $c_map['_SeqObjectiveMap']=$map;
511  array_push($maps,$c_map);
512  }
513  }
514  }
515  if (count($maps)==null) {
516  $maps = null;
517  }
518  return $maps;
519  }
520 
521  public static function getRollupRules($iNode, $ioAct) {
522  $ok = true;
523  $tempVal = null;
524  $rollupRules = array();
525 
526  // Look for 'rollupObjectiveSatisfied'
527  $tempVal = $iNode->getAttribute("rollupObjectiveSatisfied");
528  if($tempVal) {
529  $ioAct->setIsObjRolledUp(self::convert_to_bool($tempVal));
530  }
531 
532  // Look for 'objectiveMeasureWeight'
533  $tempVal = $iNode->getAttribute("objectiveMeasureWeight");
534  if($tempVal) {
535  $ioAct->setObjMeasureWeight($tempVal);
536 
537  }
538  // Look for 'rollupProgressCompletion'
539  $tempVal = $iNode->getAttribute("rollupProgressCompletion");
540  if($tempVal) {
541  $ioAct->setIsProgressRolledUp(self::convert_to_bool($tempVal));
542 
543  }
544  $children = $iNode->childNodes;
545  for ($i = 0; $i < $children->length; $i++ ) {
546  $curNode=$children->item($i);
547  if ($curNode->nodeType == XML_ELEMENT_NODE) {
548  if ($curNode->localName == "rollupRule") {
549  $rule = new SeqRollupRule();
550 
551  // Look for 'childActivitySet'
552  $tempVal=$curNode->getAttribute("childActivitySet");
553  if($tempVal) {
554  $rule->mChildActivitySet = $tempVal;
555  }
556  // Look for 'minimumCount'
557  $tempVal=$curNode->getAttribute("minimumCount");
558  if($tempVal) {
559  $rule->mMinCount = $tempVal;
560  }
561 
562  // Look for 'minimumPercent'
563  $tempVal=$curNode->getAttribute("minimumPercent");
564  if($tempVal) {
565  $rule->mMinPercent = $tempVal;
566  }
567  $rule->mConditions['_SeqConditionSet'] = new SeqConditionSet(true);
568  $conditions = array();
569  $ruleInfo = $curNode->childNodes;
570  for ($j = 0; $j < $ruleInfo->length; $j++ ) {
571  $curRule=$ruleInfo->item($j);
572  //check for element
573  if ($curRule->nodeType == XML_ELEMENT_NODE) {
574  if ($curRule->localName == "rollupConditions") {
575  $tempVal = $curRule->getAttribute("conditionCombination");
576  if($tempVal) {
577  $rule->mConditions['_SeqConditionSet']->mCombination = $tempVal;
578  } else {
579  $rule->mConditions['_SeqConditionSet']->mCombination = COMBINATION_ANY;
580  }
581  $conds = $curRule->childNodes;
582  for ($k = 0; $k < $conds->length; $k++ ) {
583  $con=$conds->item($k);
584  if ($con->nodeType == XML_ELEMENT_NODE) {
585  if ($con->localName == "rollupCondition") {
586  $cond = new SeqCondition();
587  // Look for 'condition'
588  $tempVal = $con->getAttribute("condition");
589  if($tempVal) {
590  $cond->mCondition=$tempVal;
591  }
592  // Look for 'operator'
593  $tempVal = $con->getAttribute("operator");
594  if($tempVal) {
595  if($tempVal=='not') {$cond->mNot = true;} else {$cond->mNot = false;}
596  }
597  //add class
598  $c_cond['_SeqCondition'] = $cond;
599  array_push($conditions,$c_cond);
600  }
601 
602  }
603  }
604  }
605  else if ($curRule->localName == "rollupAction") {
606  $tempVal = $curRule->getAttribute("action");
607  if ($tempVal) {
608  $rule->setRollupAction($tempVal);
609  }
610 
611  }
612 
613  }
614  }
615  // Add the conditions to the condition set for the rule
616  $rule->mConditions['_SeqConditionSet']->mConditions = $conditions;
617 
618  // Add the rule to the ruleset
619  //add class
620  $c_rule['_SeqRollupRule']=$rule;
621  array_push($rollupRules,$c_rule);
622  }
623  }
624  }
625 
626  if ( $rollupRules != null ) {
627  $rules = new SeqRollupRuleset($rollupRules);
628  // Set the Activity's rollup rules
629  //add class
630  $c_rules['_SeqRollupRuleset']=$rules;
631  $ioAct->setRollupRules($c_rules);
632  }
633 
634  return $ioAct;
635  }
636 
637 
638  public static function getSequencingRules($iNode,$ioAct) {
639  //local variables
640  $ok = true;
641  $tempVal = null;
642 
643  $preRules = array();
644  $exitRules = array();
645  $postRules = array();
646 
647  //get children
648  $children = $iNode->childNodes;
649 
650  //find sequencing rules
651  for ($i = 0; $i < $children->length; $i++ ) {
652  $curNode=$children->item($i);
653  if ($curNode->nodeType == XML_ELEMENT_NODE) {
654  if ($curNode->localName == "preConditionRule" || $curNode->localName == "exitConditionRule" || $curNode->localName == "postConditionRule" ) {
655  $rule = new SeqRule();
656  $ruleInfo = $curNode->childNodes;
657  for ($j = 0; $j < $ruleInfo->length; $j++ ){
658  $curRule=$ruleInfo->item($j);
659  //echo "$curRule->localName\n";
660  if ($curRule->nodeType == XML_ELEMENT_NODE) {
661  if ($curRule->localName == "ruleConditions") {
662  $rule->mConditions = self::extractSeqRuleConditions($curRule);
663  }
664  else if($curRule->localName == "ruleAction"){
665  $tempVal=$curRule->getAttribute("action");
666  if($tempVal) {
667  $rule->mAction = $tempVal;
668  }
669  }
670 
671  }
672  }//end for inner
673  if ( $rule->mConditions != null && $rule->mAction != null ) {
674  //changed from ADL Code..
675  if ($curNode->localName == "preConditionRule") {
676  //echo "ADD PRE";
677  //add class
678  $c_rule['_SeqRule'] = $rule;
679  array_push($preRules,$c_rule);
680  }
681  if ($curNode->localName == "exitConditionRule") {
682  //echo "ADD EXIT";
683  //add class
684  $c_rule['_SeqRule'] = $rule;
685  array_push($exitRules,$c_rule);
686  }
687  if ($curNode->localName == "postConditionRule") {
688  //echo "ADD POST";
689  //add class
690  $c_rule['_SeqRule'] = $rule;
691  array_push($postRules,$c_rule);
692  }
693  }
694  } //end if preCondition
695 
696  } //end if ELEMENT
697  }
698 
699  if ( count($preRules) > 0 ) {
700  $rules = new SeqRuleset($preRules);
701  //add class
702  $c_rules['_SeqRuleset']=$rules;
703  $ioAct->setPreSeqRules($c_rules);
704 
705  }
706 
707  if ( count($exitRules) > 0 ){
708  $rules = new SeqRuleset($exitRules);
709  //add class
710  $c_rules['_SeqRuleset']=$rules;
711  $ioAct->setExitSeqRules($c_rules);
712  }
713  if ( count($postRules) > 0 ){
714  $rules = new SeqRuleset($postRules);
715  //add class
716  $c_rules['_SeqRuleset']=$rules;
717  $ioAct->setPostSeqRules($c_rules);
718  }
719  //echo json_encode($ioAct);
720 
721  return $ioAct;
722 
723  }
724 
725  public static function extractSeqRuleConditions($iNode) {
726  $tempVal = null;
727  $condSet = new SeqConditionSet(false);
728 
729  $conditions = array();
730  $tempVal=$iNode->getAttribute("conditionCombination");
731  if ($tempVal) {
732  $condSet->mCombination=$tempVal;
733  } else {
734  $condSet->mCombination=COMBINATION_ALL;
735  }
736  $condInfo = $iNode->childNodes;
737  for ($i = 0; $i < $condInfo->length; $i++ ) {
738  $curCond=$condInfo->item($i);
739  if ($curCond->nodeType == XML_ELEMENT_NODE) {
740  if ($curCond->localName == "ruleCondition") {
741  $cond = new SeqCondition();
742 
743  //look for condition
744  $tempVal=$curCond->getAttribute("condition");
745  if ($tempVal) {
746  $cond->mCondition = $tempVal;
747  }
748 
749  // Look for 'referencedObjective'
750  $tempVal=$curCond->getAttribute("referencedObjective");
751  if ($tempVal) {
752  $cond->mObjID = $tempVal;
753  }
754 
755  // Look for 'measureThreshold'
756  $tempVal=$curCond->getAttribute("measureThreshold");
757  if ($tempVal) {
758  $cond->mThreshold = $tempVal;
759  }
760 
761  // Look for 'operator'
762  $tempVal = $curCond->getAttribute("operator");
763  if ($tempVal) {
764  if ($tempVal == 'not') {
765  $cond->mNot = true;
766  } else {
767  $cond->mNot = false;
768  }
769  }
770 
771  //add class
772  $c_cond['_SeqCondition']=$cond;
773  array_push($conditions,$c_cond);
774 
775  }
776  }
777  }
778 
779  if (count($conditions)>0) {
780  $condSet->mConditions = $conditions;
781  } else {
782  $condSet->mConditions = null;
783  }
784  //add class
785  $c_condSet['_SeqConditionSet']=$condSet;
786  return $c_condSet;
787  }
788 
789  public static function getAuxResources($iNode, $ioAct) {
790  $ok = true;
791  $tempVal = null;
792  $auxRes = array();
793  //get children
794  $children = $iNode->childNodes;
795 
796  //find ressources
797  for ($i = 0; $i < $children->length; $i++ ) {
798  $curNode=$children->item($i);
799  if ($curNode->nodeType == XML_ELEMENT_NODE) {
800  if ($curNode->localName == "auxiliaryResource") {
801  //found it
802  $res = new ADLAuxiliaryResource();
803 
804  // Get the resource's purpose
805  $tempVal=$curNode->getAttribute("purpose");
806  if ($tempVal) {
807  $res->mType = $tempVal;
808  }
809  // Get the resource's ID
810  $tempVal=$curNode->getAttribute("auxiliaryResourceID");
811  if ($tempVal) {
812  $res->mResourceID = $tempVal;
813  }
814  array_push($auxRes,$res);
815  }
816  }
817  }
818  //add class
819  $c_auxRes['_ADLAuxiliaryResource']=$auxRes;
820  $ioAct->setAuxResources($c_auxRes);
821  return $ioAct;
822  }
823 
824  //helper functions
825 
826  private static function convert_to_bool($string) {
827  if (strtoupper($string)=="FALSE") {
828  return false;
829  } else {
830  return true;
831  }
832  }
833 
834 
835  private function lookupElement($iNode, $iElement){
836  $value = null;
837  $curNode = null;
838  $children = null;
839 
840  if ( $iNode != null && $iElement != null ){
841  $children = $iNode->childNodes;
842  for ($i = 0; $i < $children->length; $i++ ) {
843  $curNode = $children->item($i);
844  if ( ($curNode->nodeType == XML_ELEMENT_NODE)) {
845  if ($curNode->localName == $iElement) {
846  break;
847  }
848  }
849 
850  }
851  if ($curNode != null ) {
852  $comp = $curNode->localName;
853  if ($comp != null) {
854  if ($comp != $iElement) {
855  $curNode = null;
856  }
857  } else {
858  $curNode = null;
859 
860  }
861  }
862 
863  }
864  else {
865  //$iElement is null
866  $curNode = $iNode;
867  }
868 
869  if ( $curNode != null )
870  {
871  $children = $curNode->childNodes;
872  if ( $children != null ) {
873  for ($i = 0; $i < $children->length; $i++ ) {
874  $curNode = $children->item($i);
875  // make sure we have a 'text' element
876  if ( ($curNode->nodeType == XML_TEXT_NODE) ||($curNode->nodeType == XML_CDATA_SECTION_NODE) )
877  {
878  $value = $value.$curNode->nodeValue;
879  }
880  }
881  }
882  }
883  return $value;
884  }
885 
886 
887 } //end class
888 
889 ?>