SCORM MDL-23492 tidy up grading method display/calculation
This commit is contained in:
@@ -146,7 +146,7 @@ function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='n
|
||||
// If not specified retrieve the last attempt number
|
||||
//
|
||||
if (empty($attempt)) {
|
||||
$attempt = scorm_get_attempt_count($user, $scorm);
|
||||
$attempt = scorm_get_attempt_count($user->id, $scorm);
|
||||
}
|
||||
$result->attemptleft = $scorm->maxattempt == 0 ? 1 : $scorm->maxattempt - $attempt;
|
||||
$conditions['scorm'] = $scorm->id;
|
||||
|
||||
@@ -107,7 +107,7 @@ $string['gradeaverage'] = 'Average grade';
|
||||
$string['gradeforattempt'] = 'Grade for attempt';
|
||||
$string['gradehighest'] = 'Highest grade';
|
||||
$string['grademethod'] = 'Grading method';
|
||||
$string['grademethod_help'] = 'The grading method defines how a final grade for the activity is determined.
|
||||
$string['grademethod_help'] = 'The grading method defines how the grade for a single attempt of the activity is determined.
|
||||
|
||||
There are 4 grading methods:
|
||||
|
||||
|
||||
+48
-28
@@ -592,6 +592,13 @@ function scorm_grade_user($scorm, $userid) {
|
||||
|
||||
break;
|
||||
case AVERAGEATTEMPT:
|
||||
$attemptcount = scorm_get_attempt_count($userid, $scorm, true);
|
||||
print_object($attemptcount);
|
||||
if (empty($attemptcount)) {
|
||||
return 0;
|
||||
} else {
|
||||
$attemptcount = count($attemptcount);
|
||||
}
|
||||
$lastattempt = scorm_get_last_attempt($scorm->id, $userid);
|
||||
$sumscore = 0;
|
||||
for ($attempt = 1; $attempt <= $lastattempt; $attempt++) {
|
||||
@@ -599,13 +606,7 @@ function scorm_grade_user($scorm, $userid) {
|
||||
$sumscore += $attemptscore;
|
||||
}
|
||||
|
||||
if ($lastattempt > 0) {
|
||||
$score = $sumscore / $lastattempt;
|
||||
} else {
|
||||
$score = 0;
|
||||
}
|
||||
|
||||
return $score;
|
||||
return round($sumscore / $attemptcount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -765,7 +766,7 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
|
||||
}
|
||||
|
||||
// is this the first attempt ?
|
||||
$attemptcount = scorm_get_attempt_count($user, $scorm);
|
||||
$attemptcount = scorm_get_attempt_count($user->id, $scorm);
|
||||
|
||||
// do not give the player launch FORM if the SCORM object is locked after the final attempt
|
||||
if ($scorm->lastattemptlock == 0 || $result->attemptleft > 0) {
|
||||
@@ -1006,7 +1007,7 @@ function scorm_element_cmp($a, $b) {
|
||||
function scorm_get_attempt_status($user, $scorm) {
|
||||
global $DB;
|
||||
|
||||
$attempts = scorm_get_attempt_count($user, $scorm, true);
|
||||
$attempts = scorm_get_attempt_count($user->id, $scorm, true);
|
||||
if(empty($attempts)) {
|
||||
$attemptcount = 0;
|
||||
} else {
|
||||
@@ -1023,33 +1024,52 @@ function scorm_get_attempt_status($user, $scorm) {
|
||||
|
||||
$gradereported = 0;
|
||||
$gradesum = 0;
|
||||
switch ($scorm->grademethod) {
|
||||
case GRADEHIGHEST:
|
||||
$grademethod = get_string('gradehighest', 'scorm');
|
||||
break;
|
||||
case GRADEAVERAGE:
|
||||
$grademethod = get_string('gradeaverage', 'scorm');
|
||||
break;
|
||||
case GRADESUM:
|
||||
$grademethod = get_string('gradesum', 'scorm');
|
||||
break;
|
||||
case GRADESCOES:
|
||||
$grademethod = get_string('gradescoes', 'scorm');
|
||||
break;
|
||||
}
|
||||
if ($scorm->maxattempt == 1) {
|
||||
switch ($scorm->grademethod) {
|
||||
case GRADEHIGHEST:
|
||||
$grademethod = get_string('gradehighest', 'scorm');
|
||||
break;
|
||||
case GRADEAVERAGE:
|
||||
$grademethod = get_string('gradeaverage', 'scorm');
|
||||
break;
|
||||
case GRADESUM:
|
||||
$grademethod = get_string('gradesum', 'scorm');
|
||||
break;
|
||||
case GRADESCOES:
|
||||
$grademethod = get_string('gradescoes', 'scorm');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($scorm->whatgrade) {
|
||||
case HIGHESTATTEMPT:
|
||||
$grademethod = get_string('highestattempt', 'scorm');
|
||||
break;
|
||||
case AVERAGEATTEMPT:
|
||||
$grademethod = get_string('averageattempt', 'scorm');
|
||||
break;
|
||||
case FIRSTATTEMPT:
|
||||
$grademethod = get_string('firstattempt', 'scorm');
|
||||
break;
|
||||
case LASTATTEMPT:
|
||||
$grademethod = get_string('lastattempt', 'scorm');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($attempts)) {
|
||||
$i = 1;
|
||||
foreach($attempts as $attempt) {
|
||||
$gradereported = scorm_grade_user_attempt($scorm, $user->id, $attempt->attemptnumber);
|
||||
$result .= get_string('gradeforattempt', 'scorm').' ' . $attempt->attemptnumber . ': ' . $gradereported .'%<BR>';
|
||||
$result .= get_string('gradeforattempt', 'scorm').' ' . $i . ': ' . $gradereported .'%<BR>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$calculatedgrade = scorm_grade_user($scorm, $user->id);
|
||||
$result .= get_string('grademethod', 'scorm'). ': ' . $grademethod;
|
||||
if(empty($attempts)) {
|
||||
$result .= '<BR>' . get_string('gradereported','scorm') . ': ' . get_string('none') . '<BR>';
|
||||
} else {
|
||||
$result .= '<BR>' . get_string('gradereported','scorm') . ': ' . $gradereported . ($scorm->grademethod == GRADESCOES ? '' : '%') .'<BR>';
|
||||
$result .= '<BR>' . get_string('gradereported','scorm') . ': ' . $calculatedgrade . ($scorm->grademethod == GRADESCOES ? '' : '%') .'<BR>';
|
||||
}
|
||||
$result .= '</p>';
|
||||
if ($attemptcount >= $scorm->maxattempt and $scorm->maxattempt > 0) {
|
||||
@@ -1066,14 +1086,14 @@ function scorm_get_attempt_status($user, $scorm) {
|
||||
* @param bool $attempts return the list of attempts
|
||||
* @return int - no. of attempts so far
|
||||
*/
|
||||
function scorm_get_attempt_count($user, $scorm, $attempts_only=false) {
|
||||
function scorm_get_attempt_count($userid, $scorm, $attempts_only=false) {
|
||||
global $DB;
|
||||
$attemptcount = 0;
|
||||
$element = 'cmi.core.score.raw';
|
||||
if ($scorm->version == 'scorm1_3') {
|
||||
$element = 'cmi.score.raw';
|
||||
}
|
||||
$attempts = $DB->get_records_select('scorm_scoes_track',"element=? AND userid=? AND scormid=?", array($element, $user->id, $scorm->id),'attempt','DISTINCT attempt AS attemptnumber');
|
||||
$attempts = $DB->get_records_select('scorm_scoes_track',"element=? AND userid=? AND scormid=?", array($element, $userid, $scorm->id),'attempt','DISTINCT attempt AS attemptnumber');
|
||||
if ($attempts_only) {
|
||||
return $attempts;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user