Permalink
Browse files

Fix for MDL-7707. Also had to update index.php to show students the s…

…ame score as in the gradebook.
  • Loading branch information...
1 parent 5aa3fe9 commit 0e0fd9627843263fc51eae267a69994338b36e27 mark-nielsen committed Nov 28, 2006
Showing with 25 additions and 20 deletions.
  1. +9 −14 mod/lesson/index.php
  2. +16 −6 mod/lesson/lib.php
View
@@ -8,7 +8,8 @@
**/
require_once("../../config.php");
- require_once("locallib.php");
+ require_once($CFG->dirroot.'/mod/lesson/lib.php');
+ require_once($CFG->dirroot.'/mod/lesson/locallib.php');
$id = required_param('id', PARAM_INT); // course
@@ -30,7 +31,7 @@
/// Print the header
if ($course->category) {
- $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
+ $navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->";
} else {
$navigation = '';
}
@@ -86,19 +87,13 @@
if (has_capability('mod/lesson:manage', $context)) {
$grade_value = $lesson->grade;
} else {
- // it's a student, show their mean or maximum grade
- if ($lesson->usemaxgrade) {
- $grade = get_record_sql("SELECT MAX(grade) as grade FROM {$CFG->prefix}lesson_grades
- WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
- } else {
- $grade = get_record_sql("SELECT AVG(grade) as grade FROM {$CFG->prefix}lesson_grades
- WHERE lessonid = $lesson->id AND userid = $USER->id GROUP BY userid");
- }
- if ($grade) {
+ // it's a student, show their grade
+ $grade_value = 0;
+ if ($return = lesson_grades($lesson->id)) {
// grades are stored as percentages
- $grade_value = number_format($grade->grade * $lesson->grade / 100, 1);
- } else {
- $grade_value = 0;
+ if (isset($return->grades[$USER->id])) {
+ $grade_value = $return->grades[$USER->id];
+ }
}
}
$table->data[] = array ($lesson->section, $link, $grade_value, $due);
View
@@ -409,14 +409,24 @@ function lesson_grades($lessonid) {
if (!$lesson = get_record("lesson", "id", $lessonid)) {
return NULL;
}
- if ($lesson->usemaxgrade) {
- $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
- lessonid = $lessonid GROUP BY userid");
- } else {
- $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
+ if ($lesson->retake) {
+ if ($lesson->usemaxgrade) {
+ $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
+ lessonid = $lessonid GROUP BY userid");
+ } else {
+ $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
lessonid = $lessonid GROUP BY userid");
+ }
+ } else {
+ // Retakes is turned Off; only count first attempt
+ $firstgrades = get_records_sql("SELECT userid, MIN(completed), grade FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid");
+ $grades = array();
+ if (!empty($firstgrades)) {
+ foreach($firstgrades as $userid => $info) {
+ $grades[$userid] = $info->grade;
+ }
+ }
}
-
// convert grades from percentages and tidy the numbers
if (!$lesson->practice) { // dont display practice lessons
if ($grades) {

0 comments on commit 0e0fd96

Please sign in to comment.