Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-37733 SCORM: Correct check for force new attempt

  • Loading branch information...
commit c9d15cee1a0bd6b560f47ffd8b4bbe37b0b19d49 1 parent ce3c766
@tollstorff tollstorff authored danmarsden committed
Showing with 40 additions and 18 deletions.
  1. +39 −17 mod/scorm/lib.php
  2. +1 −1  mod/scorm/player.php
View
56 mod/scorm/lib.php
@@ -1359,27 +1359,49 @@ function scorm_set_completion($scorm, $userid, $completionstate = COMPLETION_COM
* @param int $userid the userid of the user.
* @param string $mode the current mode that has been selected.
*/
-function scorm_check_mode($scorm, $newattempt, &$attempt, $userid, &$mode) {
+function scorm_check_mode($scorm, &$newattempt, &$attempt, $userid, &$mode) {
global $DB;
+
+ if (($mode == 'browse')) {
+ if ($scorm->hidebrowse == 1) {
+ // Prevent Browse mode if hidebrowse is set.
+ $mode = 'normal';
+ } else {
+ // We don't need to check attempts as browse mode is set.
+ return;
+ }
+ }
+ // Check if the scorm module is incomplete (used to validate user request to start a new attempt).
+ $incomplete = true;
+ $tracks = $DB->get_recordset('scorm_scoes_track', array('scormid' => $scorm->id, 'userid' => $userid,
+ 'attempt' => $attempt, 'element' => 'cmi.core.lesson_status'));
+ foreach ($tracks as $track) {
+ if (($track->value == 'completed') || ($track->value == 'passed') || ($track->value == 'failed')) {
+ $incomplete = false;
+ } else {
+ $incomplete = true;
+ break; // Found an incomplete sco, so the result as a whole is incomplete.
+ }
+ }
+ $tracks->close();
+
+ // Validate user request to start a new attempt.
+ if ($incomplete === true) {
+ // The option to start a new attempt should never have been presented. Force false.
+ $newattempt = 'off';
+ } else if (($attempt !== '1') && !empty($scorm->forcenewattempt)) {
+ // A new attempt should be forced for already completed attempts.
+ $newattempt = 'on';
+ }
+
if (($newattempt == 'on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
$attempt++;
$mode = 'normal';
- } else if ($mode != 'browse') { // Check if review mode should be set.
- $mode = 'normal'; // Set to normal mode by default.
-
- // If all tracks == passed, failed or completed then use review mode.
- $tracks = $DB->get_recordset('scorm_scoes_track', array('scormid' => $scorm->id, 'userid' => $userid,
- 'attempt' => $attempt, 'element' => 'cmi.core.lesson_status'));
- foreach ($tracks as $track) {
- if (($track->value == 'completed') || ($track->value == 'passed') || ($track->value == 'failed')) {
- $mode = 'review';
- } else { // Found an incomplete sco so exit and use normal mode.
- $mode = 'normal';
- break;
- }
+ } else { // Check if review mode should be set.
+ if ($incomplete === true) {
+ $mode = 'normal';
+ } else {
+ $mode = 'review';
}
- $tracks->close();
- } else if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { // Prevent Browse mode if hidebrowse is set.
- $mode = 'normal';
}
}
View
2  mod/scorm/player.php
@@ -66,7 +66,7 @@
// If new attempt is being triggered set normal mode and increment attempt number.
$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
-// Check mode is correct and set mode/attempt (uses pass by reference).
+// Check mode is correct and set/validate mode/attempt/newattempt (uses pass by reference).
scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode);
$url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
Please sign in to comment.
Something went wrong with that request. Please try again.