diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 06f1863e8e1..c660c079c02 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -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; +} \ No newline at end of file diff --git a/mod/scorm/player.php b/mod/scorm/player.php index df9b2eeb3bf..1d5408d492f 100644 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -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);