MDL-46390 mod_scorm: Find correct sco to launch when org based sco is selected

Also tidies up some redundant code in scorm_format_toc_for_droplist()
This commit is contained in:
Dan Marsden 2015-02-20 14:37:00 +13:00
parent 95751e81ac
commit f47a8a6f81
2 changed files with 34 additions and 8 deletions

View File

@ -1798,14 +1798,8 @@ function scorm_format_toc_for_droplist($scorm, $scoes, $usertracks, $currentorg=
}
}
if ($sco->prereq) {
if ($sco->scormtype == 'sco') {
$tocmenus[$sco->id] = scorm_repeater('−', $level) . '>' . format_string($sco->title);
}
} else {
if ($sco->scormtype == 'sco') {
$tocmenus[$sco->id] = scorm_repeater('−', $level) . '>' . format_string($sco->title);
}
if ($sco->scormtype == 'sco') {
$tocmenus[$sco->id] = scorm_repeater('−', $level) . '>' . format_string($sco->title);
}
if (!empty($sco->children)) {
@ -1999,3 +1993,31 @@ function scorm_isset($userdata, $param, $ifempty = '') {
return $ifempty;
}
}
/**
* Check if the current sco is launchable
* If not, find the next launchable sco
*
* @param stdClass $scorm Scorm object
* @param integer $scoid id of scorm_scoes record.
* @return integer scoid of correct sco to launch or empty if one cannot be found, which will trigger first sco.
*/
function scorm_check_launchable_sco($scorm, $scoid) {
global $DB;
if ($sco = scorm_get_sco($scoid, SCO_ONLY)) {
if ($sco->launch == '') {
// This scoid might be a top level org that can't be launched, find the first launchable sco after this sco.
$scoes = $DB->get_records_select('scorm_scoes',
'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true).
' AND id > ?', array($scorm->id, $sco->id), 'sortorder, id', 'id', 0, 1);
if (!empty($scoes)) {
$sco = reset($scoes); // Get first item from the list.
return $sco->id;
}
} else {
return $sco->id;
}
}
// Returning 0 will cause default behaviour which will find the first launchable sco in the package.
return 0;
}

View File

@ -57,6 +57,10 @@ $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
// Check mode is correct and set/validate mode/attempt/newattempt (uses pass by reference).
scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode);
if (!empty($scoid)) {
$scoid = scorm_check_launchable_sco($scorm, $scoid);
}
$url = new moodle_url('/mod/scorm/player.php', array('scoid' => $scoid, 'cm' => $cm->id));
if ($mode !== 'normal') {
$url->param('mode', $mode);