Skip to content

Commit

Permalink
Fix issues with suspend_data and score
Browse files Browse the repository at this point in the history
The suspend_data was not saved when course becomes "completed" so the last visited page was not recorded as visited.
With a SCORM First Pass Tracking Mode course the first score was not preserved if we revisit any page that report a score.
  • Loading branch information
LeoRodz committed Apr 5, 2016
1 parent 3a512d5 commit 9413b3b
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions modules/xerte/scorm2004.3rd/xttracking_scorm2004.3rd.js
Expand Up @@ -8,15 +8,15 @@
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Created with JetBrains PhpStorm.
* User: tom
Expand Down Expand Up @@ -186,19 +186,19 @@ function ScormTrackingState()
if (jsonStr.length > 0)
{
var jsonObj = JSON.parse(jsonStr);
// Do NOT touch scormmode, and don't touch start
// Do NOT touch scormmode, don't touch start and don't touch finished
this.currentid = jsonObj.currentid;
this.currentpageid = jsonObj.currentpageid;
this.trackingmode = jsonObj.trackingmode;
this.scoremode = jsonObj.scoremode;
this.nrpages = jsonObj.nrpages;
this.pages_visited=jsonObj.pages_visited;
//this.start = new Date(jsonObj.start);
// this.start = new Date(jsonObj.start);
this.duration_previous_attempts = jsonObj.duration_previous_attempts;
this.lo_type = jsonObj.lo_type;
this.lo_passed = jsonObj.lo_passed;
this.lo_completed = jsonObj.lo_completed;
this.finished = jsonObj.finished;
// this.finished = jsonObj.finished;
this.interactions = new Array();
var i=0;
for (i=0; i<jsonObj.interactions.length; i++)
Expand Down Expand Up @@ -374,7 +374,6 @@ function ScormTrackingState()
if (this.scoremode == 'first' && sit.count > 1)
return;


// Record this action
var id = makeId(sit.page_nr, sit.ia_nr, sit.ia_type, sit.ia_name);
var currnrinteractions = this.scorm_nr_interactions();
Expand Down Expand Up @@ -569,11 +568,9 @@ function ScormTrackingState()
return "unknown";
}
}
return "";
}



function getdScaledScore()
{
return this.getdRawScore() / (this.getdMaxScore() - this.getdMinScore());
Expand Down Expand Up @@ -669,16 +666,12 @@ function ScormTrackingState()
var completionStatus = this.getCompletionStatus();

if (completionStatus)
{
setValue('cmi.completion_status', completionStatus);
if (completionStatus == 'incomplete')
{
state.currentpageid = currentid;
var suspend_str = JSON.stringify(this);
setValue('cmi.exit', 'suspend');
setValue('cmi.suspend_data', suspend_str);
}
}
state.currentpageid = currentid;
var suspend_str = JSON.stringify(this);
setValue('cmi.exit', 'suspend');
setValue('cmi.suspend_data', suspend_str);

setValue('cmi.success_status', this.getSuccessStatus());
setValue('cmi.score.scaled', this.getScaledScore());
setValue('cmi.score.raw', this.getRawScore());
Expand All @@ -689,7 +682,6 @@ function ScormTrackingState()
var duration = end.getTime() - this.start.getTime();
setValue('cmi.session_time', this.formatDuration(duration));
}
this.finished = true;
}

function initTracking()
Expand Down Expand Up @@ -797,7 +789,6 @@ function XTNeedsLogin()

function XTSetOption(option, value)
{

switch (option)
{
case "nrpages":
Expand Down Expand Up @@ -894,7 +885,7 @@ function XTSetPageScore(page_nr, score)
if (state.scormmode == 'normal')
{
var sit = state.findPage(page_nr);
if (sit != null)
if (sit != null && (state.scoremode != 'first' || sit.count < 1))
{
sit.score = score;
}
Expand Down Expand Up @@ -950,33 +941,32 @@ function XTGetInteractionLearnerAnswerFeedback(page_nr, ia_nr, ia_type, ia_name)

function XTTerminate()
{
if (state.scormmode == 'normal')
if (state.finished) return;
state.finished = true;

if (state.scormmode == 'normal' && (state.scoremode != 'first' || getValue('cmi.core.lesson_status') == "incomplete"))
{
if (!state.finished)
var currentpageid = "";
if (state.currentid)
{
var currentpageid = "";
if (state.currentid)
var sit = state.find(currentid);
// there is still an interaction open, close it
if (sit != null)
{
var sit = state.find(currentid);
// there is still an interaction open, close it
if (sit != null)
{
state.exitInteraction(sit.page_nr, sit.ia_nr, false, "", "", "", false);
}
state.exitInteraction(sit.page_nr, sit.ia_nr, false, "", "", "", false);
}
if (state.currentpageid)
}
if (state.currentpageid)
{
currentpageid = state.currentpageid;
var sit = state.find(currentpageid);
// there is still an interaction open, close it
if (sit != null)
{
currentpageid = state.currentpageid;
var sit = state.find(currentpageid);
// there is still an interaction open, close it
if (sit != null)
{
state.exitInteraction(sit.page_nr, sit.ia_nr, false, "", "", "", false);
}

state.exitInteraction(sit.page_nr, sit.ia_nr, false, "", "", "", false);
}
state.finishTracking(currentpageid);
}
state.finishTracking(currentpageid);
}
terminateCommunication();
}

0 comments on commit 9413b3b

Please sign in to comment.