2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 function scorm_get_resources($blocks) {
19 foreach ($blocks as $block) {
20 if ($block['name'] == 'RESOURCES' && isset($block['children'])) {
21 foreach ($block['children'] as $resource) {
22 if ($resource['name'] == 'RESOURCE') {
23 $resources[addslashes_js($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];
31 function scorm_get_manifest($blocks, $scoes) {
33 static $parents = array();
39 $manifestresourcesnotfound = array();
40 if (count($blocks) > 0) {
41 foreach ($blocks as $block) {
42 switch ($block['name']) {
44 if (isset($block['children'])) {
45 foreach ($block['children'] as $metadata) {
46 if ($metadata['name'] == 'SCHEMAVERSION') {
47 if (empty($scoes->version)) {
48 if (isset($metadata['tagData']) && (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/", $metadata['tagData'], $matches))) {
49 $scoes->version = 'SCORM_'.$matches[count($matches)-1];
51 if (isset($metadata['tagData']) && (preg_match("/^2004 (3rd|4th) Edition$/", $metadata['tagData'], $matches))) {
52 $scoes->version = 'SCORM_1.3';
54 $scoes->version = 'SCORM_1.2';
63 $manifest = $block['attrs']['IDENTIFIER'];
66 $resources = scorm_get_resources($block['children']);
67 $scoes = scorm_get_manifest($block['children'], $scoes);
68 if (empty($scoes->elements) || count($scoes->elements) <= 0) {
69 foreach ($resources as $item => $resource) {
70 if (!empty($resource['HREF'])) {
71 $sco = new stdClass();
72 $sco->identifier = $item;
75 $sco->launch = $resource['HREF'];
76 $sco->scormtype = $resource['ADLCP:SCORMTYPE'];
77 $scoes->elements[$manifest][$organization][$item] = $sco;
83 if (!isset($scoes->defaultorg) && isset($block['attrs']['DEFAULT'])) {
84 $scoes->defaultorg = $block['attrs']['DEFAULT'];
86 if (!empty($block['children'])) {
87 $scoes = scorm_get_manifest($block['children'], $scoes);
91 $identifier = $block['attrs']['IDENTIFIER'];
93 $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
94 $scoes->elements[$manifest][$organization][$identifier]->parent = '/';
95 $scoes->elements[$manifest][$organization][$identifier]->launch = '';
96 $scoes->elements[$manifest][$organization][$identifier]->scormtype = '';
99 $parent = new stdClass();
100 $parent->identifier = $identifier;
101 $parent->organization = $organization;
102 array_push($parents, $parent);
103 $organization = $identifier;
105 if (!empty($block['children'])) {
106 $scoes = scorm_get_manifest($block['children'], $scoes);
112 $parent = array_pop($parents);
113 array_push($parents, $parent);
115 $identifier = $block['attrs']['IDENTIFIER'];
116 $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier;
117 $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier;
118 if (!isset($block['attrs']['ISVISIBLE'])) {
119 $block['attrs']['ISVISIBLE'] = 'true';
121 $scoes->elements[$manifest][$organization][$identifier]->isvisible = $block['attrs']['ISVISIBLE'];
122 if (!isset($block['attrs']['PARAMETERS'])) {
123 $block['attrs']['PARAMETERS'] = '';
125 $scoes->elements[$manifest][$organization][$identifier]->parameters = $block['attrs']['PARAMETERS'];
126 if (!isset($block['attrs']['IDENTIFIERREF'])) {
127 $scoes->elements[$manifest][$organization][$identifier]->launch = '';
128 $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset';
130 $idref = $block['attrs']['IDENTIFIERREF'];
132 if (isset($resources[$idref]['XML:BASE'])) {
133 $base = $resources[$idref]['XML:BASE'];
135 if (!isset($resources[$idref])) {
136 $manifestresourcesnotfound[] = $idref;
137 $scoes->elements[$manifest][$organization][$identifier]->launch = '';
139 $scoes->elements[$manifest][$organization][$identifier]->launch = $base.$resources[$idref]['HREF'];
140 if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
141 $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
143 $scoes->elements[$manifest][$organization][$identifier]->scormtype = $resources[$idref]['ADLCP:SCORMTYPE'];
147 $parent = new stdClass();
148 $parent->identifier = $identifier;
149 $parent->organization = $organization;
150 array_push($parents, $parent);
152 if (!empty($block['children'])) {
153 $scoes = scorm_get_manifest($block['children'], $scoes);
159 $parent = array_pop($parents);
160 array_push($parents, $parent);
161 if (!isset($block['tagData'])) {
162 $block['tagData'] = '';
164 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = $block['tagData'];
166 case 'ADLCP:PREREQUISITES':
167 if ($block['attrs']['TYPE'] == 'aicc_script') {
168 $parent = array_pop($parents);
169 array_push($parents, $parent);
170 if (!isset($block['tagData'])) {
171 $block['tagData'] = '';
173 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = $block['tagData'];
176 case 'ADLCP:MAXTIMEALLOWED':
177 $parent = array_pop($parents);
178 array_push($parents, $parent);
179 if (!isset($block['tagData'])) {
180 $block['tagData'] = '';
182 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = $block['tagData'];
184 case 'ADLCP:TIMELIMITACTION':
185 $parent = array_pop($parents);
186 array_push($parents, $parent);
187 if (!isset($block['tagData'])) {
188 $block['tagData'] = '';
190 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = $block['tagData'];
192 case 'ADLCP:DATAFROMLMS':
193 $parent = array_pop($parents);
194 array_push($parents, $parent);
195 if (!isset($block['tagData'])) {
196 $block['tagData'] = '';
198 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = $block['tagData'];
200 case 'ADLCP:MASTERYSCORE':
201 $parent = array_pop($parents);
202 array_push($parents, $parent);
203 if (!isset($block['tagData'])) {
204 $block['tagData'] = '';
206 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = $block['tagData'];
208 case 'ADLCP:COMPLETIONTHRESHOLD':
209 $parent = array_pop($parents);
210 array_push($parents, $parent);
211 if (!isset($block['attrs']['MINPROGRESSMEASURE'])) {
212 $block['attrs']['MINPROGRESSMEASURE'] = '1.0';
214 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->threshold = $block['attrs']['MINPROGRESSMEASURE'];
216 case 'ADLNAV:PRESENTATION':
217 $parent = array_pop($parents);
218 array_push($parents, $parent);
219 if (!empty($block['children'])) {
220 foreach ($block['children'] as $adlnav) {
221 if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') {
222 foreach ($adlnav['children'] as $adlnavInterface) {
223 if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI') {
224 if ($adlnavInterface['tagData'] == 'continue') {
225 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hidecontinue = 1;
227 if ($adlnavInterface['tagData'] == 'previous') {
228 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hideprevious = 1;
230 if ($adlnavInterface['tagData'] == 'exit') {
231 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hideexit = 1;
233 if ($adlnavInterface['tagData'] == 'exitAll') {
234 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hideexitall = 1;
236 if ($adlnavInterface['tagData'] == 'abandon') {
237 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hideabandon = 1;
239 if ($adlnavInterface['tagData'] == 'abandonAll') {
240 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hideabandonall = 1;
242 if ($adlnavInterface['tagData'] == 'suspendAll') {
243 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->hidesuspendall = 1;
251 case 'IMSSS:SEQUENCING':
252 $parent = array_pop($parents);
253 array_push($parents, $parent);
254 if (!empty($block['children'])) {
255 foreach ($block['children'] as $sequencing) {
256 if ($sequencing['name']=='IMSSS:CONTROLMODE') {
257 if (isset($sequencing['attrs']['CHOICE'])) {
258 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choice = $sequencing['attrs']['CHOICE'] == 'true'?1:0;
260 if (isset($sequencing['attrs']['CHOICEEXIT'])) {
261 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choiceexit = $sequencing['attrs']['CHOICEEXIT'] == 'true'?1:0;
263 if (isset($sequencing['attrs']['FLOW'])) {
264 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->flow = $sequencing['attrs']['FLOW'] == 'true'?1:0;
266 if (isset($sequencing['attrs']['FORWARDONLY'])) {
267 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->forwardonly = $sequencing['attrs']['FORWARDONLY'] == 'true'?1:0;
269 if (isset($sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'])) {
270 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptobjectinfo = $sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'] == 'true'?1:0;
272 if (isset($sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'])) {
273 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptprogressinfo = $sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'] == 'true'?1:0;
276 if ($sequencing['name']=='ADLSEQ:CONSTRAINEDCHOICECONSIDERATIONS') {
277 if (isset($sequencing['attrs']['CONSTRAINCHOICE'])) {
278 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->constrainChoice = $sequencing['attrs']['CONSTRAINCHOICE'] == 'true'?1:0;
280 if (isset($sequencing['attrs']['PREVENTACTIVATION'])) {
281 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->preventactivation = $sequencing['attrs']['PREVENTACTIVATION'] == 'true'?1:0;
284 if ($sequencing['name']=='IMSSS:OBJECTIVES') {
285 $objectives = array();
286 foreach ($sequencing['children'] as $objective) {
287 $objectivedata = new stdClass();
288 $objectivedata->primaryobj = 0;
289 switch ($objective['name']) {
290 case 'IMSSS:PRIMARYOBJECTIVE':
291 $objectivedata->primaryobj = 1;
292 case 'IMSSS:OBJECTIVE':
293 $objectivedata->satisfiedbymeasure = 0;
294 if (isset($objective['attrs']['SATISFIEDBYMEASURE'])) {
295 $objectivedata->satisfiedbymeasure = $objective['attrs']['SATISFIEDBYMEASURE']== 'true'?1:0;
297 $objectivedata->objectiveid = '';
298 if (isset($objective['attrs']['OBJECTIVEID'])) {
299 $objectivedata->objectiveid = $objective['attrs']['OBJECTIVEID'];
301 $objectivedata->minnormalizedmeasure = 1.0;
302 if (!empty($objective['children'])) {
304 foreach ($objective['children'] as $objectiveparam) {
305 if ($objectiveparam['name']=='IMSSS:MINNORMALIZEDMEASURE') {
306 if (isset($objectiveparam['tagData'])) {
307 $objectivedata->minnormalizedmeasure = $objectiveparam['tagData'];
309 $objectivedata->minnormalizedmeasure = 0;
312 if ($objectiveparam['name']=='IMSSS:MAPINFO') {
313 $mapinfo = new stdClass();
314 $mapinfo->targetobjectiveid = '';
315 if (isset($objectiveparam['attrs']['TARGETOBJECTIVEID'])) {
316 $mapinfo->targetobjectiveid = $objectiveparam['attrs']['TARGETOBJECTIVEID'];
318 $mapinfo->readsatisfiedstatus = 1;
319 if (isset($objectiveparam['attrs']['READSATISFIEDSTATUS'])) {
320 $mapinfo->readsatisfiedstatus = $objectiveparam['attrs']['READSATISFIEDSTATUS'] == 'true'?1:0;
322 $mapinfo->writesatisfiedstatus = 0;
323 if (isset($objectiveparam['attrs']['WRITESATISFIEDSTATUS'])) {
324 $mapinfo->writesatisfiedstatus = $objectiveparam['attrs']['WRITESATISFIEDSTATUS'] == 'true'?1:0;
326 $mapinfo->readnormalizemeasure = 1;
327 if (isset($objectiveparam['attrs']['READNORMALIZEDMEASURE'])) {
328 $mapinfo->readnormalizemeasure = $objectiveparam['attrs']['READNORMALIZEDMEASURE'] == 'true'?1:0;
330 $mapinfo->writenormalizemeasure = 0;
331 if (isset($objectiveparam['attrs']['WRITENORMALIZEDMEASURE'])) {
332 $mapinfo->writenormalizemeasure = $objectiveparam['attrs']['WRITENORMALIZEDMEASURE'] == 'true'?1:0;
334 array_push($mapinfos, $mapinfo);
337 if (!empty($mapinfos)) {
338 $objectivesdata->mapinfos = $mapinfos;
343 array_push($objectives, $objectivedata);
345 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->objectives = $objectives;
347 if ($sequencing['name']=='IMSSS:LIMITCONDITIONS') {
348 if (isset($sequencing['attrs']['ATTEMPTLIMIT'])) {
349 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptLimit = $sequencing['attrs']['ATTEMPTLIMIT'];
351 if (isset($sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'])) {
352 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptAbsoluteDurationLimit = $sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'];
355 if ($sequencing['name']=='IMSSS:ROLLUPRULES') {
356 if (isset($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'])) {
357 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupobjectivesatisfied = $sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'] == 'true'?1:0;;
359 if (isset($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'])) {
360 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupprogresscompletion = $sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'] == 'true'?1:0;
362 if (isset($sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'])) {
363 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->objectivemeasureweight = $sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'];
366 if (!empty($sequencing['children'])) {
367 $rolluprules = array();
368 foreach ($sequencing['children'] as $sequencingrolluprule) {
369 if ($sequencingrolluprule['name']=='IMSSS:ROLLUPRULE' ) {
370 $rolluprule = new stdClass();
371 $rolluprule->childactivityset = 'all';
372 if (isset($sequencingrolluprule['attrs']['CHILDACTIVITYSET'])) {
373 $rolluprule->childactivityset = $sequencingrolluprule['attrs']['CHILDACTIVITYSET'];
375 $rolluprule->minimumcount = 0;
376 if (isset($sequencingrolluprule['attrs']['MINIMUMCOUNT'])) {
377 $rolluprule->minimumcount = $sequencingrolluprule['attrs']['MINIMUMCOUNT'];
379 $rolluprule->minimumpercent = 0.0000;
380 if (isset($sequencingrolluprule['attrs']['MINIMUMPERCENT'])) {
381 $rolluprule->minimumpercent = $sequencingrolluprule['attrs']['MINIMUMPERCENT'];
383 if (!empty($sequencingrolluprule['children'])) {
384 foreach ($sequencingrolluprule['children'] as $rolluproleconditions) {
385 if ($rolluproleconditions['name']=='IMSSS:ROLLUPCONDITIONS') {
386 $conditions = array();
387 $rolluprule->conditioncombination = 'all';
388 if (isset($rolluproleconditions['attrs']['CONDITIONCOMBINATION'])) {
389 $rolluprule->conditioncombination = $rolluproleconditions['attrs']['CONDITIONCOMBINATION'];
391 foreach ($rolluproleconditions['children'] as $rolluprulecondition) {
392 if ($rolluprulecondition['name']=='IMSSS:ROLLUPCONDITION') {
393 $condition = new stdClass();
394 if (isset($rolluprulecondition['attrs']['CONDITION'])) {
395 $condition->cond = $rolluprulecondition['attrs']['CONDITION'];
397 $condition->operator = 'noOp';
398 if (isset($rolluprulecondition['attrs']['OPERATOR'])) {
399 $condition->operator = $rolluprulecondition['attrs']['OPERATOR'];
401 array_push($conditions, $condition);
404 $rolluprule->conditions = $conditions;
406 if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION') {
407 $rolluprule->rollupruleaction = $rolluproleconditions['attrs']['ACTION'];
411 array_push($rolluprules, $rolluprule);
414 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules = $rolluprules;
418 if ($sequencing['name']=='IMSSS:SEQUENCINGRULES') {
419 if (!empty($sequencing['children'])) {
420 $sequencingrules = array();
421 foreach ($sequencing['children'] as $conditionrules) {
423 switch($conditionrules['name']) {
424 case 'IMSSS:PRECONDITIONRULE':
427 case 'IMSSS:POSTCONDITIONRULE':
430 case 'IMSSS:EXITCONDITIONRULE':
434 if (!empty($conditionrules['children'])) {
435 $sequencingrule = new stdClass();
436 foreach ($conditionrules['children'] as $conditionrule) {
437 if ($conditionrule['name']=='IMSSS:RULECONDITIONS') {
438 $ruleconditions = array();
439 $sequencingrule->conditioncombination = 'all';
440 if (isset($conditionrule['attrs']['CONDITIONCOMBINATION'])) {
441 $sequencingrule->conditioncombination = $conditionrule['attrs']['CONDITIONCOMBINATION'];
443 foreach ($conditionrule['children'] as $rulecondition) {
444 if ($rulecondition['name']=='IMSSS:RULECONDITION') {
445 $condition = new stdClass();
446 if (isset($rulecondition['attrs']['CONDITION'])) {
447 $condition->cond = $rulecondition['attrs']['CONDITION'];
449 $condition->operator = 'noOp';
450 if (isset($rulecondition['attrs']['OPERATOR'])) {
451 $condition->operator = $rulecondition['attrs']['OPERATOR'];
453 $condition->measurethreshold = 0.0000;
454 if (isset($rulecondition['attrs']['MEASURETHRESHOLD'])) {
455 $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];
457 $condition->referencedobjective = '';
458 if (isset($rulecondition['attrs']['REFERENCEDOBJECTIVE'])) {
459 $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];
461 array_push($ruleconditions, $condition);
464 $sequencingrule->ruleconditions = $ruleconditions;
466 if ($conditionrule['name']=='IMSSS:RULEACTION') {
467 $sequencingrule->action = $conditionrule['attrs']['ACTION'];
469 $sequencingrule->type = $conditiontype;
471 array_push($sequencingrules, $sequencingrule);
474 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->sequencingrules = $sequencingrules;
483 if (!empty($manifestresourcesnotfound)) {
484 //throw warning to user to let them know manifest contains references to resources that don't appear to exist.
485 if (!defined('DEBUGGING_PRINTED')) { //prevent redirect and display warning
486 define('DEBUGGING_PRINTED', 1);
488 echo $OUTPUT->notification(get_string('invalidmanifestresource', 'scorm').' '. implode(', ',$manifestresourcesnotfound));
493 function scorm_parse_scorm($scorm, $manifest) {
496 // load manifest into string
497 if ($manifest instanceof stored_file) {
498 $xmltext = $manifest->get_content();
500 require_once("$CFG->libdir/filelib.php");
501 $xmltext = download_file_content($manifest);
506 $pattern = '/&(?!\w{2,6};)/';
507 $replacement = '&';
508 $xmltext = preg_replace($pattern, $replacement, $xmltext);
510 $objXML = new xml2Array();
511 $manifests = $objXML->parse($xmltext);
512 $scoes = new stdClass();
513 $scoes->version = '';
514 $scoes = scorm_get_manifest($manifests, $scoes);
515 if (count($scoes->elements) > 0) {
516 $olditems = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id));
517 foreach ($scoes->elements as $manifest => $organizations) {
518 foreach ($organizations as $organization => $items) {
519 foreach ($items as $identifier => $item) {
520 // This new db mngt will support all SCORM future extensions
521 $newitem = new stdClass();
522 $newitem->scorm = $scorm->id;
523 $newitem->manifest = $manifest;
524 $newitem->organization = $organization;
525 $standarddatas = array('parent', 'identifier', 'launch', 'scormtype', 'title');
526 foreach ($standarddatas as $standarddata) {
527 if (isset($item->$standarddata)) {
528 $newitem->$standarddata = $item->$standarddata;
532 // Insert the new SCO, and retain the link between the old and new for later adjustment
533 $id = $DB->insert_record('scorm_scoes', $newitem);
534 if (!empty($olditems) && ($olditemid = scorm_array_search('identifier', $newitem->identifier, $olditems))) {
535 $olditems[$olditemid]->newid = $id;
538 if ($optionaldatas = scorm_optionals_data($item, $standarddatas)) {
539 $data = new stdClass();
541 foreach ($optionaldatas as $optionaldata) {
542 if (isset($item->$optionaldata)) {
543 $data->name = $optionaldata;
544 $data->value = $item->$optionaldata;
545 $dataid = $DB->insert_record('scorm_scoes_data', $data);
550 if (isset($item->sequencingrules)) {
551 foreach ($item->sequencingrules as $sequencingrule) {
552 $rule = new stdClass();
554 $rule->ruletype = $sequencingrule->type;
555 $rule->conditioncombination = $sequencingrule->conditioncombination;
556 $rule->action = $sequencingrule->action;
557 $ruleid = $DB->insert_record('scorm_seq_ruleconds', $rule);
558 if (isset($sequencingrule->ruleconditions)) {
559 foreach ($sequencingrule->ruleconditions as $rulecondition) {
560 $rulecond = new stdClass();
561 $rulecond->scoid = $id;
562 $rulecond->ruleconditionsid = $ruleid;
563 $rulecond->referencedobjective = $rulecondition->referencedobjective;
564 $rulecond->measurethreshold = $rulecondition->measurethreshold;
565 $rulecond->cond = $rulecondition->cond;
566 $rulecondid = $DB->insert_record('scorm_seq_rulecond', $rulecond);
572 if (isset($item->rolluprules)) {
573 foreach ($item->rolluprules as $rolluprule) {
574 $rollup = new stdClass();
575 $rollup->scoid = $id;
576 $rollup->childactivityset = $rolluprule->childactivityset;
577 $rollup->minimumcount = $rolluprule->minimumcount;
578 $rollup->minimumpercent = $rolluprule->minimumpercent;
579 $rollup->rollupruleaction = $rolluprule->rollupruleaction;
580 $rollup->conditioncombination = $rolluprule->conditioncombination;
582 $rollupruleid = $DB->insert_record('scorm_seq_rolluprule', $rollup);
583 if (isset($rollup->conditions)) {
584 foreach ($rollup->conditions as $condition) {
585 $cond = new stdClass();
586 $cond->scoid = $rollup->scoid;
587 $cond->rollupruleid = $rollupruleid;
588 $cond->operator = $condition->operator;
589 $cond->cond = $condition->cond;
590 $conditionid = $DB->insert_record('scorm_seq_rolluprulecond', $cond);
596 if (isset($item->objectives)) {
597 foreach ($item->objectives as $objective) {
598 $obj = new stdClass();
600 $obj->primaryobj = $objective->primaryobj;
601 $obj->satisfiedbumeasure = $objective->satisfiedbymeasure;
602 $obj->objectiveid = $objective->objectiveid;
603 $obj->minnormalizedmeasure = trim($objective->minnormalizedmeasure);
604 $objectiveid = $DB->insert_record('scorm_seq_objective', $obj);
605 if (isset($objective->mapinfos)) {
606 foreach ($objective->mapinfos as $objmapinfo) {
607 $mapinfo = new stdClass();
608 $mapinfo->scoid = $id;
609 $mapinfo->objectiveid = $objectiveid;
610 $mapinfo->targetobjectiveid = $objmapinfo->targetobjectiveid;
611 $mapinfo->readsatisfiedstatus = $objmapinfo->readsatisfiedstatus;
612 $mapinfo->writesatisfiedstatus = $objmapinfo->writesatisfiedstatus;
613 $mapinfo->readnormalizedmeasure = $objmapinfo->readnormalizedmeasure;
614 $mapinfo->writenormalizedmeasure = $objmapinfo->writenormalizedmeasure;
615 $mapinfoid = $DB->insert_record('scorm_seq_mapinfo', $mapinfo);
620 if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) {
626 if (!empty($olditems)) {
627 foreach ($olditems as $olditem) {
628 $DB->delete_records('scorm_scoes', array('id'=>$olditem->id));
629 $DB->delete_records('scorm_scoes_data', array('scoid'=>$olditem->id));
630 if (isset($olditem->newid)) {
631 $DB->set_field('scorm_scoes_track', 'scoid', $olditem->newid, array('scoid' => $olditem->id));
633 $DB->delete_records('scorm_scoes_track', array('scoid'=>$olditem->id));
634 $DB->delete_records('scorm_seq_objective', array('scoid'=>$olditem->id));
635 $DB->delete_records('scorm_seq_mapinfo', array('scoid'=>$olditem->id));
636 $DB->delete_records('scorm_seq_ruleconds', array('scoid'=>$olditem->id));
637 $DB->delete_records('scorm_seq_rulecond', array('scoid'=>$olditem->id));
638 $DB->delete_records('scorm_seq_rolluprule', array('scoid'=>$olditem->id));
639 $DB->delete_records('scorm_seq_rolluprulecond', array('scoid'=>$olditem->id));
642 if (empty($scoes->version)) {
643 $scoes->version = 'SCORM_1.2';
645 $DB->set_field('scorm', 'version', $scoes->version, array('id'=>$scorm->id));
646 $scorm->version = $scoes->version;
649 $scorm->launch = $launch;
654 function scorm_optionals_data($item, $standarddata) {
656 $sequencingdata = array('sequencingrules', 'rolluprules', 'objectives');
657 foreach ($item as $element => $value) {
658 if (! in_array($element, $standarddata)) {
659 if (! in_array($element, $sequencingdata)) {
660 $result[] = $element;
667 function scorm_is_leaf($sco) {
670 if ($DB->get_record('scorm_scoes', array('scorm'=>$sco->scorm, 'parent'=>$sco->identifier))) {
676 function scorm_get_parent($sco) {
679 if ($sco->parent != '/') {
680 if ($parent = $DB->get_record('scorm_scoes', array('scorm'=>$sco->scorm, 'identifier'=>$sco->parent))) {
681 return scorm_get_sco($parent->id);
687 function scorm_get_children($sco) {
690 if ($children = $DB->get_records('scorm_scoes', array('scorm'=>$sco->scorm, 'parent'=>$sco->identifier))) {//originally this said parent instead of childrean
696 function scorm_get_available_children($sco) { // TODO: undefined vars!!!
699 $res = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,
701 'element'=>'availablechildren'));
702 if (!$res || $res == null) {
705 return unserialize($res->value);
709 function scorm_get_available_descendent($descend = array(), $sco) {
713 $avchildren = scorm_get_available_children($sco);
714 foreach ($avchildren as $avchild) {
715 array_push($descend, $avchild);
717 foreach ($avchildren as $avchild) {
718 scorm_get_available_descendent($descend, $avchild);
723 function scorm_get_siblings($sco) {
726 if ($siblings = $DB->get_records('scorm_scoes', array('scorm'=>$sco->scorm, 'parent'=>$sco->parent))) {
727 unset($siblings[$sco->id]);
728 if (!empty($siblings)) {
734 //get an array that contains all the parent scos for this sco.
735 function scorm_get_ancestors($sco) {
736 $ancestors = array();
739 $ancestor = scorm_get_parent($sco);
740 if (!empty($ancestor) && $ancestor->id !== $sco->id) {
742 $ancestors[] = $ancestor;
743 if ($sco->parent == '/') {
753 function scorm_get_preorder($preorder=array(), $sco) {
755 array_push($preorder, $sco);
756 $children = scorm_get_children($sco);
757 foreach ($children as $child) {
758 scorm_get_preorder($sco);
765 function scorm_find_common_ancestor($ancestors, $sco) {
766 $pos = scorm_array_search('identifier', $sco->parent, $ancestors);
767 if ($sco->parent != '/') {
768 if ($pos === false) {
769 return scorm_find_common_ancestor($ancestors, scorm_get_parent($sco));
776 Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;
778 $objXML = new xml2Array();
779 $arrOutput = $objXML->parse($strYourXML);
780 print_r($arrOutput); //print it out, or do whatever!
785 var $arrOutput = array();
790 * Convert a utf-8 string to html entities
792 * @param string $str The UTF-8 string
795 function utf8_to_entities($str) {
806 * Parse an XML text string and create an array tree that rapresent the XML structure
808 * @param string $strInputXML The XML string
811 function parse($strInputXML) {
812 $this->resParser = xml_parser_create ('UTF-8');
813 xml_set_object($this->resParser, $this);
814 xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
816 xml_set_character_data_handler($this->resParser, "tagData");
818 $this->strXmlData = xml_parse($this->resParser, $strInputXML );
819 if (!$this->strXmlData) {
820 die(sprintf("XML error: %s at line %d",
821 xml_error_string(xml_get_error_code($this->resParser)),
822 xml_get_current_line_number($this->resParser)));
825 xml_parser_free($this->resParser);
827 return $this->arrOutput;
830 function tagOpen($parser, $name, $attrs) {
831 $tag=array("name"=>$name, "attrs"=>$attrs);
832 array_push($this->arrOutput, $tag);
835 function tagData($parser, $tagData) {
836 if (trim($tagData)) {
837 if (isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
838 $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $this->utf8_to_entities($tagData);
840 $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $this->utf8_to_entities($tagData);
845 function tagClosed($parser, $name) {
846 $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
847 array_pop($this->arrOutput);