Permalink
Browse files

New data model system

  • Loading branch information...
1 parent 1085b45 commit 3a94d06df6a199a68bb10ffe14224c65888b57bd bobopinna committed Apr 6, 2005
@@ -0,0 +1,298 @@
+ // Standard Data Type Definition
+ CMIString255 = '^.{0,255}$';
+ CMIString4096 = '^[.|\\n|\\r]{0,4096}$';
+ CMITime = '^([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
+ CMITimespan = '^([0-9]{2,4}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$';
+ CMIInteger = '^\\d+$';
+ CMISInteger = '^-?([0-9]+)$';
+ CMIDecimal = '^[0-9]?(\.[0-9]{1,2})?$';
+ CMIIdentifier = '^\\w{0,255}$';
+ CMIFeedback = CMIString255; // This must be redefined
+ CMIIndex = '.\\d+.';
+ // Vocabulary Data Type Definition
+ CMIStatus = '^passed|completed|failed|incomplete|browsed|not attempted$';
+ CMIExit = '^time-out|suspend|logout|$';
+ CMIType = '^true-false|choice|fill-in|matching|performance|sequencing|likert|numeric$';
+ CMIResult = '^correct|wrong|unanticipated|neutral|[0-9]?(\.[0-9]{1,2})?$';
+ // Children lists
+ cmi_children = 'core, suspend_data, launch_data, comments, objectives, student_data, student_preference, interactions';
+ core_children = 'student_id, student_name, lesson_location, credit, lesson_status, entry, score, total_time, lesson_mode, exit, session_time';
+ score_children = 'raw, min, max';
+ objectives_children = 'id, score, status';
+ student_data_children = 'mastery_score, max_time_allowed, time_limit_action';
+ student_preference_children = 'audio, language, speed, text';
+ interactions_children = 'id, objectives, time, type, correct_responses, weighting, student_response, result, latency';
+ // Data ranges
+ score_range = '0#100';
+ audio_range = '-1#100';
+ speed_range = '-100#100';
+ text_range = '-1#1';
+ // The SCORM 1.2 data model
+ var datamodel = {
+ 'cmi._children':{'defaultvalue':cmi_children, 'mod':'r', 'writeerror':'402'},
+ 'cmi._version':{'defaultvalue':'3.4', 'mod':'r', 'writeerror':'402'},
+ 'cmi.core._children':{'defaultvalue':core_children, 'mod':'r', 'writeerror':'402'},
+ 'cmi.core.student_id':{'defaultvalue':'<?php echo $user->username ?>', 'mod':'r', 'writeerror':'403'},
+ 'cmi.core.student_name':{'defaultvalue':'<?php echo $user->lastname.', '.$user->firstname ?>', 'mod':'r', 'writeerror':'403'},
+ 'cmi.core.lesson_location':{'format':CMIString255, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.core.credit':{'mod':'r', 'writeerror':'403'},
+ 'cmi.core.lesson_status':{'format':CMIStatus, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.core.entry':{'mod':'r', 'writeerror':'403'},
+ 'cmi.core.score._children':{'defaultvalue':score_children, 'mod':'r', 'writeerror':'402'},
+ 'cmi.core.score.raw':{'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.core.score.max':{'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.core.score.min':{'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.core.total_time':{'mod':'r', 'writeerror':'403'},
+ 'cmi.core.lesson_mode':{'mod':'r', 'writeerror':'405'},
+ 'cmi.core.exit':{'format':CMIExit, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.core.session_time':{'format':CMITimespan, 'mod':'w', 'defaultvalue':'00:00:00', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.suspend_data':{'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.launch_data':{'mod':'r', 'writeerror':'403'},
+ 'cmi.comments':{'format':CMIString4096, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.comments_from_lms':{'mod':'r', 'writeerror':'403'},
+ 'cmi.objectives._children':{'defaultvalue':objectives_children, 'mod':'r', 'writeerror':'403'},
+ 'cmi.objectives._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
+ 'cmi.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.objectives.n.score._children':{'pattern':CMIIndex, 'defaultvalue':score_children, 'mod':'r', 'writeerror':'402'},
+ 'cmi.objectives.n.score.raw':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.objectives.n.score.min':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.objectives.n.score.max':{'pattern':CMIIndex, 'format':CMIDecimal, 'range':score_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.objectives.n.status':{'pattern':CMIIndex, 'format':CMIStatus, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.student_data._children':{'defaultvalue':student_data_children, 'mod':'r', 'writeerror':'403'},
+ 'cmi.student_data.mastery_score':{'mod':'r', 'writeerror':'403'},
+ 'cmi.student_data.max_time_allowed':{'mod':'r', 'writeerror':'403'},
+ 'cmi.student_data.time_limit_action':{'mod':'r', 'writeerror':'403'},
+ 'cmi.student_preference._children':{'defaultvalue':student_preference_children, 'mod':'r', 'writeerror':'403'},
+ 'cmi.student_preference.audio':{'format':CMISInteger, 'range':audio_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.student_preference.language':{'format':CMIString255, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.student_preference.speed':{'format':CMISInteger, 'range':speed_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.student_preference.text':{'format':CMISInteger, 'range':text_range, 'mod':'rw', 'writeerror':'405'},
+ 'cmi.interactions._children':{'defaultvalue':interactions_children, 'mod':'r', 'writeerror':'403'},
+ 'cmi.interactions._count':{'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
+ 'cmi.interactions.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.objectives._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
+ 'cmi.interactions.n.objectives.n.id':{'pattern':CMIIndex, 'format':CMIIdentifier, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.time':{'pattern':CMIIndex, 'format':CMITime, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.type':{'pattern':CMIIndex, 'format':CMIType, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.correct_responses._count':{'pattern':CMIIndex, 'mod':'r', 'defaultvalue':'0', 'writeerror':'402'},
+ 'cmi.interactions.n.correct_responses.n.pattern':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.weighting':{'pattern':CMIIndex, 'format':CMIDecimal, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.student_response':{'pattern':CMIIndex, 'format':CMIFeedback, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.result':{'pattern':CMIIndex, 'format':CMIResult, 'mod':'w', 'readerror':'404', 'writeerror':'405'},
+ 'cmi.interactions.n.latency':{'pattern':CMIIndex, 'format':CMITimespan, 'mod':'w', 'readerror':'404', 'writeerror':'405'}
+ };
+ //
+ // Datamodel inizialization
+ //
+ var cmi = new Object();
+ cmi.core = new Object();
+ cmi.core.score = new Object();
+ cmi.objectives = new Object();
+ cmi.student_data = new Object();
+ cmi.student_preference = new Object();
+ cmi.interactions = new Object();
+ var nav = new Object();
+ for (element in datamodel) {
+ if (element.match(/\.n\./) == null) {
+ //alert (element+' = '+eval('datamodel["'+element+'"].defaultvalue'));
+ if ((typeof eval('datamodel["'+element+'"].defaultvalue')) != 'undefined') {
+ eval(element+' = datamodel["'+element+'"].defaultvalue;');
+ } else {
+ eval(element+' = "";');
+ }
+ //alert (element+' = '+eval(element));
+ }
+ }
+
+ //
+ // API Methods definition
+ //
+ var Initialized = false;
+
+ function LMSInitialize (param) {
+ if (param == "") {
+ if (!Initialized) {
+ Initialized = true;
+ errorCode = "0";
+ return "true";
+ } else {
+ errorCode = "101";
+ }
+ } else {
+ errorCode = "201";
+ }
+ return "false";
+ }
+
+ function LMSFinish (param) {
+ if (param == "") {
+ if (Initialized) {
+ LMSCommit("");
+ Initialized = false;
+ errorCode = "0";
+ return "true";
+ } else {
+ errorCode = "301";
+ }
+ } else {
+ errorCode = "201";
+ }
+ }
+
+ function LMSGetValue (element) {
+ if (Initialized) {
+ if (element !="") {
+ expression = new RegExp(CMIIndex,'g');
+ element = element.replace(expression,'.n.');
+ if ((typeof eval('datamodel["'+element+'"]')) != "undefined") {
+ if (eval('datamodel["'+element+'"].mod') != 'w') {
+ errorCode = "0";
+ return eval(element);
+ } else {
+ errorCode = eval('datamodel["'+element+'"].readerror');
+ }
+ } else {
+ errorCode = "401"
+ }
+ } else {
+ errorCode = "201";
+ }
+ } else {
+ errorCode = "301";
+ }
+ return "";
+ }
+
+ function LMSSetValue (element,value) {
+ if (Initialized) {
+ if (element != "") {
+ //alert('LMSSetValue: '+element+'\nValue: '+value);
+ expression = new RegExp(CMIIndex,'g');
+ elementmodel = element.replace(expression,'.n.');
+ if ((typeof eval('datamodel["'+elementmodel+'"]')) != "undefined") {
+ if (eval('datamodel["'+elementmodel+'"].mod') != 'r') {
+ expression.compile(eval('datamodel["'+elementmodel+'"].format'));
+ value = value+'';
+ matches = value.match(expression);
+ if (matches != null) {
+ //Create dynamic data model element
+ if (element != elementmodel) {
+ elementIndexes = element.split('.');
+ //alert(elementIndexes);
+ subelement = 'cmi';
+ for (i=1;i < elementIndexes.length-1;i++) {
+ elementIndex = elementIndexes[i];
+ //alert(elementIndex+' '+elementIndexes[i+1]);
+ if (elementIndexes[i+1].match(/^\d+$/)) {
+ if ((typeof eval(subelement+'.'+elementIndex+'._count')) == "undefined") {
+ eval(subelement+'.'+elementIndex+' = new Object();');
+ eval(subelement+'.'+elementIndex+'._count = 0;');
+ }
+ if (elementIndexes[i+1] <= eval(subelement+'.'+elementIndex+'._count')) {
+ if (elementIndexes[i+1] == eval(subelement+'.'+elementIndex+'._count')) {
+ eval(subelement+'.'+elementIndex+'._count++;');
+ }
+ subelement = subelement.concat('.'+elementIndex+'_'+elementIndexes[i+1]);
+ i++;
+ }
+ } else {
+ subelement = subelement.concat('.'+elementIndex);
+ }
+ alert(subelement);
+ if ((typeof eval(subelement)) == "undefined") {
+ eval(subelement+' = new Object();');
+ }
+ }
+ element = subelement.concat('.'+elementIndexes[elementIndexes.length-1]);
+ alert('LMSSetValue: '+element+'\nModel: '+elementmodel+'\nValue: '+value+'\nMatches: '+matches);
+ }
+ //Store data
+ if ((typeof eval('datamodel["'+elementmodel+'"].range')) != "undefined") {
+ range = eval('datamodel["'+elementmodel+'"].range');
+ ranges = range.split('#');
+ value = value+0.0;
+ if ((value >= ranges[0]) && (value <= ranges[1])) {
+ eval(element+'="'+value+'";');
+ errorCode = "0";
+ return "true";
+ } else {
+ errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
+ }
+ } else {
+ eval(element+'="'+value+'";');
+ errorCode = "0";
+ return "true";
+ }
+ } else {
+ errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
+ }
+ } else {
+ errorCode = eval('datamodel["'+elementmodel+'"].writeerror');
+ }
+ } else {
+ errorCode = "401"
+ }
+ } else {
+ errorCode = "201";
+ }
+ } else {
+ errorCode = "301";
+ }
+ alert('LMSSetValue: '+element+'\nValue: '+value+'\nPattern: '+expression+'\nMatches: '+matches+'\nError Code: '+errorCode);
+ return "false";
+ }
+
+ function LMSCommit (param) {
+ if (param == "") {
+ if (Initialized) {
+
+ errorCode = "0";
+ return "true";
+ } else {
+ errorCode = "301";
+ }
+ } else {
+ errorCode = "201";
+ }
+ return "false";
+ }
+
+ function LMSGetLastError () {
+ return errorCode;
+ }
+
+ function LMSGetErrorString (param) {
+ if (param != "") {
+ var errorString = new Array();
+ errorString["0"] = "No error";
+ errorString["101"] = "General exception";
+ errorString["201"] = "Invalid argument error";
+ errorString["202"] = "Element cannot have children";
+ errorString["203"] = "Element not an array - cannot have count";
+ errorString["301"] = "Not initialized";
+ errorString["401"] = "Not implemented error";
+ errorString["402"] = "Invalid set value, element is a keyword";
+ errorString["403"] = "Element is read only";
+ errorString["404"] = "Element is write only";
+ errorString["405"] = "Incorrect data type";
+ return errorString[param];
+ } else {
+ return "";
+ }
+ }
+
+ function LMSGetDiagnostic (param) {
+ if (param == "") {
+ param = errorCode;
+ }
+ return param;
+ }
+
+ this.LMSInitialize = LMSInitialize;
+ this.LMSFinish = LMSFinish;
+ this.LMSGetValue = LMSGetValue;
+ this.LMSSetValue = LMSSetValue;
+ this.LMSCommit = LMSCommit;
+ this.LMSGetLastError = LMSGetLastError;
+ this.LMSGetErrorString = LMSGetErrorString;
+ this.LMSGetDiagnostic = LMSGetDiagnostic;
Oops, something went wrong.

0 comments on commit 3a94d06

Please sign in to comment.