Skip to content
Permalink
Browse files

MDL-52653 SCORM: fix scorm_check_mode on v1.3

SCORM 2004 uses the element 'cmi.completion_status' to store the
completion status of a SCO, not 'cmi.core.lesson_status'.

This amends scorm_check_mode so that the right element is looked up.

When scorm_version_check returns false, SCORM 1.2 is assumed.
  • Loading branch information...
christianp authored and Damyon Wiese committed Oct 4, 2017
1 parent b8e10f2 commit 56df23be4f6648b1da4515d17310ec7db83cfee9
@@ -1438,12 +1438,23 @@ function scorm_check_mode($scorm, &$newattempt, &$attempt, $userid, &$mode) {
}
// Check if the scorm module is incomplete (used to validate user request to start a new attempt).
$incomplete = true;
$completionelements = array(
SCORM_12 => 'cmi.core.lesson_status',
SCORM_13 => 'cmi.completion_status',
SCORM_AICC => 'cmi.core.lesson_status'
);
$scormversion = scorm_version_check($scorm->version);
if($scormversion===false) {
$scormversion = SCORM_12;
}
$completionelement = $completionelements[$scormversion];
$sql = "SELECT sc.id, t.value
FROM {scorm_scoes} sc
LEFT JOIN {scorm_scoes_track} t ON sc.scorm = t.scormid AND sc.id = t.scoid
AND t.element = 'cmi.core.lesson_status' AND t.userid = ? AND t.attempt = ?
AND t.element = ? AND t.userid = ? AND t.attempt = ?
WHERE sc.scormtype = 'sco' AND sc.scorm = ?";
$tracks = $DB->get_recordset_sql($sql, array($userid, $attempt, $scorm->id));
$tracks = $DB->get_recordset_sql($sql, array($completionelement, $userid, $attempt, $scorm->id));
foreach ($tracks as $track) {
if (($track->value == 'completed') || ($track->value == 'passed') || ($track->value == 'failed')) {
@@ -45,7 +45,6 @@ public function create_instance($record = null, array $options = null) {
$record = (array)$record + array(
'scormtype' => SCORM_TYPE_LOCAL,
'packagefile' => '',
'packagefilepath' => $CFG->dirroot.'/mod/scorm/tests/packages/singlescobasic.zip',
'packageurl' => '',
'updatefreq' => SCORM_UPDATE_NEVER,
'popup' => 0,
@@ -72,6 +71,9 @@ public function create_instance($record = null, array $options = null) {
'auto' => $cfgscorm->auto,
'displayactivityname' => $cfgscorm->displayactivityname
);
if (empty($record['packagefilepath'])) {
$record['packagefilepath'] = $CFG->dirroot.'/mod/scorm/tests/packages/singlescobasic.zip';
}
// The 'packagefile' value corresponds to the draft file area ID. If not specified, create from packagefilepath.
if (empty($record['packagefile']) && $record['scormtype'] === SCORM_TYPE_LOCAL) {
@@ -67,6 +67,48 @@ public function setUp() {
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
}
/** Test scorm_check_mode
*
* @return void
*/
public function test_scorm_check_mode() {
global $CFG;
$newattempt = 'on';
$attempt = 1;
$mode = 'normal';
scorm_check_mode($this->scorm, $newattempt, $attempt, $this->student->id, $mode);
$this->assertEquals('off', $newattempt);
$scoes = scorm_get_scoes($this->scorm->id);
$sco = array_pop($scoes);
scorm_insert_track($this->student->id, $this->scorm->id, $sco->id, 1, 'cmi.core.lesson_status', 'completed');
$newattempt = 'on';
scorm_check_mode($this->scorm, $newattempt, $attempt, $this->student->id, $mode);
$this->assertEquals('on', $newattempt);
// Now do the same with a SCORM 2004 package.
$record = new stdClass();
$record->course = $this->course->id;
$record->packagefilepath = $CFG->dirroot.'/mod/scorm/tests/packages/RuntimeBasicCalls_SCORM20043rdEdition.zip';
$scorm13 = $this->getDataGenerator()->create_module('scorm', $record);
$newattempt = 'on';
$attempt = 1;
$mode = 'normal';
scorm_check_mode($scorm13, $newattempt, $attempt, $this->student->id, $mode);
$this->assertEquals('off', $newattempt);
$scoes = scorm_get_scoes($scorm13->id);
$sco = array_pop($scoes);
scorm_insert_track($this->student->id, $scorm13->id, $sco->id, 1, 'cmi.completion_status', 'completed');
$newattempt = 'on';
$attempt = 1;
$mode = 'normal';
scorm_check_mode($scorm13, $newattempt, $attempt, $this->student->id, $mode);
$this->assertEquals('on', $newattempt);
}
/**
* Test scorm_view
* @return void
Binary file not shown.
@@ -6,6 +6,7 @@ Sample Packages downloaded from http://scorm.com/scorm-explained/technical-scorm
* singlescobasic.zip - Single SCO with basic runtime calls. SCORM 1.2.
* singlesco_scorm12.zip - Single SCO content packaging example. SCORM 1.2.
* RuntimeMinimumCalls_SCORM12.zip - Multi-SCO packaging example. SCORM 1.2.
* RuntimeBasicCalls_SCORM20043rdEdition.zip - Multi-SCO packaging example. SCORM 2004 3rd edition.

These packages were downloaded from http://scorm.com/ website, the website
disclaimer states that *Content on this site is licensed under a Creative

0 comments on commit 56df23b

Please sign in to comment.
You can’t perform that action at this time.