function hotpot_get_grades($hotpot, $user_ids = '') { global $CFG; $grades = array(); $weighting = $hotpot->grade / 100; $precision = hotpot_get_precision($hotpot); // set the SQL string to determine the $grade $grade = ""; switch ($hotpot->grademethod) { case HOTPOT_GRADEMETHOD_HIGHEST: $grade = "ROUND(MAX(score) * {$weighting}, {$precision}) AS grade"; break; case HOTPOT_GRADEMETHOD_AVERAGE: // the 'AVG' function skips abandoned quizzes, so use SUM(score)/COUNT(id) $grade = "ROUND(SUM(score)/COUNT(id) * {$weighting}, {$precision}) AS grade"; break; case HOTPOT_GRADEMETHOD_FIRST: $grade = "ROUND(score * {$weighting}, {$precision})"; $grade = sql_concat('timestart', "'_'", $grade); $grade = "MIN({$grade}) AS grade"; break; case HOTPOT_GRADEMETHOD_LAST: $grade = "ROUND(score * {$weighting}, {$precision})"; $grade = sql_concat('timestart', "'_'", $grade); $grade = "MAX({$grade}) AS grade"; break; } if ($grade) { $userid_condition = empty($user_ids) ? '' : "AND userid IN ({$user_ids}) "; $grades = get_records_sql_menu("\n SELECT userid, {$grade}\n FROM {$CFG->prefix}hotpot_attempts\n WHERE timefinish>0 AND hotpot='{$hotpot->id}' {$userid_condition}\n GROUP BY userid\n "); if ($grades) { if ($hotpot->grademethod == HOTPOT_GRADEMETHOD_FIRST || $hotpot->grademethod == HOTPOT_GRADEMETHOD_LAST) { // remove left hand characters in $grade (up to and including the underscore) foreach ($grades as $userid => $grade) { $grades[$userid] = substr($grades[$userid], strpos($grades[$userid], '_') + 1); } } } } return $grades; }
// are there any totals for this hotpot? if (empty($totals[$hotpot->id]->attemptcount)) { $report = " "; $bestscore = " "; } else { $cm = get_coursemodule_from_instance('hotpot', $hotpot->id); // report number of attempts and users $report = get_string("viewallreports", "quiz", $totals[$hotpot->id]->attemptcount); if (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_MODULE, $cm->id))) { $report .= " (" . $totals[$hotpot->id]->usercount . " {$strusers})"; } $report = '<a href="report.php?hp=' . $hotpot->id . '">' . $report . '</a>'; // get best score if (is_numeric($totals[$hotpot->id]->maxscore)) { $weighting = $hotpot->grade / 100; $precision = hotpot_get_precision($hotpot); $bestscore = round($totals[$hotpot->id]->maxscore * $weighting, $precision) . " / {$hotpot->grade}"; } else { $bestscore = " "; } } if (has_capability('mod/hotpot:grade', $sitecontext)) { if (in_array($hotpot->id, $regrade_hotpots)) { $report .= ' <font color="red">' . $strregraderequired . '</font>'; } } $data = array(); if ($course->format == "weeks" || $course->format == "topics") { array_push($data, $printsection); } if (has_capability('moodle/course:manageactivities', $coursecontext)) {