MDL-37733 SCORM: Correct check for force new attempt
This commit is contained in:
committed by
Dan Marsden
parent
ce3c7668b0
commit
c9d15cee1a
+39
-17
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ if (!empty($id)) {
|
||||
// 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));
|
||||
|
||||
Reference in New Issue
Block a user