JavaScript 和Moodle 中的 Scorm 1.2

发布于 2024-10-21 08:33:26 字数 4942 浏览 1 评论 0原文

我从 flash 发布 html,即 flash + scorm 1.2 我的 html 包含 .swf 作为播放器 .swf 播放器将有菜单,学生可以从此 swf 导航页面,因此当学生到达最后一页时,课程状态应该已完成,但是我发生了什么? 当第一次学生访问课程并关闭它时 >>课程状态不完整,这是正确的,,,,但是在第二次打开课程时,状态更改为已完成,第三次更改为未完成..第四次更改为完成,,我无法理解到底发生了什么是我使用的javascript函数::

var g_nFindAPITries = 0;
var g_objAPI = null;
var g_bInitDone = false;
var g_bFinishDone = false;
var g_bSCOBrowse = false;
var g_dtmInitialized = new Date(); // will be adjusted after initialize
var g_bMasteryScoreInitialized = false;
function AlertUserOfAPIError(strText) {
    if (g_bShowApiErrors) {
        var s = strText + "\n\n" + g_strDisableErrorMsgs;
        if (!confirm(s)){
            g_bShowApiErrors = false
        }
    }
}

function ExpandString(s){
    var re = new RegExp("%","g")
    for (i = arguments.length-1; i > 0; i--){
        s2 = "%" + i;
        if (s.indexOf(s2) > -1){
            re.compile(s2,"g")
            s = s.replace(re, arguments[i]);
        }
    }
    return s
}
function FindAPI(win) {
    while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
        g_nFindAPITries ++;
        if (g_nFindAPITries > 500) {
            AlertUserOfAPIError(g_strAPITooDeep);
            return null;
        }
        win = win.parent;
    }
    return win.API;
}
function APIOK() {
    return ((typeof(g_objAPI)!= "undefined") && (g_objAPI != null))
}
function SCOInitialize() {
var err = true;
    if (!g_bInitDone) 
        {


        if ((window.parent) && (window.parent != window)){
            g_objAPI = FindAPI(window.parent)
        }
        if ((g_objAPI == null) && (window.opener != null))  {
            g_objAPI = FindAPI(window.opener)
        }
        if (!APIOK()) {
            AlertUserOfAPIError(g_strAPINotFound);
            err = false
        } 
                else
                {
            err = g_objAPI.LMSInitialize("");
            if (err == "true") 
                         {
                g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
                if (!g_bSCOBrowse)
                                   {
                    if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
                                           {
                        err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
                       }
                   }
            }
                        else 
                        {
                AlertUserOfAPIError(g_strAPIInitFailed)
            }
        }
          if (typeof(SCOInitData) != "undefined") 
                   {
            // The SCOInitData function can be defined in another script of the SCO
            SCOInitData()
           }
        g_dtmInitialized = new Date();
    }
    g_bInitDone = true;

    return (err + "") // Force type to string
}
function SCOFinish() {
    if ((APIOK()) && (g_bFinishDone == false)) {
        SCOReportSessionTime()
        if (g_bSetCompletedAutomatically){
            SCOSetStatusCompleted();
        }
        if (typeof(SCOSaveData) != "undefined"){
            // The SCOSaveData function can be defined in another script of the SCO
            SCOSaveData();
        }
        g_bFinishDone = (g_objAPI.LMSFinish("") == "true");
    }
    return (g_bFinishDone + "" ) // Force type to string
}
// Call these catcher functions rather than trying to call the API adapter directly
function SCOGetValue(nam)           {return ((APIOK())?g_objAPI.LMSGetValue(nam.toString()):"")}
function SCOCommit()                    {return ((APIOK())?g_objAPI.LMSCommit(""):"false")}
function SCOGetLastError()      {return ((APIOK())?g_objAPI.LMSGetLastError():"-1")}
function SCOGetErrorString(n)   {return ((APIOK())?g_objAPI.LMSGetErrorString(n):"No API")}
function SCOGetDiagnostic(p)    {return ((APIOK())?g_objAPI.LMSGetDiagnostic(p):"No API")}
//LMSSetValue is implemented with more complex data management logic below
var g_bMinScoreAcquired = false;
var g_bMaxScoreAcquired = false;
// Special logic begins here
function SCOSetValue(nam,val){
    var err = "";
    if (!APIOK()){
            AlertUserOfAPIError(g_strAPISetError + "\n" + nam + "\n" + val);
            err = "false"
    } else if (nam == "cmi.core.score.raw") err = privReportRawScore(val)
    if (err == ""){
            err = g_objAPI.LMSSetValue(nam,val.toString() + "");
            if (err != "true") return err
    }
    if (nam == "cmi.core.score.min"){
        g_bMinScoreAcquired = true;
        g_nSCO_ScoreMin = val
    }
    else if (nam == "cmi.core.score.max"){
        g_bMaxScoreAcquired = true;
        g_nSCO_ScoreMax = val
    }
    return err
}

,这是在body html中,

<body bgcolor="#ffffff" onload="SCOInitialize()" onunload="SCOFinish()" onbeforeunload="SCOFinish()" >

所以为什么它的交换一次又一次不完整和完成,我尝试设置值 cmi.core.lesson_status 但它不起作用

I am publish html from flash which is flash + scorm 1.2
my html contain .swf as player
.swf player will have menu and student navigate pages from this swf, so the status of the course should be completed when the student reach last page,,, but what happened with me?
when 1st time student visit the course and close it >> the status of lesson is incomplete which is correct,,,, but at the 2nd time when open the course the status changed to completed and the third time change to incomplete ..4th time change to complete ,, i cant understand what exactly happened this is the javascript functions i use ::

var g_nFindAPITries = 0;
var g_objAPI = null;
var g_bInitDone = false;
var g_bFinishDone = false;
var g_bSCOBrowse = false;
var g_dtmInitialized = new Date(); // will be adjusted after initialize
var g_bMasteryScoreInitialized = false;
function AlertUserOfAPIError(strText) {
    if (g_bShowApiErrors) {
        var s = strText + "\n\n" + g_strDisableErrorMsgs;
        if (!confirm(s)){
            g_bShowApiErrors = false
        }
    }
}

function ExpandString(s){
    var re = new RegExp("%","g")
    for (i = arguments.length-1; i > 0; i--){
        s2 = "%" + i;
        if (s.indexOf(s2) > -1){
            re.compile(s2,"g")
            s = s.replace(re, arguments[i]);
        }
    }
    return s
}
function FindAPI(win) {
    while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
        g_nFindAPITries ++;
        if (g_nFindAPITries > 500) {
            AlertUserOfAPIError(g_strAPITooDeep);
            return null;
        }
        win = win.parent;
    }
    return win.API;
}
function APIOK() {
    return ((typeof(g_objAPI)!= "undefined") && (g_objAPI != null))
}
function SCOInitialize() {
var err = true;
    if (!g_bInitDone) 
        {


        if ((window.parent) && (window.parent != window)){
            g_objAPI = FindAPI(window.parent)
        }
        if ((g_objAPI == null) && (window.opener != null))  {
            g_objAPI = FindAPI(window.opener)
        }
        if (!APIOK()) {
            AlertUserOfAPIError(g_strAPINotFound);
            err = false
        } 
                else
                {
            err = g_objAPI.LMSInitialize("");
            if (err == "true") 
                         {
                g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
                if (!g_bSCOBrowse)
                                   {
                    if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
                                           {
                        err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
                       }
                   }
            }
                        else 
                        {
                AlertUserOfAPIError(g_strAPIInitFailed)
            }
        }
          if (typeof(SCOInitData) != "undefined") 
                   {
            // The SCOInitData function can be defined in another script of the SCO
            SCOInitData()
           }
        g_dtmInitialized = new Date();
    }
    g_bInitDone = true;

    return (err + "") // Force type to string
}
function SCOFinish() {
    if ((APIOK()) && (g_bFinishDone == false)) {
        SCOReportSessionTime()
        if (g_bSetCompletedAutomatically){
            SCOSetStatusCompleted();
        }
        if (typeof(SCOSaveData) != "undefined"){
            // The SCOSaveData function can be defined in another script of the SCO
            SCOSaveData();
        }
        g_bFinishDone = (g_objAPI.LMSFinish("") == "true");
    }
    return (g_bFinishDone + "" ) // Force type to string
}
// Call these catcher functions rather than trying to call the API adapter directly
function SCOGetValue(nam)           {return ((APIOK())?g_objAPI.LMSGetValue(nam.toString()):"")}
function SCOCommit()                    {return ((APIOK())?g_objAPI.LMSCommit(""):"false")}
function SCOGetLastError()      {return ((APIOK())?g_objAPI.LMSGetLastError():"-1")}
function SCOGetErrorString(n)   {return ((APIOK())?g_objAPI.LMSGetErrorString(n):"No API")}
function SCOGetDiagnostic(p)    {return ((APIOK())?g_objAPI.LMSGetDiagnostic(p):"No API")}
//LMSSetValue is implemented with more complex data management logic below
var g_bMinScoreAcquired = false;
var g_bMaxScoreAcquired = false;
// Special logic begins here
function SCOSetValue(nam,val){
    var err = "";
    if (!APIOK()){
            AlertUserOfAPIError(g_strAPISetError + "\n" + nam + "\n" + val);
            err = "false"
    } else if (nam == "cmi.core.score.raw") err = privReportRawScore(val)
    if (err == ""){
            err = g_objAPI.LMSSetValue(nam,val.toString() + "");
            if (err != "true") return err
    }
    if (nam == "cmi.core.score.min"){
        g_bMinScoreAcquired = true;
        g_nSCO_ScoreMin = val
    }
    else if (nam == "cmi.core.score.max"){
        g_bMaxScoreAcquired = true;
        g_nSCO_ScoreMax = val
    }
    return err
}

and this is in body html

<body bgcolor="#ffffff" onload="SCOInitialize()" onunload="SCOFinish()" onbeforeunload="SCOFinish()" >

so why its swap time after time incomplete and completed and i am try to set value for
cmi.core.lesson_status but it doesn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疯了 2024-10-28 08:33:26

我会将调试重点放在 g_bSetCompletedAutomatically 变量上。在其上设置一个监视,看看当您退出课程时代码是否正在调用 SCOSetStatusCompleted()。另外,如果没有看到您提供的示例中的 g_bSetCompletedAutomatically 的原始值或 SCOSetStatusCompleted() 的代码,真的很难给您更多指导。但这出现在您将 Lesson_status 设置为已完成的位置,因为我没有看到任何其他代码将其设置为已完成代码中的任何其他位置。

对于课程完成时的问题,您可能想要查看的另一件事是在您的 SCOInitialize() 中,因为这是我看到您的代码设置 Lesson_status 的唯一位置。您需要查看 Lesson_mode 是否返回浏览,以及 Lesson_status 是否返回未尝试,以查看该代码是否是将课程设置为不完整的原因。此外,当课程处于浏览模式时,RTE 和 LMS 无论如何都应该忽略 SetValue 调用。

g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
if (!g_bSCOBrowse)
    {
        if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
        {
            err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
        }
    }

I would focus your debugging around the g_bSetCompletedAutomatically variable. Set a watch on it and see if the code is calling SCOSetStatusCompleted() when you exit the course. Also, without seeing what the original value of g_bSetCompletedAutomatically or the code for SCOSetStatusCompleted() in the samples you provided, it is really hard to give you any more direction. But that appears where you are setting the lesson_status to completed as I do not see any other code that sets it completed any where else in your code.

For the issue when the course is complete, the other thing you might want to look at is in your SCOInitialize() as that is the only place I see your code setting the lesson_status. You need to see if lesson_mode is returning browse and lesson_status is returning not attempted to see if that piece of code is what is setting the course to incomplete. Also, when a course is in browse mode, the RTE and the LMS should ignore and SetValue calls anyway.

g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");
if (!g_bSCOBrowse)
    {
        if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted")
        {
            err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete")
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文