Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SCORM MDL-25757 fix for saving of duplicate CMI values - thanks to Ev…

…an Irving-Pease for the patch
  • Loading branch information...
commit f029a59e2490ddd667730075136a9c3e93b37245 1 parent 92939cd
@danmarsden danmarsden authored stronk7 committed
Showing with 50 additions and 7 deletions.
  1. +50 −7 mod/scorm/datamodels/scorm_12.js.php
View
57 mod/scorm/datamodels/scorm_12.js.php
@@ -566,19 +566,49 @@ function CollectData(data,parent) {
} else {
element = parent+'.'+property;
expression = new RegExp(CMIIndex,'g');
+
+ // get the generic name for this element (e.g. convert 'cmi.interactions.1.id' to 'cmi.interactions.n.id')
elementmodel = String(element).replace(expression,'.n.');
- if (elementmodel != "cmi.core.session_time") {
- if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
- if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
+
+ // ignore the session time element
+ if (element != "cmi.core.session_time") {
+
+ // check if this specific element is not defined in the datamodel,
+ // but the generic element name is
+ if ((eval('typeof datamodel["'+element+'"]')) == "undefined"
+ && (eval('typeof datamodel["'+elementmodel+'"]')) != "undefined") {
+
+ // add this specific element to the data model (by cloning
+ // the generic element) so we can track changes to it
+ eval('datamodel["'+element+'"]=CloneObj(datamodel["'+elementmodel+'"]);');
+ }
+
+ // check if the current element exists in the datamodel
+ if ((typeof eval('datamodel["'+element+'"]')) != "undefined") {
+
+ // make sure this is not a read only element
+ if (eval('datamodel["'+element+'"].mod') != 'r') {
+
elementstring = '&'+underscore(element)+'='+encodeURIComponent(data[property]);
- if ((typeof eval('datamodel["'+elementmodel+'"].defaultvalue')) != "undefined") {
- if (eval('datamodel["'+elementmodel+'"].defaultvalue') != data[property] || eval('typeof(datamodel["'+elementmodel+'"].defaultvalue)') != typeof(data[property])) {
+
+ // check if the element has a default value
+ if ((typeof eval('datamodel["'+element+'"].defaultvalue')) != "undefined") {
+
+ // check if the default value is different from the current value
+ if (eval('datamodel["'+element+'"].defaultvalue') != data[property]
+ || eval('typeof(datamodel["'+element+'"].defaultvalue)') != typeof(data[property])) {
+
+ // append the URI fragment to the string we plan to commit
datastring += elementstring;
- eval('datamodel["'+elementmodel+'"].defaultvalue=data[property];');
+
+ // update the element default to reflect the current committed value
+ eval('datamodel["'+element+'"].defaultvalue=data[property];');
}
} else {
+ // append the URI fragment to the string we plan to commit
datastring += elementstring;
- eval('datamodel["'+elementmodel+'"].defaultvalue=data[property];');
+ // no default value for the element, so set it now
+ eval('datamodel["'+element+'"].defaultvalue=data[property];');
}
}
}
@@ -588,6 +618,19 @@ function CollectData(data,parent) {
return datastring;
}
+ function CloneObj(obj){
+ if(obj == null || typeof(obj) != 'object') {
+ return obj;
+ }
+
+ var temp = new obj.constructor(); // changed (twice)
+ for(var key in obj) {
+ temp[key] = CloneObj(obj[key]);
+ }
+
+ return temp;
+ }
+
function StoreData(data,storetotaltime) {
if (storetotaltime) {
if (cmi.core.lesson_status == 'not attempted') {
Please sign in to comment.
Something went wrong with that request. Please try again.