Skip to content

Commit

Permalink
Merge branch 'm25_MDL-43222' of git://github.com/danmarsden/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_25_STABLE
  • Loading branch information
stronk7 committed Jan 14, 2014
2 parents e2565b2 + 69f07dc commit 712cb85
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions mod/scorm/locallib.php
Expand Up @@ -702,7 +702,7 @@ function scorm_grade_user($scorm, $userid) {

break;
case AVERAGEATTEMPT:
$attemptcount = scorm_get_attempt_count($userid, $scorm, true);
$attemptcount = scorm_get_attempt_count($userid, $scorm, true, true);
if (empty($attemptcount)) {
return 0;
} else {
Expand Down Expand Up @@ -1237,27 +1237,43 @@ function scorm_get_attempt_status($user, $scorm, $cm='') {
*
* @param object $user Current context user
* @param object $scorm a moodle scrom object - mdl_scorm
* @param bool $attempts return the list of attempts
* @param bool $returnobjects if true returns a object with attempts, if false returns count of attempts.
* @param bool $ignoremissingcompletion - ignores attempts that haven't reported a grade/completion.
* @return int - no. of attempts so far
*/
function scorm_get_attempt_count($userid, $scorm, $attempts_only=false) {
function scorm_get_attempt_count($userid, $scorm, $returnobjects = false, $ignoremissingcompletion = false) {
global $DB;
$attemptcount = 0;
$element = 'cmi.core.score.raw';
if ($scorm->grademethod == GRADESCOES) {
$element = 'cmi.core.lesson_status';
}

// Historically attempts that don't report these elements haven't been included in the average attempts grading method
// we may want to change this in future, but to avoid unexpected grade decreases we're leaving this in. MDL-43222
if (scorm_version_check($scorm->version, SCORM_13)) {
$element = 'cmi.score.raw';
} else if ($scorm->grademethod == GRADESCOES) {
$element = 'cmi.core.lesson_status';
} else {
$element = 'cmi.core.score.raw';
}
$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) {

if ($returnobjects) {
$params = array('userid' => $userid, 'scormid' => $scorm->id);
if ($ignoremissingcompletion) { // Exclude attempts that don't have the completion element requested.
$params['element'] = $element;
}
$attempts = $DB->get_records('scorm_scoes_track', $params, 'attempt', 'DISTINCT attempt AS attemptnumber');
return $attempts;
} else {
$params = array($userid, $scorm->id);
$sql = "SELECT COUNT(DISTINCT attempt)
FROM {scorm_scoes_track}
WHERE 'userid' = ? AND 'scormid' = ?";
if ($ignoremissingcompletion) { // Exclude attempts that don't have the completion element requested.
$sql .= ' AND element = ?';
$params[] = $element;
}

$attemptscount = $DB->count_records_sql($sql, $params);
return $attemptscount;
}
if (!empty($attempts)) {
$attemptcount = count($attempts);
}
return $attemptcount;
}

/**
Expand Down Expand Up @@ -1746,7 +1762,7 @@ function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='',
global $CFG, $DB, $OUTPUT;

if (empty($attempt)) {
$attempt = scorm_get_attempt_count($user->id, $scorm);
$attempt = scorm_get_last_attempt($scorm->id, $user->id);
}

$result = new stdClass();
Expand Down

0 comments on commit 712cb85

Please sign in to comment.