In the \moodle\mod\scorm\datamodels\scorm_12.js.php file at line 131 there is a PHP block designed to initialise the data model's objectives.
However, the last check-in of this code introduced a bug whereby $subelement is always empty-string and the for..each block only matches the first objective initialisation. This is due to the regular expression exclusively matching full-stops (now \., previously .), rather than the underscore as captured by the data model from a previous session write-back (cmi.objectives_0.id). Also the replacement is performed after the regex matcher for the objective identifiers, introducing needless complexity. Consequently the following JS code is produced by api.php when revisiting a SCORM 1.2 package making use of the cmi.objectives data model section:
= new Object();
.score = new Object();
.score._children = score_children;
.score.raw = '';
.score.min = '';
.score.max = '';
Note: There is no actual or intended 'with' block, nor should there be.
I propose the following code fix:
<?php
$count = 0;
$objectives = '';
foreach($userdata as $element => $value) {
if (substr($element, 0, 14) == 'cmi.objectives') {
$element = preg_replace('/\.(\d+)\./', "_\$1.", $element);
preg_match('/_(\d+)\./', $element, $matches);
if ($matches[1] == $count)
echo ' '.$element.' = \''.$value."';\n";
}
}
if ($count > 0)
?>