diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index c713e723dc189..abb3c28268938 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -888,7 +888,7 @@ function scorm_get_all_attempts($scormid, $userid) { * @param stdClass $cm course module object */ function scorm_print_launch ($user, $scorm, $action, $cm) { - global $CFG, $DB, $PAGE, $OUTPUT, $COURSE; + global $CFG, $DB, $OUTPUT; if ($scorm->updatefreq == SCORM_UPDATE_EVERYTIME) { scorm_parse($scorm, false); @@ -931,6 +931,13 @@ function scorm_print_launch ($user, $scorm, $action, $cm) { $result = scorm_get_toc($user, $scorm, $cm->id, TOCFULLURL, $orgidentifier); $incomplete = $result->incomplete; + // Get latest incomplete sco to launch first. + if (!empty($result->sco->id)) { + $launchsco = $result->sco->id; + } else { + // Use launch defined by SCORM package. + $launchsco = $scorm->launch; + } // Do we want the TOC to be displayed? if ($scorm->displaycoursestructure == 1) { @@ -976,7 +983,7 @@ function scorm_print_launch ($user, $scorm, $action, $cm) { } echo html_writer::empty_tag('br'); - echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scoid', 'value' => $scorm->launch)); + echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scoid', 'value' => $launchsco)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'cm', 'value' => $cm->id)); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'currentorg', 'value' => $orgidentifier)); echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('enter', 'scorm'), @@ -1013,12 +1020,19 @@ function scorm_simple_play($scorm, $user, $context, $cmid) { } if ($scorm->skipview >= SCORM_SKIPVIEW_FIRST) { $sco = current($scoes); - $url = new moodle_url('/mod/scorm/player.php', array('a' => $scorm->id, - 'currentorg' => $orgidentifier, - 'scoid' => $sco->id)); + $result = scorm_get_toc($user, $scorm, $cmid, TOCFULLURL, $orgidentifier); + $url = new moodle_url('/mod/scorm/player.php', array('a' => $scorm->id, 'currentorg' => $orgidentifier)); + + // Set last incomplete sco to launch first. + if (!empty($result->sco->id)) { + $url->param('scoid', $result->sco->id); + } else { + $url->param('scoid', $sco->id); + } + if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $user->id)) { if (!empty($scorm->forcenewattempt)) { - $result = scorm_get_toc($user, $scorm, $cmid, TOCFULLURL, $orgidentifier); + if ($result->incomplete === false) { $url->param('newattempt', 'on'); } @@ -1522,6 +1536,7 @@ function scorm_get_toc_object($user, $scorm, $currentorg='', $scoid='', $mode='n if ($sco->isvisible === 'true') { if (!empty($sco->launch)) { + // Set first sco to launch if in browse/review mode. if (empty($scoid) && ($mode != 'normal')) { $scoid = $sco->id; } @@ -1542,7 +1557,7 @@ function scorm_get_toc_object($user, $scorm, $currentorg='', $scoid='', $mode='n ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) { $incomplete = true; - if ($play && empty($scoid)) { + if (empty($scoid)) { $scoid = $sco->id; } } @@ -1561,7 +1576,7 @@ function scorm_get_toc_object($user, $scorm, $currentorg='', $scoid='', $mode='n } } else { - if ($play && empty($scoid)) { + if (empty($scoid)) { $scoid = $sco->id; } diff --git a/mod/scorm/tests/behat/multisco_reentry.feature b/mod/scorm/tests/behat/multisco_reentry.feature new file mode 100644 index 0000000000000..7a873c61dc460 --- /dev/null +++ b/mod/scorm/tests/behat/multisco_reentry.feature @@ -0,0 +1,57 @@ +@mod @mod_scorm @_file_upload @_switch_iframe +Feature: Scorm multi-sco review mode. + In order to let students access a scorm package + As a teacher + I need to add scorm activity to a course + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + + @javascript + Scenario: Test re-entry and make sure next uncompleted SCO is shown on second entry. + When I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I navigate to "Edit settings" in current page administration + And I set the following fields to these values: + | Enable completion tracking | Yes | + And I press "Save and display" + And I add a "SCORM package" to section "1" + And I set the following fields to these values: + | Name | Multi-sco SCORM package | + | Description | Description | + | Completion tracking | Show activity as complete when conditions are met | + | Require all scos to return completion status | 1 | + And I set the field "Completed" to "1" + And I upload "mod/scorm/tests/packages/RuntimeMinimumCalls_SCORM12.zip" file to "Package file" filemanager + And I click on "Save and display" "button" + And I should see "Multi-sco SCORM package" + And I log out + And I log in as "student1" + And I follow "Course 1" + And I follow "Multi-sco SCORM package" + And I should see "Normal" + And I press "Enter" + And I switch to "scorm_object" iframe + And I should see "Play of the game" + And I switch to the main frame + And I click on "Par?" "list_item" + And I switch to "scorm_object" iframe + And I should see "Par" + And I switch to the main frame + And I follow "Exit activity" + And I wait until the page is ready + And I follow "Multi-sco SCORM package" + And I should see "Normal" + And I press "Enter" + And I switch to "scorm_object" iframe + Then I should see "Scoring" \ No newline at end of file diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 21d63b882fa55..676f87b7cc246 100644 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -70,13 +70,20 @@ $scoid = 0; $orgidentifier = ''; - if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) { - if (($sco->organization == '') && ($sco->launch == '')) { - $orgidentifier = $sco->identifier; - } else { - $orgidentifier = $sco->organization; + + $result = scorm_get_toc($USER, $scorm, $cm->id, TOCFULLURL); + // Set last incomplete sco to launch first. + if (!empty($result->sco->id)) { + $scoid = $result->sco->id; + } else { + if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) { + if (($sco->organization == '') && ($sco->launch == '')) { + $orgidentifier = $sco->identifier; + } else { + $orgidentifier = $sco->organization; + } + $scoid = $sco->id; } - $scoid = $sco->id; } if (empty($preventskip) && $scorm->skipview >= SCORM_SKIPVIEW_FIRST &&