Merge branch 'm35_MDL-63953' of https://github.com/danmarsden/moodle into MOODLE_35_STABLE

This commit is contained in:
Andrew Nicols
2018-11-13 07:54:18 +08:00
2 changed files with 35 additions and 2 deletions
+10 -1
View File
@@ -1453,9 +1453,18 @@ function scorm_check_mode($scorm, &$newattempt, &$attempt, $userid, &$mode) {
if ($scorm->forcenewattempt == SCORM_FORCEATTEMPT_ALWAYS) {
// This SCORM is configured to force a new attempt on every re-entry.
$attempt++;
$newattempt = 'on';
$mode = 'normal';
if ($attempt == 1) {
// Check if the user has any existing data or if this is really the first attempt.
$exists = $DB->record_exists('scorm_scoes_track', array('userid' => $userid, 'scormid' => $scorm->id));
if (!$exists) {
// No records yet - Attempt should == 1.
return;
}
}
$attempt++;
return;
}
// Check if the scorm module is incomplete (used to validate user request to start a new attempt).
+25 -1
View File
@@ -780,7 +780,7 @@ function scorm_grade_user($scorm, $userid) {
switch ($scorm->whatgrade) {
case FIRSTATTEMPT:
return scorm_grade_user_attempt($scorm, $userid, 1);
return scorm_grade_user_attempt($scorm, $userid, scorm_get_first_attempt($scorm->id, $userid));
break;
case LASTATTEMPT:
return scorm_grade_user_attempt($scorm, $userid, scorm_get_last_completed_attempt($scorm->id, $userid));
@@ -850,6 +850,30 @@ function scorm_get_last_attempt($scormid, $userid) {
}
}
/**
* Returns the first attempt used - if no attempts yet, returns 1 for first attempt.
*
* @param int $scormid the id of the scorm.
* @param int $userid the id of the user.
*
* @return int The first attempt number.
*/
function scorm_get_first_attempt($scormid, $userid) {
global $DB;
// Find the first attempt number for the given user id and scorm id.
$sql = "SELECT MIN(attempt)
FROM {scorm_scoes_track}
WHERE userid = ? AND scormid = ?";
$lastattempt = $DB->get_field_sql($sql, array($userid, $scormid));
if (empty($lastattempt)) {
return '1';
} else {
return $lastattempt;
}
}
/**
* Returns the last completed attempt used - if no completed attempts yet, returns 1 for first attempt
*