• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Scorm2004/classes/adlparser/SeqTreeBuilder.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2007 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 /*
00024         PHP port of several ADL-sources
00025         @author Hendrik Holtmann <holtmann@mac.com>
00026         
00027         This .php file is GPL licensed (see above) but based on
00028         Sourcecode by ADL Co-Lab, which is licensed as:
00029         
00030         Advanced Distributed Learning Co-Laboratory (ADL Co-Lab) Hub grants you 
00031         ("Licensee") a non-exclusive, royalty free, license to use, modify and 
00032         redistribute this software in source and binary code form, provided that 
00033         i) this copyright notice and license appear on all copies of the software; 
00034         and ii) Licensee does not utilize the software in a manner which is 
00035         disparaging to ADL Co-Lab Hub.
00036 
00037         This software is provided "AS IS," without a warranty of any kind.  ALL 
00038         EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING 
00039         ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
00040         OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.  ADL Co-Lab Hub AND ITS LICENSORS 
00041         SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
00042         USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES.  IN NO 
00043         EVENT WILL ADL Co-Lab Hub OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, 
00044         PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, 
00045         INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE 
00046         THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE 
00047         SOFTWARE, EVEN IF ADL Co-Lab Hub HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
00048         DAMAGES.
00049 */
00050 
00051         require_once("SeqActivity.php");
00052         
00053         require_once("SeqRule.php");
00054         require_once("SeqRuleset.php");
00055         
00056         require_once("SeqCondition.php");
00057         require_once("SeqConditionSet.php");
00058         
00059         require_once("SeqObjective.php");
00060         require_once("SeqObjectiveMap.php");
00061         
00062         require_once("SeqRollupRule.php");
00063         require_once("SeqRollupRuleset.php");
00064         
00065         require_once("ADLAuxiliaryResource.php");
00066 
00067         class SeqTreeBuilder{
00068 
00069           public function buildNodeSeqTree($file){
00070                 
00071                 $doc = new DomDocument();
00072                 $doc->load($file);
00073                 $organizations = $doc->getElementsByTagName("organizations");
00074                 
00075                 //lookup default organization id
00076                 $default=$organizations->item(0)->getAttribute("default");
00077                 
00078                 //get all organization nodes
00079                 $organization = $doc->getElementsByTagName("organization");
00080                 
00081                 //lookup the default organization
00082                 foreach ($organization as $element) {
00083                         if ($element->getAttribute("identifier")==$default) {
00084                                 $default_organization = $element;
00085                         }
00086                 }
00087                 
00088                 //read seqCollection
00089                 $seqCollection = $doc->getElementsByTagName("sequencingCollection")->item(0);
00090                 
00091                 $root = $this->buildNode($default_organization,$seqCollection,$doc);
00092                 
00093                 //return no data please check
00094                 $objectivesGlobalToSystem = $default_organization->getAttributeNS("http://www.adlnet.org/xsd/adlseq_v1p3","objectivesGlobalToSystem");
00095         
00096                 $org = $default_organization->getAttribute("identifier");
00097                 
00098                 //default true
00099                 $globaltosystem = 1;
00100                 
00101                 if ($objectivesGlobalToSystem=="false") {
00102                         $globaltosystem = 0;
00103                 }
00104                                 
00105                 //assign SeqActivity to top node
00106                 $c_root['_SeqActivity']=$root;
00107                                 
00108                 $ret['global'] = $globaltosystem;
00109                 $ret['tree'] = $c_root;
00110                 
00111                 return $ret;
00112                 
00113           }
00114           
00115           
00116           
00117           private function buildNode($node,$seq,$doc) {
00118                 
00119                 //create a new activity object
00120                 $act = new SeqActivity();
00121                 
00122                 
00123                 //set various attributes, if existent
00124                 $act->setID($node->getAttribute("identifier"));
00125                 
00126                 $tempVal = $node->getAttribute("identifierref");
00127                 if ($tempVal){
00128                         $act->setResourceID($tempVal);
00129                 }
00130                 
00131                 $tempVal = $node->getAttribute("isvisible");
00132           
00133                 
00134                 if ($tempVal){
00135                                 $act->setIsVisible(self::convert_to_bool($tempVal));
00136                 }
00137             
00138                 
00139                 //Proceed nested items
00140                 $children = $node->childNodes;
00141                 
00142                  for ($i = 0; $i < $children->length; $i++ ) {
00143                         
00144                         $curNode=$children->item($i);
00145                         //elements only
00146                         
00147                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00148                                 //only items are nested
00149                                 if ($curNode->localName == "item") {
00150                                         //init;
00151                                         $c_nestedAct=null;
00152                                         $nestedAct = new SeqActivity();
00153                                         $nestedAct = $this->buildNode($curNode,$seq,$doc);
00154                                         if ($nestedAct != null ) {
00155                                                 $act->AddChild($nestedAct);
00156                         }
00157                                 }
00158                                 else if ($curNode->localName == "title") {
00159                                          $act->setTitle($this->lookupElement($curNode,null));
00160                                 }
00161                                 else if ($curNode->localName == "sequencing") {
00162                                         $seqInfo = $curNode;
00163                                         //get IDRef
00164                                         $tempVal = $curNode->getAttribute("IDRef");
00165                                         //only execute for referenced sequencing parts
00166                                         if ($tempVal) {
00167                                                 //init seqGlobal
00168                                                 $seqGlobal = null;
00169                                                 
00170                                                 //get all sequencing nodes in collections
00171                                                 $sequencing = $seq->getElementsByTagName("sequencing");
00172           
00173                                                 //lookup the matching sequencing element
00174                                                 foreach ($sequencing as $element) {
00175                                                         if ($element->getAttribute("ID")==$tempVal) {
00176                                                                 $seqGlobal = $element;
00177                                                         }
00178                                                 }
00179                                                 
00180                                                 //clone the global node
00181                                                 $seqInfo = $seqGlobal->cloneNode(TRUE);
00182                                                 
00183                                                 //back to the local node
00184                                                 $seqChildren = $curNode->childNodes;
00185                                 for ($j = 0; $j < $seqChildren->length; $j++ ) {
00186                                                         //process local nodes
00187                                                         $curChild = $seqChildren->item($j);
00188                                 if ( $curChild->nodeType == XML_ELEMENT_NODE ) {
00189                                                                 //echo "\nFound Sequencing Element Node".$curChild->localName;
00190                                                                 //add local to global sequencing info
00191                                                                 $seqInfo->appendChild($curChild);
00192                                     
00193                                   }
00194                                                 }
00195                          }      
00196                                         //extract the sequencing info, if we have one
00197                                         //avoid working with 
00198                                         $act=$this->extractSeqInfo($seqInfo, $act);
00199                                         
00200                                 }
00201                         }
00202                         
00203                 
00204                  
00205                         $item=$children->item($i)->nodeValue;
00206                 }
00207                 //add class
00208                 //$c_act['_SeqActivity']=$act;
00209                 return $act;
00210           
00211           }
00212           
00213           
00214           private function extractSeqInfo($iNode, $ioAct) {
00215                 //set sequencing information
00216                 $children = $iNode->childNodes;
00217                 for ( $i = 0; $i < $children->length; $i++ ) {
00218                         $curNode = $children->item($i);
00219                 if ( $curNode->nodeType == XML_ELEMENT_NODE ) {
00220                                 if ($curNode->localName == "controlMode") {
00221                                         //look for choice
00222                                         $tempVal=$curNode->getAttribute("choice");
00223                                         if ($tempVal) {
00224                                                 $ioAct->setControlModeChoice(self::convert_to_bool($tempVal));
00225                                         }
00226                                         //look for choiceExit
00227                                         $tempVal=$curNode->getAttribute("choiceExit");
00228                                         if ($tempVal) {
00229                                                 $ioAct->setControlModeChoiceExit(self::convert_to_bool($tempVal));
00230                                         }
00231                                         
00232                                         //look for flow
00233                                         $tempVal=$curNode->getAttribute("flow");
00234                                         if ($tempVal) {
00235                                                 $ioAct->setControlModeFlow(self::convert_to_bool($tempVal));
00236                                         }
00237                                         
00238                                         // Look for 'forwardOnly'
00239                         $tempVal=$curNode->getAttribute("forwardOnly");
00240                                         if ($tempVal) {
00241                                                 $ioAct->setControlForwardOnly(self::convert_to_bool($tempVal));
00242                                         }
00243                                         
00244                                         // Look for 'useCurrentAttemptObjectiveInfo'
00245                             $tempVal=$curNode->getAttribute("useCurrentAttemptObjectiveInfo");
00246                                         if ($tempVal) {
00247                                                 $ioAct->setUseCurObjective(self::convert_to_bool($tempVal));
00248                                         }
00249                                         
00250                                         // Look for 'useCurrentAttemptProgressInfo'
00251                                 $tempVal=$curNode->getAttribute("useCurrentAttemptProgressInfo");
00252                                         if ($tempVal) {
00253                                                 $ioAct->setUseCurProgress(self::convert_to_bool($tempVal));
00254                                         }
00255                                         
00256                                 }
00257                                 
00258                                 else if ($curNode->localName == "sequencingRules") {
00259                                         $ioAct = $this->getSequencingRules($curNode,$ioAct);
00260                                         
00261                                 }
00262                                 
00263                                 else if ($curNode->localName == "limitConditions") {
00264                                         // Look for 'useCurrentAttemptObjectiveInfo'
00265                                         $tempVal=$curNode->getAttribute("attemptLimit");
00266                                         if ($tempVal) {
00267                                                 $ioAct->setAttemptLimit($tempVal);
00268                                         }
00269                                 
00270                                         // Look for 'attemptAbsoluteDurationLimit'
00271                         $tempVal=$curNode->getAttribute("attemptAbsoluteDurationLimit");
00272                                         if ($tempVal) {
00273                                                 $ioAct->setAttemptAbDur($tempVal);
00274                                         }
00275                         
00276                                // Look for 'attemptExperiencedDurationLimit'
00277                                 $tempVal=$curNode->getAttribute("attemptExperiencedDurationLimit");
00278                                         if ($tempVal) {
00279                                         $ioAct->setAttemptExDur($tempVal);
00280                                         }
00281         
00282                        // Look for 'activityAbsoluteDurationLimit'
00283                                 $tempVal=$curNode->getAttribute("activityAbsoluteDurationLimit");
00284                                         if ($tempVal) {
00285                                                 $ioAct->setActivityAbDur($tempVal);
00286                                         }
00287                                    
00288                                         // Look for 'activityExperiencedDurationLimit'
00289                                         $tempVal=$curNode->getAttribute("activityExperiencedDurationLimit");
00290                                         if ($tempVal) {
00291                                         $ioAct->setActivityExDur($tempVal);
00292                                         }
00293                         
00294                        // Look for 'beginTimeLimit'
00295                                         $tempVal=$curNode->getAttribute("beginTimeLimit");
00296                                         if ($tempVal) {
00297                                                 $ioAct->setBeginTimeLimit($tempVal);
00298                                         }
00299                                         
00300                                         // Look for 'endTimeLimit'
00301                         $tempVal=$curNode->getAttribute("endTimeLimit");
00302                                         if ($tempVal) {
00303                                                 $ioAct->setEndTimeLimit($tempVal);
00304                                         }
00305                                 }
00306                                 else if ($curNode->localName == "auxiliaryResources") {
00307                                         $ioAct = self::getAuxResources($curNode, $ioAct);
00308                                 }
00309                                 
00310                                 else if ($curNode->localName == "rollupRules") {
00311                                         $ioAct = self::getRollupRules($curNode, $ioAct);
00312                                 }
00313                                 
00314                                 else if ($curNode->localName == "objectives") {
00315                                         $ioAct = self::getObjectives($curNode,$ioAct);
00316                                 }
00317                                 
00318                                 else if ($curNode->localName == "randomizationControls") {
00319                                         
00320                                         // Look for 'randomizationTiming'
00321                         $tempVal=$curNode->getAttribute("randomizationTiming");
00322                                         if ($tempVal) {
00323                                                 $ioAct->setRandomTiming($tempVal);
00324                                         }
00325                                         
00326                                         // Look for 'selectCount'
00327                                         $tempVal=$curNode->getAttribute("selectCount");
00328                                         if ($tempVal) {
00329                                                 $ioAct->setSelectCount($tempVal);
00330                                         }
00331                                         
00332                                         // Look for 'reorderChildren'
00333                         $tempVal=$curNode->getAttribute("reorderChildren");
00334                                         if ($tempVal) {
00335                                                 $ioAct->setReorderChildren(self::convert_to_bool($tempVal));
00336                                         }
00337                                         
00338                                         // Look for 'selectionTiming'
00339                         $tempVal=$curNode->getAttribute("selectionTiming");
00340                                         if ($tempVal) {
00341                                 $ioAct->setSelectionTiming($tempVal);
00342                                         }
00343                                 }
00344                                 else if ($curNode->localName == "deliveryControls") {
00345                                         
00346                                         // Look for 'tracked'
00347                                         $tempVal=$curNode->getAttribute("tracked");
00348                                         if ($tempVal) {
00349                                                 $ioAct->setIsTracked(self::convert_to_bool($tempVal));
00350                                         }
00351                         
00352                        // Look for 'completionSetByContent'
00353                                         $tempVal=$curNode->getAttribute("completionSetByContent");
00354                                         if ($tempVal) {
00355                                                 $ioAct->setSetCompletion(self::convert_to_bool($tempVal));
00356                                         }
00357                       
00358                                         // Look for 'objectiveSetByContent'
00359                                         $tempVal=$curNode->getAttribute("objectiveSetByContent");
00360                                         if ($tempVal) {
00361                                                 $ioAct->setSetObjective(self::convert_to_bool($tempVal));
00362                                         }
00363                                 }       
00364                     else if ($curNode->localName == "constrainedChoiceConsiderations") {
00365                                         
00366                                         // Look for 'preventActivation'
00367                         $tempVal=$curNode->getAttribute("preventActivation");
00368                                         if ($tempVal) {
00369                                                 $ioAct->setPreventActivation(self::convert_to_bool($tempVal));
00370                                         }
00371                                         
00372                                         // Look for 'constrainChoice'
00373                         $tempVal=$curNode->getAttribute("constrainChoice");
00374                                         if ($tempVal) {
00375                                                 $ioAct->setConstrainChoice(self::convert_to_bool($tempVal));
00376                                         }
00377                                 }       
00378                                 else if ($curNode->localName == "rollupConsiderations") {
00379                                 
00380                                         // Look for 'requiredForSatisfied'
00381                                         $tempVal=$curNode->getAttribute("requiredForSatisfied");
00382                                         if ($tempVal) {
00383                                                 $ioAct->setRequiredForSatisfied($tempVal);
00384                                         }
00385                                         
00386                                         // Look for 'requiredForNotSatisfied'
00387                                         $tempVal=$curNode->getAttribute("requiredForNotSatisfied");
00388                                         if ($tempVal) {
00389                                                 $ioAct->setRequiredForNotSatisfied($tempVal);
00390                                         }
00391                                         
00392                                         // Look for 'requiredForCompleted'
00393                         $tempVal=$curNode->getAttribute("requiredForCompleted");
00394                                         if ($tempVal) {
00395                                                 $ioAct->setRequiredForCompleted($tempVal);
00396                                         }
00397                                         
00398                                         // Look for 'requiredForIncomplete'
00399                         $tempVal=$curNode->getAttribute("requiredForIncomplete");
00400                                         if ($tempVal) {
00401                                 $ioAct->setRequiredForIncomplete($tempVal);
00402                                         }
00403                                 
00404                                    // Look for 'measureSatisfactionIfActive'
00405                                         $tempVal=$curNode->getAttribute("measureSatisfactionIfActive");
00406                                         if ($tempVal) {
00407                                                 $ioAct->setSatisfactionIfActive(self::convert_to_bool($tempVal));
00408                                         }
00409                                 }       
00410                                 
00411                                 
00412                                 
00413                 }  //end note-type check
00414                 
00415                 } //end for-loop
00416                  
00417                 return $ioAct;
00418           }
00419         
00420         
00421         public static function getObjectives ($iNode,$ioAct) {
00422                 $ok = true;
00423             $tempVal = null;
00424             $objectives = array();
00425                 $children = $iNode->childNodes;
00426                 for ($i = 0; $i < $children->length; $i++ ) {
00427                         $curNode=$children->item($i);
00428                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00429                                 if ($curNode->localName == "primaryObjective" || $curNode->localName == "objective" ) {
00430                 
00431                                         $obj = new SeqObjective();
00432                                         if ($curNode->localName == "primaryObjective") { 
00433                                 $obj->mContributesToRollup = true;
00434                                         }
00435                                         
00436                         // Look for 'objectiveID'
00437                                         $tempVal = $curNode->getAttribute("objectiveID");
00438                                         if($tempVal) {
00439                                                 $obj->mObjID = $tempVal;
00440                         }
00441 
00442                                         // Look for 'satisfiedByMeasure'
00443                         $tempVal = $curNode->getAttribute("satisfiedByMeasure");
00444                                         if($tempVal) {
00445                                                 $obj->mSatisfiedByMeasure = self::convert_to_bool($tempVal);
00446                         }
00447                                         // Look for 'minNormalizedMeasure'
00448                                         $tempVal=self::lookupElement($curNode,"minNormalizedMeasure");
00449                         if($tempVal) {
00450                                                 $obj->mMinMeasure = $tempVal;
00451                         }
00452                                 
00453                                         //get ObjectiveMaps
00454                                         $maps = self::getObjectiveMaps($curNode);
00455                                         if ( $maps != null ){
00456                                                 $obj->mMaps = $maps;
00457                         }
00458                                         //$obj->mContributesToRollup = true;
00459                                         //add class
00460                                         $c_obj['_SeqObjective'] = $obj;
00461                                         array_push($objectives,$c_obj);
00462                }
00463                         }
00464                 }
00465                 $ioAct->setObjectives($objectives);
00466         return $ioAct;
00467         }
00468         
00469         
00470         public static function getObjectiveMaps($iNode) {
00471                 $tempVal = null;
00472             $maps = array();
00473                 $children = $iNode->childNodes;
00474                 for ($i = 0; $i < $children->length; $i++ ) {
00475                         $curNode=$children->item($i);
00476                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00477                                 if ($curNode->localName == "mapInfo") {
00478                                          $map = new SeqObjectiveMap();
00479                                         
00480                                         // Look for 'targetObjectiveID'
00481                          $tempVal = $curNode->getAttribute("targetObjectiveID");
00482                                          if($tempVal) {
00483                                                 $map->mGlobalObjID = $tempVal;
00484                              }
00485                 
00486                            // Look for 'readSatisfiedStatus'
00487                                 $tempVal = $curNode->getAttribute("readSatisfiedStatus");
00488                                         if($tempVal) {
00489                                                 $map->mReadStatus = self::convert_to_bool($tempVal);
00490                             }
00491                 
00492                                         // Look for 'readNormalizedMeasure'
00493                                         $tempVal = $curNode->getAttribute("readNormalizedMeasure");
00494                                         if($tempVal) {
00495                                                 $map->mReadMeasure = self::convert_to_bool($tempVal);
00496                                 }
00497                         
00498                                // Look for 'writeSatisfiedStatus'
00499                                 $tempVal = $curNode->getAttribute("writeSatisfiedStatus");
00500                                         if($tempVal) {
00501                                                 $map->mWriteStatus = self::convert_to_bool($tempVal);
00502                                 }
00503                         
00504                                // Look for 'writeNormalizedMeasure'
00505                                 $tempVal = $curNode->getAttribute("writeNormalizedMeasure");
00506                                         if($tempVal) {
00507                                                 $map->mWriteMeasure = self::convert_to_bool($tempVal);
00508                                 }
00509                         //add class
00510                                         $c_map['_SeqObjectiveMap']=$map;
00511                                         array_push($maps,$c_map);
00512                                 }
00513                         }
00514                 }       
00515                 if (count($maps)==null) {
00516                         $maps = null;
00517                 }
00518                 return $maps;
00519         }
00520         
00521         public static function getRollupRules($iNode, $ioAct) {
00522                 $ok = true;
00523                 $tempVal = null;
00524                 $rollupRules = array();
00525                 
00526                 // Look for 'rollupObjectiveSatisfied'
00527         $tempVal = $iNode->getAttribute("rollupObjectiveSatisfied");
00528                 if($tempVal) {
00529                         $ioAct->setIsObjRolledUp(self::convert_to_bool($tempVal));
00530                 }
00531                 
00532       // Look for 'objectiveMeasureWeight'
00533         $tempVal = $iNode->getAttribute("objectiveMeasureWeight");
00534         if($tempVal) {
00535                         $ioAct->setObjMeasureWeight($tempVal);
00536         
00537                 }
00538                 // Look for 'rollupProgressCompletion'
00539         $tempVal = $iNode->getAttribute("rollupProgressCompletion");
00540                 if($tempVal) {
00541                         $ioAct->setIsProgressRolledUp(self::convert_to_bool($tempVal));
00542                         
00543                 }
00544                 $children = $iNode->childNodes;
00545                 for ($i = 0; $i < $children->length; $i++ ) {
00546                         $curNode=$children->item($i);
00547                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00548                                 if ($curNode->localName == "rollupRule") {
00549                                         $rule = new SeqRollupRule();
00550                         
00551                                         // Look for 'childActivitySet'
00552                         $tempVal=$curNode->getAttribute("childActivitySet");
00553                                 if($tempVal) {
00554                                                 $rule->mChildActivitySet = $tempVal;
00555                                 }
00556                                         // Look for 'minimumCount'
00557                         $tempVal=$curNode->getAttribute("minimumCount");
00558                                         if($tempVal) {
00559                                                         $rule->mMinCount = $tempVal;
00560                                     }
00561                                 
00562                                    // Look for 'minimumPercent'
00563                         $tempVal=$curNode->getAttribute("minimumPercent");
00564                         if($tempVal) {
00565                                                         $rule->mMinPercent = $tempVal;
00566                                     }
00567                                         $rule->mConditions['_SeqConditionSet'] =  new SeqConditionSet(true);
00568                             $conditions = array();
00569                                         $ruleInfo = $curNode->childNodes;
00570                                         for ($j = 0; $j < $ruleInfo->length; $j++ ) {
00571                                                 $curRule=$ruleInfo->item($j);
00572                                                 //check for element
00573                                                 if ($curRule->nodeType == XML_ELEMENT_NODE) {
00574                                                   if ($curRule->localName == "rollupConditions") {
00575                                                         $tempVal = $curRule->getAttribute("conditionCombination");
00576                                         if($tempVal) {
00577                                                                 $rule->mConditions['_SeqConditionSet']->mCombination = $tempVal;
00578                                                    } else {
00579                                                                 $rule->mConditions['_SeqConditionSet']->mCombination = COMBINATION_ANY;         
00580                                                    }
00581                                                 $conds = $curRule->childNodes;
00582                                                 for ($k = 0; $k < $conds->length; $k++ ) {
00583                                                         $con=$conds->item($k);
00584                                                         if ($con->nodeType == XML_ELEMENT_NODE) {
00585                                                                 if ($con->localName == "rollupCondition") {
00586                                                                          $cond =  new SeqCondition();
00587                                                                          // Look for 'condition'
00588                                          $tempVal = $con->getAttribute("condition");
00589                                                                          if($tempVal) {
00590                                                                                 $cond->mCondition=$tempVal;
00591                                                                          }
00592                                                                          // Look for 'operator'
00593                                           $tempVal = $con->getAttribute("operator");
00594                                                                           if($tempVal) {
00595                                                                                 if($tempVal=='not') {$cond->mNot = true;} else {$cond->mNot = false;}
00596                                                                           }     
00597                                                                         //add class
00598                                                                         $c_cond['_SeqCondition'] = $cond;
00599                                                                         array_push($conditions,$c_cond);
00600                                                                 }                                                               
00601                                                         
00602                                                   }     
00603                                                 }
00604                                         }       
00605                                         else if ($curRule->localName == "rollupAction") {
00606                                                         $tempVal = $curRule->getAttribute("action");
00607                                                         if ($tempVal) {
00608                                                                 $rule->setRollupAction($tempVal);
00609                          }
00610                                                 
00611                                   }
00612                                 
00613                                 }
00614                            }
00615                                 // Add the conditions to the condition set for the rule
00616                          $rule->mConditions['_SeqConditionSet']->mConditions = $conditions;
00617 
00618                    // Add the rule to the ruleset
00619                                 //add class 
00620                                 $c_rule['_SeqRollupRule']=$rule;
00621                                 array_push($rollupRules,$c_rule);
00622                                 }
00623                         }
00624                 }
00625                  
00626                 if ( $rollupRules != null ) {
00627                  $rules = new SeqRollupRuleset($rollupRules);
00628                  // Set the Activity's rollup rules
00629                          //add class
00630                          $c_rules['_SeqRollupRuleset']=$rules;
00631                  $ioAct->setRollupRules($c_rules);
00632              }
00633 
00634                 return $ioAct;
00635         }
00636    
00637    
00638         public static function getSequencingRules($iNode,$ioAct) {
00639                 //local variables
00640                 $ok = true;
00641             $tempVal = null;
00642 
00643             $preRules = array();
00644             $exitRules = array();
00645             $postRules = array();
00646 
00647                 //get children
00648                 $children = $iNode->childNodes;
00649                 
00650                 //find sequencing rules
00651                  for ($i = 0; $i < $children->length; $i++ ) {
00652                         $curNode=$children->item($i);
00653                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00654                                 if ($curNode->localName == "preConditionRule" || $curNode->localName == "exitConditionRule" || $curNode->localName == "postConditionRule" ) {
00655                                         $rule = new SeqRule();
00656                         $ruleInfo = $curNode->childNodes;
00657                                         for ($j = 0; $j < $ruleInfo->length; $j++ ){
00658                                                 $curRule=$ruleInfo->item($j);
00659                                                 //echo "$curRule->localName\n";
00660                                                 if ($curRule->nodeType == XML_ELEMENT_NODE) { 
00661                                                         if ($curRule->localName == "ruleConditions") {
00662                                                                         $rule->mConditions = self::extractSeqRuleConditions($curRule);
00663                                                         }
00664                                                         else if($curRule->localName == "ruleAction"){
00665                                                                 $tempVal=$curRule->getAttribute("action");
00666                                                 if($tempVal) {
00667                                                                         $rule->mAction = $tempVal;
00668                                     }
00669                                                         }
00670                                                         
00671                                                 }
00672                                         }//end for inner
00673                         if ( $rule->mConditions != null && $rule->mAction != null ) {
00674                                                 //changed from ADL Code..
00675                                                 if ($curNode->localName == "preConditionRule") {
00676                                                         //echo "ADD PRE";
00677                                                         //add class
00678                                                         $c_rule['_SeqRule'] = $rule;
00679                                         array_push($preRules,$c_rule);
00680                                                 }
00681                                                 if ($curNode->localName == "exitConditionRule") {
00682                                                         //echo "ADD EXIT";
00683                                                         //add class
00684                                                         $c_rule['_SeqRule'] = $rule;
00685                                                         array_push($exitRules,$c_rule);
00686                                                 }
00687                                                 if ($curNode->localName == "postConditionRule") {
00688                                                         //echo "ADD POST";
00689                                                         //add class
00690                                                         $c_rule['_SeqRule'] = $rule;
00691                                         array_push($postRules,$c_rule);
00692                                                 }
00693                                         }
00694                                 } //end if preCondition
00695                         
00696                         }  //end if ELEMENT
00697                 }
00698                 
00699                 if ( count($preRules) > 0 ) {
00700                  $rules = new SeqRuleset($preRules);
00701                          //add class
00702                          $c_rules['_SeqRuleset']=$rules;
00703                  $ioAct->setPreSeqRules($c_rules);
00704         
00705             }
00706         
00707                 if ( count($exitRules) > 0 ){
00708                  $rules = new SeqRuleset($exitRules);
00709                          //add class
00710                          $c_rules['_SeqRuleset']=$rules;
00711                  $ioAct->setExitSeqRules($c_rules);
00712             }
00713                 if ( count($postRules) > 0 ){
00714                 $rules = new SeqRuleset($postRules);
00715                         //add class
00716                         $c_rules['_SeqRuleset']=$rules;
00717                 $ioAct->setPostSeqRules($c_rules);
00718                 }
00719                 //echo json_encode($ioAct);
00720                 
00721                 return $ioAct;
00722                 
00723         }
00724         
00725         public static function extractSeqRuleConditions($iNode) {
00726                 $tempVal = null;
00727             $condSet = new SeqConditionSet(false);
00728 
00729             $conditions = array();
00730                 $tempVal=$iNode->getAttribute("conditionCombination");
00731                 if ($tempVal) {
00732                         $condSet->mCombination=$tempVal;
00733                 } else {
00734                         $condSet->mCombination=COMBINATION_ALL;
00735                 }
00736                 $condInfo = $iNode->childNodes;
00737                 for ($i = 0; $i < $condInfo->length; $i++ ) {
00738                         $curCond=$condInfo->item($i);
00739                         if ($curCond->nodeType == XML_ELEMENT_NODE) {
00740                                 if ($curCond->localName == "ruleCondition") {
00741                                         $cond = new SeqCondition();
00742                                         
00743                                         //look for condition
00744                         $tempVal=$curCond->getAttribute("condition");
00745                                         if ($tempVal) {
00746                                                 $cond->mCondition = $tempVal;
00747                     }
00748 
00749                        // Look for 'referencedObjective'
00750                                         $tempVal=$curCond->getAttribute("referencedObjective");
00751                         if ($tempVal) {
00752                                                 $cond->mObjID = $tempVal;
00753                         }
00754         
00755                        // Look for 'measureThreshold'
00756                                         $tempVal=$curCond->getAttribute("measureThreshold");
00757                                         if ($tempVal) {
00758                                                 $cond->mThreshold = $tempVal;
00759                             }
00760                 
00761                            // Look for 'operator'
00762                                 $tempVal = $curCond->getAttribute("operator");
00763                                         if ($tempVal) {
00764                                                 if ($tempVal == 'not') {
00765                                                         $cond->mNot = true;
00766                                                 } else {
00767                                                         $cond->mNot = false;
00768                                                 }
00769                                         }
00770                                         
00771                                         //add class
00772                                         $c_cond['_SeqCondition']=$cond;
00773                                         array_push($conditions,$c_cond);
00774                                         
00775                                 }
00776                         }       
00777                 }
00778                 
00779                 if (count($conditions)>0) {
00780                         $condSet->mConditions = $conditions;
00781                 } else {
00782                         $condSet->mConditions = null;
00783                 }
00784                 //add class
00785                 $c_condSet['_SeqConditionSet']=$condSet;
00786                 return $c_condSet;
00787         }
00788    
00789         public static function getAuxResources($iNode, $ioAct) {
00790                 $ok = true;
00791             $tempVal = null;
00792         $auxRes = array();
00793                 //get children
00794                 $children = $iNode->childNodes;
00795 
00796                 //find  ressources
00797                 for ($i = 0; $i < $children->length; $i++ ) {
00798                         $curNode=$children->item($i);
00799                         if ($curNode->nodeType == XML_ELEMENT_NODE) {
00800                                 if ($curNode->localName == "auxiliaryResource") {
00801                                         //found it
00802                                         $res = new ADLAuxiliaryResource();
00803                                         
00804                                         // Get the resource's purpose
00805                         $tempVal=$curNode->getAttribute("purpose");
00806                                         if ($tempVal) {
00807                                                 $res->mType = $tempVal;
00808                                 }
00809                                // Get the resource's ID
00810                                         $tempVal=$curNode->getAttribute("auxiliaryResourceID");
00811                                         if ($tempVal) {
00812                                                 $res->mResourceID = $tempVal;
00813                                     }
00814                                         array_push($auxRes,$res);
00815                                 }
00816                         }
00817                 }       
00818                 //add class
00819                 $c_auxRes['_ADLAuxiliaryResource']=$auxRes;
00820                 $ioAct->setAuxResources($c_auxRes);
00821         return $ioAct;
00822         }
00823         
00824           //helper functions
00825         
00826           private static function convert_to_bool($string) {
00827                 if (strtoupper($string)=="FALSE") {
00828                         return false;
00829                 } else {
00830                         return true;
00831                 }
00832           }
00833         
00834         
00835           private function lookupElement($iNode, $iElement){
00836                 $value = null;
00837                 $curNode = null;
00838                 $children = null;
00839                 
00840                 if ( $iNode != null && $iElement != null ){
00841                         $children = $iNode->childNodes;
00842                         for ($i = 0; $i < $children->length; $i++ ) {
00843                                 $curNode = $children->item($i);
00844                         if ( ($curNode->nodeType == XML_ELEMENT_NODE)) {
00845                                         if ($curNode->localName == $iElement) {
00846                                                 break;
00847                                         }
00848                                 }
00849             
00850                         }
00851                         if ($curNode != null ) {
00852                                 $comp = $curNode->localName;
00853                                 if ($comp != null) {
00854                                         if ($comp != $iElement) {
00855                                                 $curNode = null;
00856                                         } 
00857                                 } else {
00858                                         $curNode = null;
00859                     
00860                                 }
00861                         }
00862          
00863                 }
00864                 else {
00865                         //$iElement is null
00866                         $curNode = $iNode;
00867               }
00868           
00869                 if ( $curNode != null )
00870               {
00871                         $children = $curNode->childNodes;
00872                 if ( $children != null ) {
00873                                 for ($i = 0; $i < $children->length; $i++ ) {
00874                                         $curNode = $children->item($i);
00875                                          // make sure we have a 'text' element
00876                                if ( ($curNode->nodeType == XML_TEXT_NODE) ||($curNode->nodeType == XML_CDATA_SECTION_NODE) )
00877                                {
00878                                   $value = $value.$curNode->nodeValue;
00879                                }
00880                        }
00881                         }
00882               }
00883                 return $value;
00884           }
00885           
00886           
00887 }         //end class
00888           
00889 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1