Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-12614

SCORM 1.2 JavaScript Error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 1.8.6, 1.9.1
    • 1.8.2, 1.8.3
    • SCORM
    • None
    • MySQL
    • MOODLE_18_STABLE
    • MOODLE_18_STABLE, MOODLE_19_STABLE

      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)

      { $count++; $end = strpos($element, $matches[1]) + strlen($matches[1]); $subelement = substr($element, 0, $end); echo ' '.$subelement." = new Object();\n"; echo ' '.$subelement.".score = new Object();\n"; echo ' '.$subelement.".score._children = score_children;\n"; echo ' '.$subelement.".score.raw = '';\n"; echo ' '.$subelement.".score.min = '';\n"; echo ' '.$subelement.".score.max = '';\n"; }

      echo ' '.$element.' = \''.$value."';\n";
      }
      }
      if ($count > 0)

      { echo ' cmi.objectives._count = '.$count.";\n"; }

      ?>

            poltawski Dan Poltawski
            pinkduck Peter Chamberlin
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.