From 3505e82b529add735eaae128e347a7a0ae26a315 Mon Sep 17 00:00:00 2001 From: piers Date: Thu, 24 Jul 2008 23:08:30 +0000 Subject: [PATCH] MDL-11137 Unable to locate API error - force a sort order on the cmi elements, and ensure correct type comparison when determining whether we have seen this objective id before. affects aicc, 1.2 and 1.3. --- mod/scorm/datamodels/aicc.js.php | 8 +++++--- mod/scorm/datamodels/scorm_12.js.php | 6 ++++-- mod/scorm/datamodels/scorm_13.js.php | 6 ++++-- mod/scorm/locallib.php | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/mod/scorm/datamodels/aicc.js.php b/mod/scorm/datamodels/aicc.js.php index bc78c1801b..dfebd349e2 100644 --- a/mod/scorm/datamodels/aicc.js.php +++ b/mod/scorm/datamodels/aicc.js.php @@ -147,13 +147,15 @@ function AICCapi() { } $value){ if (substr($element,0,14) == 'cmi.objectives') { - preg_match('/.(\d+)./',$element,$matches); - $element = preg_replace('/.(\d+)./',"_\$1.",$element); - if ($matches[1] == $count) { + $element = preg_replace('/\.(\d+)\./', "_\$1.", $element); + preg_match('/\_(\d+)\./', $element, $matches); + if (count($matches) > 0 && $current_objective != $matches[1]) { + $current_objective = $matches[1]; $count++; $end = strpos($element,$matches[1])+strlen($matches[1]); $subelement = substr($element,0,$end); diff --git a/mod/scorm/datamodels/scorm_12.js.php b/mod/scorm/datamodels/scorm_12.js.php index 856841a5c8..3ee58a6e31 100644 --- a/mod/scorm/datamodels/scorm_12.js.php +++ b/mod/scorm/datamodels/scorm_12.js.php @@ -129,13 +129,15 @@ function SCORMapi1_2() { } $value){ if (substr($element,0,14) == 'cmi.objectives') { $element = preg_replace('/\.(\d+)\./', "_\$1.", $element); - preg_match('/_(\d+)\./', $element, $matches); - if (isset($matches[1]) && $matches[1] == $count) { + preg_match('/\_(\d+)\./', $element, $matches); + if (count($matches) > 0 && $current_objective != $matches[1]) { + $current_objective = $matches[1]; $count++; $end = strpos($element,$matches[1])+strlen($matches[1]); $subelement = substr($element,0,$end); diff --git a/mod/scorm/datamodels/scorm_13.js.php b/mod/scorm/datamodels/scorm_13.js.php index c5e7a22aff..29e2168de8 100644 --- a/mod/scorm/datamodels/scorm_13.js.php +++ b/mod/scorm/datamodels/scorm_13.js.php @@ -206,13 +206,15 @@ function SCORMapi1_3() { } $value){ if (substr($element,0,14) == 'cmi.objectives') { $element = preg_replace('/\.(\d+)\./', "_\$1.", $element); - preg_match('/_(\d+)\./', $element, $matches); - if (isset($matches[1]) && $matches[1] == $count) { + preg_match('/\_(\d+)\./', $element, $matches); + if (count($matches) > 0 && $current_objective != $matches[1]) { + $current_objective = $matches[1]; $count++; $end = strpos($element,$matches[1])+strlen($matches[1]); $subelement = substr($element,0,$end); diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 9f7df6ae8c..f28e28ab7c 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -278,7 +278,8 @@ function scorm_get_tracks($scoid,$userid,$attempt='') { if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) { $usertrack->timemodified = $track->timemodified; } - } + } + ksort($userdata); return $usertrack; } else { return false; -- 2.39.5