mirror of
https://github.com/moodle/moodle.git
synced 2025-04-26 19:03:38 +02:00
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:
parent
95751e81ac
commit
f47a8a6f81
@ -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;
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user